00001 // Lock_Adapter_T.cpp,v 4.4 2005/10/28 16:14:53 ossama Exp 00002 00003 #ifndef ACE_LOCK_ADAPTER_T_CPP 00004 #define ACE_LOCK_ADAPTER_T_CPP 00005 00006 #include "ace/Lock_Adapter_T.h" 00007 #include "ace/OS_Memory.h" // for ACE_NEW 00008 00009 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00010 # pragma once 00011 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00012 00013 #if !defined (__ACE_INLINE__) 00014 #include "ace/Lock_Adapter_T.inl" 00015 #endif /* __ACE_INLINE__ */ 00016 00017 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00018 00019 // This constructor isn't inlined, because SunPRO C++ 4.2 + patch 00020 // 104631-07 has trouble compiling TAO with it inline. 00021 template <class ACE_LOCKING_MECHANISM> 00022 ACE_Lock_Adapter<ACE_LOCKING_MECHANISM>::ACE_Lock_Adapter (void) 00023 : lock_ (0), 00024 delete_lock_ (1) 00025 { 00026 ACE_NEW (this->lock_, 00027 ACE_LOCKING_MECHANISM); 00028 } 00029 00030 template <class ACE_LOCKING_MECHANISM> 00031 ACE_Lock_Adapter<ACE_LOCKING_MECHANISM>::~ACE_Lock_Adapter (void) 00032 { 00033 if (this->delete_lock_) 00034 delete this->lock_; 00035 } 00036 00037 // Explicitly destroy the lock. 00038 template <class ACE_LOCKING_MECHANISM> int 00039 ACE_Lock_Adapter<ACE_LOCKING_MECHANISM>::remove (void) 00040 { 00041 return this->lock_->remove (); 00042 } 00043 00044 // Block the thread until the lock is acquired. 00045 template <class ACE_LOCKING_MECHANISM> int 00046 ACE_Lock_Adapter<ACE_LOCKING_MECHANISM>::acquire (void) 00047 { 00048 return this->lock_->acquire (); 00049 } 00050 00051 // Conditionally acquire the lock (i.e., won't block). 00052 00053 template <class ACE_LOCKING_MECHANISM> int 00054 ACE_Lock_Adapter<ACE_LOCKING_MECHANISM>::tryacquire (void) 00055 { 00056 return this->lock_->tryacquire (); 00057 } 00058 00059 // Release the lock. 00060 00061 template <class ACE_LOCKING_MECHANISM> int 00062 ACE_Lock_Adapter<ACE_LOCKING_MECHANISM>::release (void) 00063 { 00064 return this->lock_->release (); 00065 } 00066 00067 // Block until the thread acquires a read lock. If the locking 00068 // mechanism doesn't support read locks then this just calls 00069 // <acquire>. 00070 00071 template <class ACE_LOCKING_MECHANISM> int 00072 ACE_Lock_Adapter<ACE_LOCKING_MECHANISM>::acquire_read (void) 00073 { 00074 return this->lock_->acquire_read (); 00075 } 00076 00077 // Block until the thread acquires a write lock. If the locking 00078 // mechanism doesn't support read locks then this just calls 00079 // <acquire>. 00080 00081 template <class ACE_LOCKING_MECHANISM> int 00082 ACE_Lock_Adapter<ACE_LOCKING_MECHANISM>::acquire_write (void) 00083 { 00084 return this->lock_->acquire_write (); 00085 } 00086 00087 // Conditionally acquire a read lock. If the locking mechanism 00088 // doesn't support read locks then this just calls <acquire>. 00089 00090 template <class ACE_LOCKING_MECHANISM> int 00091 ACE_Lock_Adapter<ACE_LOCKING_MECHANISM>::tryacquire_read (void) 00092 { 00093 return this->lock_->tryacquire_read (); 00094 } 00095 00096 // Conditionally acquire a write lock. If the locking mechanism 00097 // doesn't support write locks then this just calls <acquire>. 00098 00099 template <class ACE_LOCKING_MECHANISM> int 00100 ACE_Lock_Adapter<ACE_LOCKING_MECHANISM>::tryacquire_write (void) 00101 { 00102 return this->lock_->tryacquire_write (); 00103 } 00104 00105 // Conditionally try to upgrade a lock held for read to a write lock. 00106 // If the locking mechanism doesn't support read locks then this just 00107 // calls <acquire>. Returns 0 on success, -1 on failure. 00108 00109 template <class ACE_LOCKING_MECHANISM> int 00110 ACE_Lock_Adapter<ACE_LOCKING_MECHANISM>::tryacquire_write_upgrade (void) 00111 { 00112 return this->lock_->tryacquire_write_upgrade (); 00113 } 00114 00115 ACE_END_VERSIONED_NAMESPACE_DECL 00116 00117 #endif /* ACE_LOCK_ADAPTER_T_CPP */