00001 // -*- C++ -*- 00002 // 00003 // $Id: Guard_T.inl 80826 2008-03-04 14:51:23Z wotte $ 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 } 00058 00059 // Implicitly and automatically acquire (or try to acquire) the 00060 // lock. 00061 00062 template <class ACE_LOCK> ACE_INLINE 00063 ACE_Guard<ACE_LOCK>::~ACE_Guard (void) 00064 { 00065 this->release (); 00066 } 00067 00068 template <class ACE_LOCK> ACE_INLINE int 00069 ACE_Guard<ACE_LOCK>::locked (void) const 00070 { 00071 return this->owner_ != -1; 00072 } 00073 00074 template <class ACE_LOCK> ACE_INLINE int 00075 ACE_Guard<ACE_LOCK>::remove (void) 00076 { 00077 return this->lock_->remove (); 00078 } 00079 00080 template <class ACE_LOCK> ACE_INLINE void 00081 ACE_Guard<ACE_LOCK>::disown (void) 00082 { 00083 this->owner_ = -1; 00084 } 00085 00086 template <class ACE_LOCK> ACE_INLINE 00087 ACE_Write_Guard<ACE_LOCK>::ACE_Write_Guard (ACE_LOCK &m) 00088 : ACE_Guard<ACE_LOCK> (&m) 00089 { 00090 this->acquire_write (); 00091 } 00092 00093 template <class ACE_LOCK> ACE_INLINE int 00094 ACE_Write_Guard<ACE_LOCK>::acquire_write (void) 00095 { 00096 return this->owner_ = this->lock_->acquire_write (); 00097 } 00098 00099 template <class ACE_LOCK> ACE_INLINE int 00100 ACE_Write_Guard<ACE_LOCK>::acquire (void) 00101 { 00102 return this->owner_ = this->lock_->acquire_write (); 00103 } 00104 00105 template <class ACE_LOCK> ACE_INLINE int 00106 ACE_Write_Guard<ACE_LOCK>::tryacquire_write (void) 00107 { 00108 return this->owner_ = this->lock_->tryacquire_write (); 00109 } 00110 00111 template <class ACE_LOCK> ACE_INLINE int 00112 ACE_Write_Guard<ACE_LOCK>::tryacquire (void) 00113 { 00114 return this->owner_ = this->lock_->tryacquire_write (); 00115 } 00116 00117 template <class ACE_LOCK> ACE_INLINE 00118 ACE_Write_Guard<ACE_LOCK>::ACE_Write_Guard (ACE_LOCK &m, 00119 int block) 00120 : ACE_Guard<ACE_LOCK> (&m) 00121 { 00122 if (block) 00123 this->acquire_write (); 00124 else 00125 this->tryacquire_write (); 00126 } 00127 00128 template <class ACE_LOCK> ACE_INLINE int 00129 ACE_Read_Guard<ACE_LOCK>::acquire_read (void) 00130 { 00131 return this->owner_ = this->lock_->acquire_read (); 00132 } 00133 00134 template <class ACE_LOCK> ACE_INLINE int 00135 ACE_Read_Guard<ACE_LOCK>::acquire (void) 00136 { 00137 return this->owner_ = this->lock_->acquire_read (); 00138 } 00139 00140 template <class ACE_LOCK> ACE_INLINE int 00141 ACE_Read_Guard<ACE_LOCK>::tryacquire_read (void) 00142 { 00143 return this->owner_ = this->lock_->tryacquire_read (); 00144 } 00145 00146 template <class ACE_LOCK> ACE_INLINE int 00147 ACE_Read_Guard<ACE_LOCK>::tryacquire (void) 00148 { 00149 return this->owner_ = this->lock_->tryacquire_read (); 00150 } 00151 00152 template <class ACE_LOCK> ACE_INLINE 00153 ACE_Read_Guard<ACE_LOCK>::ACE_Read_Guard (ACE_LOCK &m) 00154 : ACE_Guard<ACE_LOCK> (&m) 00155 { 00156 this->acquire_read (); 00157 } 00158 00159 template <class ACE_LOCK> ACE_INLINE 00160 ACE_Read_Guard<ACE_LOCK>::ACE_Read_Guard (ACE_LOCK &m, 00161 int block) 00162 : ACE_Guard<ACE_LOCK> (&m) 00163 { 00164 if (block) 00165 this->acquire_read (); 00166 else 00167 this->tryacquire_read (); 00168 } 00169 00170 ACE_END_VERSIONED_NAMESPACE_DECL