3 //==========================================================================
5 * @file Lock_Adapter_T.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
9 //==========================================================================
11 #ifndef ACE_LOCK_ADAPTER_T_H
12 #define ACE_LOCK_ADAPTER_T_H
13 #include /**/ "ace/pre.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
24 * @class ACE_Lock_Adapter
26 * @brief This is an adapter that allows applications to transparently
27 * combine the ACE_Lock abstract base class (which contains
28 * pure virtual methods) with any of the other concrete ACE
29 * synchronization classes (e.g., ACE_Mutex, ACE_Semaphore,
30 * ACE_RW_Mutex, etc.).
32 * This class uses a form of the Adapter pattern.
34 template <class ACE_LOCKING_MECHANISM
>
35 class ACE_Lock_Adapter
: public ACE_Lock
38 typedef ACE_LOCKING_MECHANISM ACE_LOCK
;
40 // = Initialization/Finalization methods.
42 /// Constructor. All locking requests will be forwarded to @a lock.
43 ACE_Lock_Adapter (ACE_LOCKING_MECHANISM
&lock
);
45 /// Constructor. Since no lock is provided by the user, one will be
46 /// created internally.
49 /// Destructor. If @c lock_ was not passed in by the user, it will be
51 virtual ~ACE_Lock_Adapter ();
54 /// Block the thread until the lock is acquired.
55 virtual int acquire ();
57 /// Conditionally acquire the lock (i.e., won't block).
58 virtual int tryacquire ();
61 virtual int release ();
64 * Block until the thread acquires a read lock. If the locking
65 * mechanism doesn't support read locks then this just calls
68 virtual int acquire_read ();
71 * Block until the thread acquires a write lock. If the locking
72 * mechanism doesn't support read locks then this just calls
75 virtual int acquire_write ();
77 /// Conditionally acquire a read lock. If the locking mechanism
78 /// doesn't support read locks then this just calls acquire().
79 virtual int tryacquire_read ();
81 /// Conditionally acquire a write lock. If the locking mechanism
82 /// doesn't support read locks then this just calls acquire().
83 virtual int tryacquire_write ();
86 * Conditionally try to upgrade a lock held for read to a write lock.
87 * If the locking mechanism doesn't support read locks then this just
88 * calls acquire(). Returns 0 on success, -1 on failure.
90 virtual int tryacquire_write_upgrade ();
92 /// Explicitly destroy the lock.
93 virtual int remove ();
96 /// The concrete locking mechanism that all the methods delegate to.
97 ACE_LOCKING_MECHANISM
*lock_
;
99 /// This flag keep track of whether we are responsible for deleting
104 ACE_END_VERSIONED_NAMESPACE_DECL
106 #if defined (__ACE_INLINE__)
107 #include "ace/Lock_Adapter_T.inl"
108 #endif /* __ACE_INLINE__ */
110 #include "ace/Lock_Adapter_T.cpp"
112 #include /**/ "ace/post.h"
113 #endif /* ACE_LOCK_ADAPTER_T_H */