// -*- C++ -*- //========================================================================== /** * @file Lock_Adapter_T.h * * $Id$ * * Moved from Synch.h. * * @author Douglas C. Schmidt */ //========================================================================== #ifndef ACE_LOCK_ADAPTER_T_H #define ACE_LOCK_ADAPTER_T_H #include /**/ "ace/pre.h" #include "ace/Lock.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ ACE_BEGIN_VERSIONED_NAMESPACE_DECL /** * @class ACE_Lock_Adapter * * @brief This is an adapter that allows applications to transparently * combine the abstract base class (which contains * pure virtual methods) with any of the other concrete ACE * synchronization classes (e.g., , , * , etc.). * * This class uses a form of the Adapter pattern. */ template class ACE_Lock_Adapter : public ACE_Lock { public: typedef ACE_LOCKING_MECHANISM ACE_LOCK; // = Initialization/Finalization methods. /// Constructor. All locking requests will be forwarded to . ACE_Lock_Adapter (ACE_LOCKING_MECHANISM &lock); /// Constructor. Since no lock is provided by the user, one will be /// created internally. ACE_Lock_Adapter (void); /// Destructor. If was not passed in by the user, it will be /// deleted. virtual ~ACE_Lock_Adapter (void); // = Lock accessors. /// Block the thread until the lock is acquired. virtual int acquire (void); /// Conditionally acquire the lock (i.e., won't block). virtual int tryacquire (void); /// Release the lock. virtual int release (void); /** * Block until the thread acquires a read lock. If the locking * mechanism doesn't support read locks then this just calls * . */ virtual int acquire_read (void); /** * Block until the thread acquires a write lock. If the locking * mechanism doesn't support read locks then this just calls * . */ virtual int acquire_write (void); /// Conditionally acquire a read lock. If the locking mechanism /// doesn't support read locks then this just calls . virtual int tryacquire_read (void); /// Conditionally acquire a write lock. If the locking mechanism /// doesn't support read locks then this just calls . virtual int tryacquire_write (void); /** * Conditionally try to upgrade a lock held for read to a write lock. * If the locking mechanism doesn't support read locks then this just * calls . Returns 0 on success, -1 on failure. */ virtual int tryacquire_write_upgrade (void); /// Explicitly destroy the lock. virtual int remove (void); private: /// The concrete locking mechanism that all the methods delegate to. ACE_LOCKING_MECHANISM *lock_; /// This flag keep track of whether we are responsible for deleting /// the lock int delete_lock_; }; ACE_END_VERSIONED_NAMESPACE_DECL #if defined (__ACE_INLINE__) #include "ace/Lock_Adapter_T.inl" #endif /* __ACE_INLINE__ */ #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) #include "ace/Lock_Adapter_T.cpp" #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) #pragma implementation ("Lock_Adapter_T.cpp") #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ #include /**/ "ace/post.h" #endif /* ACE_LOCK_ADAPTER_T_H */