Block until an event has completed.

Posted by robUK on Stack Overflow See other posts from Stack Overflow or by robUK
Published on 2010-03-31T08:48:54Z Indexed on 2010/03/31 8:53 UTC
Read the original article Hit count: 330

Filed under:

Hello,

gcc 4.4.2 c89

I have a function that has to run (config_relays). It make a call to a API function called set_relay, then the code has to wait before continuing until the event for set_relay event has completed. The set_relay is any Async call.

i.e.

void run_processes()
{
    switch()
    {
        case EV_RELAY_SET:
        break;
    }
}


void config_relays()
{
    set_relay();

    /* Wait until EV_RELAY_SET has fired */
    /* Cannot do init_relay until set_relay event has fired - has to block here */
    init_relay();
}

I guess I could put the init_relay() in the switch. However, that event is used for other things and not just for initializing the relay. I would really like to handle everything in the config_relays function.

In C# you can do this by using autoreset. Does C have anything like that.

Many thanks for any advice,

© Stack Overflow or respective owner

Related posts about c