how to release buffer for Multiple g_sf_message message subscribers

 Hi all ,

 

I have multiple subscribers of the same massage ,

 

how to make sure to release the message queue after it is being retrieved by all threads?

 

Can any one explains the buffer release mechanism for the multiple subscribers!

 

Thanks in advance!

  • Hello Smit,

    You are sending the message with the same buffer to all subscribers.After you acquire your buffer and post it (with functions),if you use bufferRelease function your buffer should be removed from memory.

    Is that the answer of your question ?
  • In reply to Tulumba:

    No,
    Suppose we have three subscribers of the same message !

    Then how could i come to know that all the subscribers had use that message and so that i come to know that now its good time to release the buffer !
  • In reply to Smit Majithia:

    Hi Smit Majithia,

    Each subscriber should call bufferRelease, the framework will automatically and appriopately handle buffer releasing. From SSP user's manual:

    8. The message subscriber threads call bufferRelease to try to release the allocated buffer for the message. If the message subscriber thread is not the last one subscribing to the message, the framework does not release the buffer as the message has to be kept in the buffer until all subscribers have received the message.
    9. The Messaging Framework module invokes a user-callback function which is specified by an event producer thread if the message subscriber thread is the last one in the message subscriber group.
    10. The Messaging Framework module releases the buffer if the message subscriber thread is the last one in the message subscriber group. (There is an option ‘SF_MESSAGE_ACQUIRE_OPTION_KEEP’ for not to release the buffer.)

    Regards,
    adboc
  • In reply to adboc:

    Thanks @abdoc now,

    9. The Messaging Framework module invokes a user-callback function which is specified by an event producer thread if the message subscriber thread is the last one in the message subscriber group.

    my question is " invokes a user-callback function " in the statement which user callback function should be there?

    10. The Messaging Framework module releases the buffer if the message subscriber thread is the last one in the message subscriber group. (There is an option ‘SF_MESSAGE_ACQUIRE_OPTION_KEEP’ for not to release the buffer.)

    I didnt find any enum mentioning "SF_MESSAGE_ACQUIRE_OPTION_KEEP" ?
  • In reply to Smit Majithia:

    Hi Smit Majithia,

    "a user-callback function which is specified by an event producer thread" - post() function takes p_post_cfg parameter (sf_message_post_cfg_t), which has p_callback member, this one will be called if specified.

    I'm not sure if SF_MESSAGE_ACQUIRE_OPTION_KEEP is still valid, it likely refers to a structure which bufferAcquire() function takes: p_acquire_cfg (sf_message_acquire_cfg_t) and its buffer_keep option.

    Regards,
    adboc
  • In reply to adboc:

    Thanks so i should mention there my callback function and threadx or g_sf_message will envoke that usercallback function and then i will release the buffer !

    Or should i give this responsibility to the g_sf_message only to handle all of this as per point 8 from SSP user's manual?
  • In reply to adboc:

    I had done the Each subscriber should call bufferRelease.

    But it will give me the SSP_ERR_ASSERTION during last subscriber bufferRelease call!!!

    How should i handle this buffer releasing ??
  • In reply to Smit Majithia:

    Hi Smit Majithia,

    I have ported the messaging framework module guide app project to SSP 1.4.0 and have changed it to use bufferAcquire/bufferRelease. Please take a look:

    Messaging_FW_MG_AP.zip

    Regards,
    adboc

  • In reply to adboc:

    Thanks

    Thanks this works for me !!! and i got idea

    Now,
    I am also trying out for the user callback function (9th Point) can you please help me for the same !

    So that i have the callback function when all the subscribers would get the message and i got the callback function!!

    Can you please help me out the same
  • In reply to Smit Majithia:

    Hello Smit Majithia,

    to use the callback function you should make following modifications in the producer_thread_entry.c file:

    • line 68:
      .p_callback = message_callback
    • function prototypes section - add the callback prototype:
      void message_callback(sf_message_callback_args_t * p_args);
    • add the callback definition, e.g.:
      void message_callback(sf_message_callback_args_t * p_args)
      {
      /* Place your processing here. */
      #ifdef SEMIHOSTING
      if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk)
      {
      printf("Message callback invoked.\r\n");
      }
      #endif
      }

    Please see the modified project:
    2728.Messaging_FW_MG_AP_140_callback.zip

    Best regards,
    anper