Event flags, Name, Synopsis – Comtrol eCos User Manual

Page 79: Description

Advertising
background image

Event Flags

Name

cyg_flag_init, cyg_flag_destroy, cyg_flag_setbits, cyg_flag_maskbits,

cyg_flag_wait, cyg_flag_timed_wait, cyg_flag_poll, cyg_flag_peek,

cyg_flag_waiting

— Synchronization primitive

Synopsis

#include

<

cyg/kernel/kapi.h

>

void cyg_flag_init(cyg_flag_t* flag);

void cyg_flag_destroy(cyg_flag_t* flag);

void cyg_flag_setbits(cyg_flag_t* flag, cyg_flag_value_t value);

void cyg_flag_maskbits(cyg_flag_t* flag, cyg_flag_value_t value);

cyg_flag_value_t cyg_flag_wait(cyg_flag_t* flag, cyg_flag_value_t pattern,

cyg_flag_mode_t mode);

cyg_flag_value_t cyg_flag_timed_wait(cyg_flag_t* flag, cyg_flag_value_t pattern,

cyg_flag_mode_t mode, cyg_tick_count_t abstime);

cyg_flag_value_t cyg_flag_poll(cyg_flag_t* flag, cyg_flag_value_t pattern,

cyg_flag_mode_t mode);

cyg_flag_value_t cyg_flag_peek(cyg_flag_t* flag);

cyg_bool_t cyg_flag_waiting(cyg_flag_t* flag);

Description

Event flags allow a consumer thread to wait for one of several different types of event to occur. Alternatively it is
possible to wait for some combination of events. The implementation is relatively straightforward. Each event flag
contains a 32-bit integer. Application code associates these bits with specific events, so for example bit 0 could
indicate that an I/O operation has completed and data is available, while bit 1 could indicate that the user has
pressed a start button. A producer thread or a DSR can cause one or more of the bits to be set, and a consumer
thread currently waiting for these bits will be woken up.

Unlike semaphores no attempt is made to keep track of event counts. It does not matter whether a given event
occurs once or multiple times before being consumed, the corresponding bit in the event flag will change only
once. However semaphores cannot easily be used to handle multiple event sources. Event flags can often be used
as an alternative to condition variables, although they cannot be used for completely arbitrary conditions and they
only support the equivalent of condition variable broadcasts, not signals.

Before an event flag can be used it must be initialized by a call to

cyg_flag_init

. This takes a pointer to a

cyg_flag_t data structure, which can be part of a larger structure. All 32 bits in the event flag will be set to 0,
indicating that no events have yet occurred. If an event flag is no longer required it can be cleaned up with a call to

cyg_flag_destroy

, allowing the memory for the

cyg_flag_t

structure to be re-used.

79

Advertising