CMSIS osThreadFlagsSet() API

Hi, 

I am using CMSIS Free RTOS. 

I see osThreadFlagsSet() function is  using xTaskNotifyFromISR() and xTaskNotifyAndQueryFromISR()  APIs. I understand their usage. As per my understanding 

(void)xTaskNotifyAndQueryFromISR (hTask, flags, eSetBits, &rflags, &yield); will serve the purpose.  Can any one explain which particular use case is being addressed by calling both of these. 

https://github.com/ARM-software/CMSIS-FreeRTOS/blob/develop/CMSIS/RTOS2/FreeRTOS/Source/cmsis_os2.c

Thanks,

  • Hi,

    as stated by osThreadFlagsSet documentation this function returns "thread flags after setting".
    Defining the return value is such way means that also "execution history" is recorded by returned flags - for example, it takes some time between when osThreadFlagsSet is called and when thread flags get modified. In that time, thread flags can be also changed (set or cleared) by some high priority thread or nested interrupt (when called from interrupt context).

    To get better compatibility with CMSIS RTOS2 API calling only xTaskNotifyAndQueryFromISR and then ORing values (since xTaskNotifyAndQueryFromISR return notification value before update) is not enough as such "execution history" is not reflected by returned thread flags value.
    Calling both functions therefore also records some execution between this time frame.