3 //==========================================================================
5 * @file Lock_Adapter_T.h
9 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
11 //==========================================================================
13 #ifndef ACE_LOCK_ADAPTER_T_H
14 #define ACE_LOCK_ADAPTER_T_H
15 #include /**/ "ace/pre.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
26 * @class ACE_Lock_Adapter
28 * @brief This is an adapter that allows applications to transparently
29 * combine the ACE_Lock abstract base class (which contains
30 * pure virtual methods) with any of the other concrete ACE
31 * synchronization classes (e.g., ACE_Mutex, ACE_Semaphore,
32 * ACE_RW_Mutex, etc.).
34 * This class uses a form of the Adapter pattern.
36 template <class ACE_LOCKING_MECHANISM
>
37 class ACE_Lock_Adapter
: public ACE_Lock
40 typedef ACE_LOCKING_MECHANISM ACE_LOCK
;
42 // = Initialization/Finalization methods.
44 /// Constructor. All locking requests will be forwarded to @a lock.
45 ACE_Lock_Adapter (ACE_LOCKING_MECHANISM
&lock
);
47 /// Constructor. Since no lock is provided by the user, one will be
48 /// created internally.
49 ACE_Lock_Adapter (void);
51 /// Destructor. If @c lock_ was not passed in by the user, it will be
53 virtual ~ACE_Lock_Adapter (void);
56 /// Block the thread until the lock is acquired.
57 virtual int acquire (void);
59 /// Conditionally acquire the lock (i.e., won't block).
60 virtual int tryacquire (void);
63 virtual int release (void);
66 * Block until the thread acquires a read lock. If the locking
67 * mechanism doesn't support read locks then this just calls
70 virtual int acquire_read (void);
73 * Block until the thread acquires a write lock. If the locking
74 * mechanism doesn't support read locks then this just calls
77 virtual int acquire_write (void);
79 /// Conditionally acquire a read lock. If the locking mechanism
80 /// doesn't support read locks then this just calls acquire().
81 virtual int tryacquire_read (void);
83 /// Conditionally acquire a write lock. If the locking mechanism
84 /// doesn't support read locks then this just calls acquire().
85 virtual int tryacquire_write (void);
88 * Conditionally try to upgrade a lock held for read to a write lock.
89 * If the locking mechanism doesn't support read locks then this just
90 * calls acquire(). Returns 0 on success, -1 on failure.
92 virtual int tryacquire_write_upgrade (void);
94 /// Explicitly destroy the lock.
95 virtual int remove (void);
98 /// The concrete locking mechanism that all the methods delegate to.
99 ACE_LOCKING_MECHANISM
*lock_
;
101 /// This flag keep track of whether we are responsible for deleting
106 ACE_END_VERSIONED_NAMESPACE_DECL
108 #if defined (__ACE_INLINE__)
109 #include "ace/Lock_Adapter_T.inl"
110 #endif /* __ACE_INLINE__ */
112 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
113 #include "ace/Lock_Adapter_T.cpp"
114 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
116 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
117 #pragma implementation ("Lock_Adapter_T.cpp")
118 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
120 #include /**/ "ace/post.h"
121 #endif /* ACE_LOCK_ADAPTER_T_H */