Proper use of k_poll_signal

I'm not sure if this code I inherited is using k_poll_signal correctly because it seems like I can handle it in a much simpler way with an atomic variable.

The below code is run from a thread in a loop.

static void handle_event()
{
    ...

    if(k_poll(display_sm_events, DISP_EVENT_MAX_SIGNALS, K_NO_WAIT) == 0)
    {
        if(display_sm_events[DISP_EVENT_STARTUP_COMPLETE_SIGNAL].signal->signaled)
        {
            display_sm_events[DISP_EVENT_STARTUP_COMPLETE_SIGNAL].signal->signaled = 0;

From a different thread, the below function is called from the same module as the above code.

void disp_event_startup_complete()
{
    k_poll_signal_raise(&startup_complete_signal, 0);
}

It works but I'm not sure the current use requires the overhead of k_poll_signal.

Please share your thoughts.

Parents
  • Hi 

    I agree using a simple atomic flag should be more efficient in this situation, if you just need to check whether or not the flag was set without any timeout when the handle_event() function is run. 

    Using the k_poll API makes more sense if you need to integrate with semaphores and FIFO's, and when you want to utilize the ability to wait for a certain amount of time for one of the events to occur before timing out. 

    Best regards
    Torbjørn

Reply
  • Hi 

    I agree using a simple atomic flag should be more efficient in this situation, if you just need to check whether or not the flag was set without any timeout when the handle_event() function is run. 

    Using the k_poll API makes more sense if you need to integrate with semaphores and FIFO's, and when you want to utilize the ability to wait for a certain amount of time for one of the events to occur before timing out. 

    Best regards
    Torbjørn

Children
Related