aboutsummaryrefslogtreecommitdiff
path: root/dep/ACE_wrappers/ace/Token.h
diff options
context:
space:
mode:
Diffstat (limited to 'dep/ACE_wrappers/ace/Token.h')
-rw-r--r--dep/ACE_wrappers/ace/Token.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/dep/ACE_wrappers/ace/Token.h b/dep/ACE_wrappers/ace/Token.h
index 2368f264cde..e98e5f9a774 100644
--- a/dep/ACE_wrappers/ace/Token.h
+++ b/dep/ACE_wrappers/ace/Token.h
@@ -1,4 +1,5 @@
// -*- C++ -*-
+
//=============================================================================
/**
* @file Token.h
@@ -11,26 +12,38 @@
* @author Douglas C. Schmidt (schmidt@cs.wustl.edu)
*/
//=============================================================================
+
#ifndef ACE_TOKEN_H
#define ACE_TOKEN_H
#include /**/ "ace/pre.h"
+
#include /**/ "ace/ACE_export.h"
+
#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
+
#include "ace/Null_Mutex.h"
+
#if defined (ACE_HAS_THREADS)
+
#include "ace/Thread_Mutex.h"
+
#if (defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)) || defined (ACE_HAS_VXTHREADS)
// If platforms support semaphores with timed wait, then we use semaphores instead of c.v.
# define ACE_TOKEN_USES_SEMAPHORE
#endif /* (ACE_WIN32 && !ACE_HAS_WINCE) || VXWORKS */
+
#if defined (ACE_TOKEN_USES_SEMAPHORE)
# include "ace/Semaphore.h"
#endif /* ACE_TOKEN_USES_SEMAPHORE */
+
#include "ace/Condition_Thread_Mutex.h"
+
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
+
class ACE_Time_Value;
+
/**
* @class ACE_Token
*
@@ -63,6 +76,7 @@ class ACE_Time_Value;
class ACE_Export ACE_Token
{
public:
+
/**
* Available queueing strategies.
*/
@@ -73,17 +87,25 @@ public:
/// LIFO, Last In, First Out
LIFO = 0
};
+
// = Initialization and termination.
+
/// Constructor
ACE_Token (const ACE_TCHAR *name = 0, void * = 0);
+
/// Destructor
virtual ~ACE_Token (void);
+
// = Strategies
+
/// Retrieve the current queueing strategy.
int queueing_strategy (void);
+
/// Set the queueing strategy.
void queueing_strategy (int queueing_strategy);
+
// = Synchronization operations.
+
/**
* Acquire the token, sleeping until it is obtained or until the
* expiration of @a timeout, which is treated as "absolute" time. If
@@ -101,18 +123,21 @@ public:
int acquire (void (*sleep_hook)(void *),
void *arg = 0,
ACE_Time_Value *timeout = 0);
+
/**
* This behaves just like the previous <acquire> method, except that
* it invokes the virtual function called <sleep_hook> that can be
* overridden by a subclass of ACE_Token.
*/
int acquire (ACE_Time_Value *timeout = 0);
+
/**
* This should be overridden by a subclass to define the appropriate
* behavior before <acquire> goes to sleep. By default, this is a
* no-op...
*/
virtual void sleep_hook (void);
+
/**
* An optimized method that efficiently reacquires the token if no
* other threads are waiting. This is useful for situations where
@@ -133,19 +158,24 @@ public:
*/
int renew (int requeue_position = 0,
ACE_Time_Value *timeout = 0);
+
/// Become interface-compliant with other lock mechanisms (implements
/// a non-blocking <acquire>).
int tryacquire (void);
+
/// Shuts down the ACE_Token instance.
int remove (void);
+
/// Relinquish the token. If there are any waiters then the next one
/// in line gets it.
int release (void);
+
/// Behaves like acquire() but at a lower priority. It should probably
/// be called acquire_yield() since the semantics aren't really
/// what's commonly expected for readers/writer locks. See the class
/// documentation above for more details.
int acquire_read (void);
+
/// Behaves like acquire() but at a lower priority. It should probably
/// be called acquire_yield() since the semantics aren't really
/// what's commonly expected for readers/writer locks. See the class
@@ -153,28 +183,39 @@ public:
int acquire_read (void (*sleep_hook)(void *),
void *arg = 0,
ACE_Time_Value *timeout = 0);
+
/// Calls acquire().
int acquire_write (void);
+
/// Calls acquire().
int acquire_write (void (*sleep_hook)(void *),
void *arg = 0,
ACE_Time_Value *timeout = 0);
+
/// Lower priority try_acquire().
int tryacquire_read (void);
+
/// Just calls <tryacquire>.
int tryacquire_write (void);
+
/// Assumes the caller has acquired the token and returns 0.
int tryacquire_write_upgrade (void);
+
// = Accessor methods.
+
/// Return the number of threads that are currently waiting to get
/// the token.
int waiters (void);
+
/// Return the id of the current thread that owns the token.
ACE_thread_t current_owner (void);
+
/// Dump the state of an object.
void dump (void) const;
+
/// Declare the dynamic allocation hooks.
ACE_ALLOC_HOOK_DECLARE;
+
/// The following structure implements a LIFO/FIFO queue of waiter threads
/// that are asleep waiting to obtain the token.
struct ACE_Token_Queue_Entry
@@ -182,18 +223,24 @@ public:
/// Constructor
ACE_Token_Queue_Entry (ACE_Thread_Mutex &m,
ACE_thread_t t_id);
+
/// Constructor using a pre-allocated attributes
ACE_Token_Queue_Entry (ACE_Thread_Mutex &m,
ACE_thread_t t_id,
ACE_Condition_Attributes &attributes);
+
/// Entry blocks on the token.
int wait (ACE_Time_Value *timeout, ACE_Thread_Mutex &lock);
+
/// Notify (unblock) the entry.
int signal (void);
+
/// Pointer to next waiter.
ACE_Token_Queue_Entry *next_;
+
/// ACE_Thread id of this waiter.
ACE_thread_t thread_id_;
+
#if defined (ACE_TOKEN_USES_SEMAPHORE)
/// ACE_Semaphore object used to wake up waiter when it can run again.
ACE_Semaphore cv_;
@@ -201,59 +248,81 @@ public:
/// ACE_Condition object used to wake up waiter when it can run again.
ACE_Condition_Thread_Mutex cv_;
#endif /* ACE_TOKEN_USES_SEMAPHORE */
+
/// Ok to run.
int runable_;
};
+
private:
enum ACE_Token_Op_Type
{
READ_TOKEN = 1,
WRITE_TOKEN
};
+
struct ACE_Token_Queue
{
/// Constructor
ACE_Token_Queue (void);
+
/// Remove a waiter from the queue.
void remove_entry (ACE_Token_Queue_Entry *);
+
/// Insert a waiter into the queue.
void insert_entry (ACE_Token_Queue_Entry &entry,
int requeue_position = -1);
+
/// Head of the list of waiting threads.
ACE_Token_Queue_Entry *head_;
+
/// Tail of the list of waiting threads.
ACE_Token_Queue_Entry *tail_;
};
+
/// Implements the <acquire> and <tryacquire> methods above.
int shared_acquire (void (*sleep_hook_func)(void *),
void *arg,
ACE_Time_Value *timeout,
ACE_Token_Op_Type op_type);
+
/// Wake next in line for ownership.
void wakeup_next_waiter (void);
+
/// A queue of writer threads.
ACE_Token_Queue writers_;
+
/// A queue of reader threads.
ACE_Token_Queue readers_;
+
/// ACE_Thread_Mutex used to lock internal data structures.
ACE_Thread_Mutex lock_;
+
/// Current owner of the token.
ACE_thread_t owner_;
+
/// Some thread (i.e., <owner_>) is using the token. We need this
/// extra variable to deal with POSIX pthreads madness...
int in_use_;
+
/// Number of waiters.
int waiters_;
+
/// Current nesting level.
int nesting_level_;
+
/// The attributes for the condition variables, optimizes lock time.
ACE_Condition_Attributes attributes_;
+
/// Queueing strategy, LIFO/FIFO.
int queueing_strategy_;
};
+
ACE_END_VERSIONED_NAMESPACE_DECL
+
#else
+
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
+
class ACE_Export ACE_Token
{
public:
@@ -264,9 +333,13 @@ public:
int remove (void) { ACE_NOTSUP_RETURN (-1); }
int release (void) { ACE_NOTSUP_RETURN (-1); }
};
+
ACE_END_VERSIONED_NAMESPACE_DECL
+
#endif /* ACE_HAS_THREADS */
+
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
+
class ACE_Export ACE_Noop_Token : public ACE_Null_Mutex
{
public:
@@ -276,21 +349,29 @@ public:
FIFO = -1,
LIFO = 0
};
+
/// Get queueing strategy.
int queueing_strategy (void);
+
/// Set queueing strategy.
void queueing_strategy (int queueing_strategy);
+
int renew (int = 0, ACE_Time_Value * =0);
+
/// Dump the state of an object.
void dump (void) const;
+
/// Declare the dynamic allocation hooks.
ACE_ALLOC_HOOK_DECLARE;
};
+
ACE_END_VERSIONED_NAMESPACE_DECL
+
#if defined (__ACE_INLINE__)
#include "ace/Token.inl"
#endif /* __ACE_INLINE__ */
+
#include /**/ "ace/post.h"
#endif /* ACE_TOKEN_H */