This synchronization object has two states: set and clear. Threads may wait for the flag be in the specific state and change it.
Sets a flag in a clear state, or changes the flag's state to clear.
If there are threads waiting for the flag object's state to become clear, all of them will become active. If there were higher priority threads already waiting before this one, the context switch may happen immediately.
#include <cywin.h> ... struct Flag data_busy; ... Flag_ctor( &data_busy, "shared_data", FALSE ); ... if( Flag_wait_clear( &data_busy, 1000 ) ) { Flag_set( &data_busy ); ... // Uses shared data. ... Flag_clear( &data_busy ); } else { TRACE( "Timeout while trying to access." ); } ... Flag_dtor( &data_busy, LEAVE_MEMORY ); ...
Creates a named flag.
#include <cywin.h> ... struct Flag data_busy; ... Flag_ctor( &data_busy, "shared_data", FALSE ); ... if( Flag_wait_clear( &data_busy, 1000 ) ) { Flag_set( &data_busy ); ... // Uses shared data. ... Flag_clear( &data_busy ); } else { TRACE( "Timeout while trying to access." ); } ... Flag_dtor( &data_busy, LEAVE_MEMORY ); ...
Destructor.
#include <cywin.h> ... struct Flag data_busy; ... Flag_ctor( &data_busy, "shared_data", FALSE ); ... if( Flag_wait_clear( &data_busy, 1000 ) ) { Flag_set( &data_busy ); ... // Uses shared data. ... Flag_clear( &data_busy ); } else { TRACE( "Timeout while trying to access." ); } ... Flag_dtor( &data_busy, LEAVE_MEMORY ); ...
Flips a flag's state from set to clear or vice-versa.
#include <cywin.h> ... struct Flag data_busy; ... Flag_ctor( &data_busy, "shared_data", FALSE ); ... if( Flag_wait_clear( &data_busy, 1000 ) ) { Flag_set( &data_busy ); ... // Uses shared data. ... Flag_flip( &data_busy ); } else { TRACE( "Timeout while trying to access." ); } ... Flag_dtor( &data_busy, LEAVE_MEMORY ); ...
Returns TRUE if a flag is in the set state.
#include <cywin.h> ... struct module_t main_module; struct Flag data_busy; ... Flag_ctor( &data_busy, "shared_data", FALSE ); ... while( Flag_is_set( &data_busy ) ) { sleep( 250 ); } Flag_set( &data_busy ); ... // Uses shared data. ... Flag_clear( &data_busy ); ... Flag_dtor( &data_busy, LEAVE_MEMORY ); ...
Sets a flag, or changes the flag to the set state.
If there are threads waiting for the flag object's state to become set, all of them will become active. If there were higher priority threads already waiting before this one, the context switch may happen immediately. Does nothing if the flag is already set.
#include <cywin.h> ... struct Flag data_busy; ... Flag_ctor( &data_busy, "shared_data", FALSE ); ... if( Flag_wait_clear( &data_busy, 1000 ) ) { Flag_set( &data_busy ); ... // Uses shared data. ... Flag_clear( &data_busy ); } else { TRACE( "Timeout while trying to access." ); } ... Flag_dtor( &data_busy, LEAVE_MEMORY ); ...
Sets the flag to a specified state, or changes the flag's state to set or clear.
If there are threads waiting for the flag object's state to change this way, all of them will become active. If there were higher priority threads already waiting before this one, the context switch may happen immediately.
#include <cywin.h> ... struct Flag data_busy; ... Flag_ctor( &data_busy, "shared_data", FALSE ); ... if( Flag_wait_clear( &data_busy, 1000 ) ) { Flag_set_Ex( &data_busy, TRUE ); ... // Uses shared data. ... Flag_set_Ex( &data_busy, FALSE ); } else { TRACE( "Timeout while trying to access." ); } ... Flag_dtor( &data_busy, LEAVE_MEMORY ); ...
Waits for a specified state.
If the flag is already in the desired state, it returns; otherwise it waits for a specified timeout.
#include <cywin.h> ... struct Flag data_busy; ... Flag_ctor( &data_busy, "shared_data", FALSE ); ... if( Flag_wait( &data_busy, FALSE, 1000 ) ) { Flag_set( &data_busy ); ... // Uses shared data. ... Flag_flip( &data_busy ); } else { TRACE( "Timeout while trying to access." ); } ... Flag_dtor( &data_busy, LEAVE_MEMORY ); ...
Waits for the flag's state to become clear.
If the flag is already clear, it returns immediately. If the flag is set, it waits until the timeout expires or the flag state changes.
#include <cywin.h> ... struct Flag data_busy; ... Flag_ctor( &data_busy, "shared_data", FALSE ); ... if( Flag_wait_clear( &data_busy, 1000 ) ) { Flag_set( &data_busy ); ... // Uses shared data. ... Flag_flip( &data_busy ); } else { TRACE( "Timeout while trying to access." ); } ... Flag_dtor( &data_busy, LEAVE_MEMORY ); ...
Wait the flag's state to change to set.
If flag is already set, it returns immediately. If the flag is clear, it waits until the timeout expires or flag's state changes.
#include <cywin.h> ... struct Flag data_not_busy; ... Flag_ctor( &data_not_busy, "shared_data", FALSE ); ... if( Flag_wait_set( &data_not_busy, 1000 ) ) { Flag_clear( &data_not_busy ); ... // Uses shared data. ... Flag_flip( &data_not_busy ); } else { TRACE( "Timeout while trying to access." ); } ... Flag_dtor( &data_not_busy, LEAVE_MEMORY ); ...