00001 // -*- C++ -*- 00002 00003 //========================================================================== 00004 /** 00005 * @file Lock_Adapter_T.h 00006 * 00007 * $Id: Lock_Adapter_T.h 80826 2008-03-04 14:51:23Z wotte $ 00008 * 00009 * Moved from Synch.h. 00010 * 00011 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> 00012 */ 00013 //========================================================================== 00014 00015 #ifndef ACE_LOCK_ADAPTER_T_H 00016 #define ACE_LOCK_ADAPTER_T_H 00017 #include /**/ "ace/pre.h" 00018 00019 #include "ace/Lock.h" 00020 00021 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00022 # pragma once 00023 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00024 00025 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00026 00027 /** 00028 * @class ACE_Lock_Adapter 00029 * 00030 * @brief This is an adapter that allows applications to transparently 00031 * combine the <ACE_Lock> abstract base class (which contains 00032 * pure virtual methods) with any of the other concrete ACE 00033 * synchronization classes (e.g., ACE_Mutex, ACE_Semaphore, 00034 * ACE_RW_Mutex, etc.). 00035 * 00036 * This class uses a form of the Adapter pattern. 00037 */ 00038 template <class ACE_LOCKING_MECHANISM> 00039 class ACE_Lock_Adapter : public ACE_Lock 00040 { 00041 public: 00042 typedef ACE_LOCKING_MECHANISM ACE_LOCK; 00043 00044 // = Initialization/Finalization methods. 00045 00046 /// Constructor. All locking requests will be forwarded to <lock>. 00047 ACE_Lock_Adapter (ACE_LOCKING_MECHANISM &lock); 00048 00049 /// Constructor. Since no lock is provided by the user, one will be 00050 /// created internally. 00051 ACE_Lock_Adapter (void); 00052 00053 /// Destructor. If <lock_> was not passed in by the user, it will be 00054 /// deleted. 00055 virtual ~ACE_Lock_Adapter (void); 00056 00057 // = Lock accessors. 00058 /// Block the thread until the lock is acquired. 00059 virtual int acquire (void); 00060 00061 /// Conditionally acquire the lock (i.e., won't block). 00062 virtual int tryacquire (void); 00063 00064 /// Release the lock. 00065 virtual int release (void); 00066 00067 /** 00068 * Block until the thread acquires a read lock. If the locking 00069 * mechanism doesn't support read locks then this just calls 00070 * <acquire>. 00071 */ 00072 virtual int acquire_read (void); 00073 00074 /** 00075 * Block until the thread acquires a write lock. If the locking 00076 * mechanism doesn't support read locks then this just calls 00077 * <acquire>. 00078 */ 00079 virtual int acquire_write (void); 00080 00081 /// Conditionally acquire a read lock. If the locking mechanism 00082 /// doesn't support read locks then this just calls <acquire>. 00083 virtual int tryacquire_read (void); 00084 00085 /// Conditionally acquire a write lock. If the locking mechanism 00086 /// doesn't support read locks then this just calls <acquire>. 00087 virtual int tryacquire_write (void); 00088 00089 /** 00090 * Conditionally try to upgrade a lock held for read to a write lock. 00091 * If the locking mechanism doesn't support read locks then this just 00092 * calls <acquire>. Returns 0 on success, -1 on failure. 00093 */ 00094 virtual int tryacquire_write_upgrade (void); 00095 00096 /// Explicitly destroy the lock. 00097 virtual int remove (void); 00098 00099 private: 00100 /// The concrete locking mechanism that all the methods delegate to. 00101 ACE_LOCKING_MECHANISM *lock_; 00102 00103 /// This flag keep track of whether we are responsible for deleting 00104 /// the lock 00105 bool delete_lock_; 00106 }; 00107 00108 ACE_END_VERSIONED_NAMESPACE_DECL 00109 00110 #if defined (__ACE_INLINE__) 00111 #include "ace/Lock_Adapter_T.inl" 00112 #endif /* __ACE_INLINE__ */ 00113 00114 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) 00115 #include "ace/Lock_Adapter_T.cpp" 00116 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00117 00118 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) 00119 #pragma implementation ("Lock_Adapter_T.cpp") 00120 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ 00121 00122 #include /**/ "ace/post.h" 00123 #endif /* ACE_LOCK_ADAPTER_T_H */