Public Types |
enum | QUEUEING_STRATEGY { FIFO = -1,
LIFO = 0
} |
Public Methods |
| ACE_Token (const ACE_TCHAR *name=0, void *=0) |
| Constructor. More...
|
virtual | ~ACE_Token (void) |
| Destructor. More...
|
int | queueing_strategy (void) |
| Retrieve the current queueing strategy. More...
|
void | queueing_strategy (int queueing_strategy) |
| Set the queueing strategy. More...
|
int | acquire (void(*sleep_hook)(void *), void *arg=0, ACE_Time_Value *timeout=0) |
int | acquire (ACE_Time_Value *timeout=0) |
virtual void | sleep_hook (void) |
int | renew (int requeue_position=0, ACE_Time_Value *timeout=0) |
int | tryacquire (void) |
| Become interface-compliant with other lock mechanisms (implements a non-blocking <acquire>). More...
|
int | remove (void) |
| Shuts down the ACE_Token instance. More...
|
int | release (void) |
| Relinquish the token. If there are any waiters then the next one in line gets it. More...
|
int | acquire_read (void) |
| Behave like acquire but in a lower priority. It should probably be called acquire_yield. More...
|
int | acquire_read (void(*sleep_hook)(void *), void *arg=0, ACE_Time_Value *timeout=0) |
| More sophisticate version of acquire_read. More...
|
int | acquire_write (void) |
| Just calls <acquire>. More...
|
int | acquire_write (void(*sleep_hook)(void *), void *arg=0, ACE_Time_Value *timeout=0) |
| More sophisticate version of acquire_write. More...
|
int | tryacquire_read (void) |
| Lower priority try_acquire. More...
|
int | tryacquire_write (void) |
| Just calls <tryacquire>. More...
|
int | tryacquire_write_upgrade (void) |
| Assumes the caller has acquired the token and returns 0. More...
|
int | waiters (void) |
| Return the number of threads that are currently waiting to get the token. More...
|
ACE_thread_t | current_owner (void) |
| Return the id of the current thread that owns the token. More...
|
void | dump (void) const |
| Dump the state of an object. More...
|
Public Attributes |
| ACE_ALLOC_HOOK_DECLARE |
| Declare the dynamic allocation hooks. More...
|
Private Types |
enum | ACE_Token_Op_Type { READ_TOKEN = 1,
WRITE_TOKEN
} |
Private Methods |
int | shared_acquire (void(*sleep_hook_func)(void *), void *arg, ACE_Time_Value *timeout, ACE_Token_Op_Type op_type) |
| Implements the <acquire> and <tryacquire> methods above. More...
|
void | wakeup_next_waiter (void) |
| Wake next in line for ownership. More...
|
Private Attributes |
ACE_Token_Queue | writers_ |
| A queue of writer threads. More...
|
ACE_Token_Queue | readers_ |
| A queue of reader threads. More...
|
ACE_Thread_Mutex | lock_ |
| ACE_Thread_Mutex used to lock internal data structures. More...
|
ACE_thread_t | owner_ |
| Current owner of the token. More...
|
int | in_use_ |
| Some thread (i.e., <owner_>) is using the token. We need this extra variable to deal with POSIX pthreads madness... More...
|
int | waiters_ |
| Number of waiters. More...
|
int | nesting_level_ |
| Current nesting level. More...
|
ACE_Condition_Attributes | attributes_ |
| The attributes for the condition variables, optimizes lock time. More...
|
int | queueing_strategy_ |
| Queueing strategy, LIFO/FIFO. More...
|
This class is a more general-purpose synchronization mechanism than many native OS mutexes. For example, it implements "recursive mutex" semantics, where a thread that owns the token can reacquire it without deadlocking. If the same thread calls <acquire> multiple times, however, it must call <release> an equal number of times before the token is actually released. Threads that are blocked awaiting the token are serviced in strict FIFO/LIFO order as other threads release the token (Solaris and Pthread mutexes don't strictly enforce an acquisition order). There are two lists within the class. Write acquires always have higher priority over read acquires. Which means, if you use both write/read operations, care must be taken to avoid starvation on the readers. Notice that the read/write acquire operations do not have the usual semantic of reader/writer locks. Only one reader can acquire the token at a time (which is different from the usual reader/writer locks where several readers can acquire a lock at the same time as long as there is no writer waiting for the lock). We choose the names to (1) borrow the semantic to give writers higher priority and (2) support a common interface for all locking classes in ACE.