00001 // -*- C++ -*- 00002 // 00003 // Guard_T.inl,v 4.3 2005/10/28 16:14:52 ossama Exp 00004 00005 #include "ace/RW_Thread_Mutex.h" 00006 00007 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00008 00009 template <class ACE_LOCK> ACE_INLINE int 00010 ACE_Guard<ACE_LOCK>::acquire (void) 00011 { 00012 return this->owner_ = this->lock_->acquire (); 00013 } 00014 00015 template <class ACE_LOCK> ACE_INLINE int 00016 ACE_Guard<ACE_LOCK>::tryacquire (void) 00017 { 00018 return this->owner_ = this->lock_->tryacquire (); 00019 } 00020 00021 template <class ACE_LOCK> ACE_INLINE int 00022 ACE_Guard<ACE_LOCK>::release (void) 00023 { 00024 if (this->owner_ == -1) 00025 return -1; 00026 else 00027 { 00028 this->owner_ = -1; 00029 return this->lock_->release (); 00030 } 00031 } 00032 00033 template <class ACE_LOCK> ACE_INLINE 00034 ACE_Guard<ACE_LOCK>::ACE_Guard (ACE_LOCK &l) 00035 : lock_ (&l), 00036 owner_ (0) 00037 { 00038 this->acquire (); 00039 } 00040 00041 template <class ACE_LOCK> ACE_INLINE 00042 ACE_Guard<ACE_LOCK>::ACE_Guard (ACE_LOCK &l, int block) 00043 : lock_ (&l), 00044 owner_ (0) 00045 { 00046 if (block) 00047 this->acquire (); 00048 else 00049 this->tryacquire (); 00050 } 00051 00052 template <class ACE_LOCK> ACE_INLINE 00053 ACE_Guard<ACE_LOCK>::ACE_Guard (ACE_LOCK &l, int block, int become_owner) 00054 : lock_ (&l), 00055 owner_ (become_owner == 0 ? -1 : 0) 00056 { 00057 ACE_UNUSED_ARG (block); 00058 } 00059 00060 // Implicitly and automatically acquire (or try to acquire) the 00061 // lock. 00062 00063 template <class ACE_LOCK> ACE_INLINE 00064 ACE_Guard<ACE_LOCK>::~ACE_Guard (void) 00065 { 00066 this->release (); 00067 } 00068 00069 template <class ACE_LOCK> ACE_INLINE int 00070 ACE_Guard<ACE_LOCK>::locked (void) const 00071 { 00072 return this->owner_ != -1; 00073 } 00074 00075 template <class ACE_LOCK> ACE_INLINE int 00076 ACE_Guard<ACE_LOCK>::remove (void) 00077 { 00078 return this->lock_->remove (); 00079 } 00080 00081 template <class ACE_LOCK> ACE_INLINE void 00082 ACE_Guard<ACE_LOCK>::disown (void) 00083 { 00084 this->owner_ = -1; 00085 } 00086 00087 template <class ACE_LOCK> ACE_INLINE 00088 ACE_Write_Guard<ACE_LOCK>::ACE_Write_Guard (ACE_LOCK &m) 00089 : ACE_Guard<ACE_LOCK> (&m) 00090 { 00091 this->acquire_write (); 00092 } 00093 00094 template <class ACE_LOCK> ACE_INLINE int 00095 ACE_Write_Guard<ACE_LOCK>::acquire_write (void) 00096 { 00097 return this->owner_ = this->lock_->acquire_write (); 00098 } 00099 00100 template <class ACE_LOCK> ACE_INLINE int 00101 ACE_Write_Guard<ACE_LOCK>::acquire (void) 00102 { 00103 return this->owner_ = this->lock_->acquire_write (); 00104 } 00105 00106 template <class ACE_LOCK> ACE_INLINE int 00107 ACE_Write_Guard<ACE_LOCK>::tryacquire_write (void) 00108 { 00109 return this->owner_ = this->lock_->tryacquire_write (); 00110 } 00111 00112 template <class ACE_LOCK> ACE_INLINE int 00113 ACE_Write_Guard<ACE_LOCK>::tryacquire (void) 00114 { 00115 return this->owner_ = this->lock_->tryacquire_write (); 00116 } 00117 00118 template <class ACE_LOCK> ACE_INLINE 00119 ACE_Write_Guard<ACE_LOCK>::ACE_Write_Guard (ACE_LOCK &m, 00120 int block) 00121 : ACE_Guard<ACE_LOCK> (&m) 00122 { 00123 if (block) 00124 this->acquire_write (); 00125 else 00126 this->tryacquire_write (); 00127 } 00128 00129 template <class ACE_LOCK> ACE_INLINE int 00130 ACE_Read_Guard<ACE_LOCK>::acquire_read (void) 00131 { 00132 return this->owner_ = this->lock_->acquire_read (); 00133 } 00134 00135 template <class ACE_LOCK> ACE_INLINE int 00136 ACE_Read_Guard<ACE_LOCK>::acquire (void) 00137 { 00138 return this->owner_ = this->lock_->acquire_read (); 00139 } 00140 00141 template <class ACE_LOCK> ACE_INLINE int 00142 ACE_Read_Guard<ACE_LOCK>::tryacquire_read (void) 00143 { 00144 return this->owner_ = this->lock_->tryacquire_read (); 00145 } 00146 00147 template <class ACE_LOCK> ACE_INLINE int 00148 ACE_Read_Guard<ACE_LOCK>::tryacquire (void) 00149 { 00150 return this->owner_ = this->lock_->tryacquire_read (); 00151 } 00152 00153 template <class ACE_LOCK> ACE_INLINE 00154 ACE_Read_Guard<ACE_LOCK>::ACE_Read_Guard (ACE_LOCK &m) 00155 : ACE_Guard<ACE_LOCK> (&m) 00156 { 00157 this->acquire_read (); 00158 } 00159 00160 template <class ACE_LOCK> ACE_INLINE 00161 ACE_Read_Guard<ACE_LOCK>::ACE_Read_Guard (ACE_LOCK &m, 00162 int block) 00163 : ACE_Guard<ACE_LOCK> (&m) 00164 { 00165 if (block) 00166 this->acquire_read (); 00167 else 00168 this->tryacquire_read (); 00169 } 00170 00171 ACE_END_VERSIONED_NAMESPACE_DECL