cmn_LockIDbyOwn< _T, _size > Class Template Reference
[Common, basic classes, functions and types]

#include <cmn_lockidbyown.h>

Inheritance diagram for cmn_LockIDbyOwn< _T, _size >:

Inheritance graph
[legend]
Collaboration diagram for cmn_LockIDbyOwn< _T, _size >:

Collaboration graph
[legend]

List of all members.


Detailed Description

template<class _T, int _size>
class cmn_LockIDbyOwn< _T, _size >

Definition at line 79 of file cmn_lockidbyown.h.


Public Types

typedef cmn_LockIDbyOwn< _T,
_size >::iterator 
cmn_LockIDbyOwn_v_i
typedef cmn_IDOwn< _T > cmn_LockEl_t

Public Member Functions

 cmn_LockIDbyOwn ()
void SetMutex ()
void ReleaseMutex ()
void LockByID (const _T a_ID)
 This lock is used for individual locking.
void LockByIDOwn (const cmn_LockEl_t &a_ID)
bool CanLockByID (const _T a_ID)
 This lock is used for individual locking.
cmn_Lock_e CanLockByIDOwn (const cmn_LockEl_t &a_ID)
int CanLockByIDOwnNoMutex (const cmn_LockEl_t &a_ID)
 return -9999 if not locked return ownerID if element is already locked
void UnLockByID (const _T a_ID)

Public Attributes

 log_CLASSID_m

Private Attributes

cmn_Mutex m_lockID_x
cmn_Condition m_releasedLockID_c

Member Typedef Documentation

template<class _T, int _size>
typedef cmn_LockIDbyOwn<_T, _size>::iterator cmn_LockIDbyOwn< _T, _size >::cmn_LockIDbyOwn_v_i

Definition at line 81 of file cmn_lockidbyown.h.

template<class _T, int _size>
typedef cmn_IDOwn<_T> cmn_LockIDbyOwn< _T, _size >::cmn_LockEl_t

Definition at line 82 of file cmn_lockidbyown.h.


Constructor & Destructor Documentation

template<class _T, int _size>
cmn_LockIDbyOwn< _T, _size >::cmn_LockIDbyOwn (  )  [inline]

Definition at line 84 of file cmn_lockidbyown.h.

00085         : 
00086         m_releasedLockID_c(&m_lockID_x) {
00087         reserve(_size);
00088     };


Member Function Documentation

template<class _T, int _size>
void cmn_LockIDbyOwn< _T, _size >::SetMutex (  )  [inline]

Definition at line 102 of file cmn_lockidbyown.h.

References cmn_Mutex::Lock(), and cmn_LockIDbyOwn< _T, _size >::m_lockID_x.

Referenced by fio_TransGroupLock< _T, _defTransEl >::LockByIDOwn().

00102                     {
00103         m_lockID_x.Lock();
00104     }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class _T, int _size>
void cmn_LockIDbyOwn< _T, _size >::ReleaseMutex (  )  [inline]

Definition at line 106 of file cmn_lockidbyown.h.

References cmn_LockIDbyOwn< _T, _size >::m_lockID_x, and cmn_Mutex::Unlock().

Referenced by fio_TransGroupLock< _T, _defTransEl >::LockByIDOwn().

00106                         {
00107         m_lockID_x.Unlock();
00108     }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class _T, int _size>
void cmn_LockIDbyOwn< _T, _size >::LockByID ( const _T  a_ID  )  [inline]

This lock is used for individual locking.

Definition at line 115 of file cmn_lockidbyown.h.

References cmn_LockIDbyOwn< _T, _size >::m_lockID_x, cmn_LockIDbyOwn< _T, _size >::m_releasedLockID_c, and cmn_Condition::Wait().

00115                                  {
00116 
00117         cmn_MutexLock l(m_lockID_x);
00118 
00119 loop:
00120         cmn_LockIDbyOwn_v_i iter  = this->begin();
00121         cmn_LockIDbyOwn_v_i endel = this->end();
00122         while (iter != endel) {
00123             if (iter->m_id == a_ID) {
00124                 m_releasedLockID_c.Wait();
00125                 goto loop;
00126              }
00127              iter++;
00128         }
00129         // doesn't matter who is owner
00130         insert(endel, cmn_LockEl_t(a_ID, -1));
00131     };

Here is the call graph for this function:

template<class _T, int _size>
void cmn_LockIDbyOwn< _T, _size >::LockByIDOwn ( const cmn_LockEl_t a_ID  )  [inline]

Definition at line 135 of file cmn_lockidbyown.h.

References assert, cmn_IDOwn< _T >::m_id, cmn_LockIDbyOwn< _T, _size >::m_lockID_x, cmn_IDOwn< _T >::m_ownerID, cmn_LockIDbyOwn< _T, _size >::m_releasedLockID_c, and cmn_Condition::Wait().

00135                                                {
00136 
00137         assert(a_ID.m_ownerID >= 0);
00138         cmn_MutexLock l(m_lockID_x);
00139 
00140 loop:
00141         cmn_LockIDbyOwn_v_i endel = this->end();
00142         cmn_LockIDbyOwn_v_i iter  = this->begin();
00143         while (iter != this->end()) { // don't know why but using end() is faster than endel
00144             if (   iter->m_id == a_ID.m_id
00145                 && iter->m_ownerID != a_ID.m_ownerID) {
00147                 // and flush 
00148                 m_releasedLockID_c.Wait();
00149                 goto loop;
00150              }
00151              iter++;
00152         }
00153         insert(endel, a_ID); // here is oposite
00154     };

Here is the call graph for this function:

template<class _T, int _size>
bool cmn_LockIDbyOwn< _T, _size >::CanLockByID ( const _T  a_ID  )  [inline]

This lock is used for individual locking.

Definition at line 161 of file cmn_lockidbyown.h.

References cmn_LockIDbyOwn< _T, _size >::m_lockID_x.

00161                                     {
00162 
00163         cmn_MutexLock l(m_lockID_x);
00164 
00165         cmn_LockIDbyOwn_v_i iter  = this->begin();
00166         cmn_LockIDbyOwn_v_i endel = this->end();
00167         while (iter != endel) {
00168             if (iter->m_id == a_ID) {
00169                 return false;
00170              }
00171              iter++;
00172         }
00173         // doesn't matter who is owner
00174         insert(endel, cmn_LockEl_t(a_ID, -1));
00175         return true;
00176     };

template<class _T, int _size>
cmn_Lock_e cmn_LockIDbyOwn< _T, _size >::CanLockByIDOwn ( const cmn_LockEl_t a_ID  )  [inline]

Definition at line 180 of file cmn_lockidbyown.h.

References assert, eLckOtherOwn, eLckSameOwn, eNotLocked, cmn_IDOwn< _T >::m_id, cmn_LockIDbyOwn< _T, _size >::m_lockID_x, and cmn_IDOwn< _T >::m_ownerID.

00180                                                         {
00181 
00182         assert(a_ID.m_ownerID >= 0);
00183         cmn_MutexLock l(m_lockID_x);
00184 
00185         cmn_LockIDbyOwn_v_i iter  = this->begin();
00186         cmn_LockIDbyOwn_v_i endel = this->end();
00187         while (iter != endel) {
00188             if (iter->m_id == a_ID.m_id) {
00189                 if (iter->m_ownerID == a_ID.m_ownerID) {
00190                     return eLckSameOwn;
00191                 }
00192                 return eLckOtherOwn;
00193              }
00194              iter++;
00195         }
00196         insert(endel, a_ID);
00197         return eNotLocked;
00198     };

template<class _T, int _size>
int cmn_LockIDbyOwn< _T, _size >::CanLockByIDOwnNoMutex ( const cmn_LockEl_t a_ID  )  [inline]

return -9999 if not locked return ownerID if element is already locked

Definition at line 206 of file cmn_lockidbyown.h.

References assert, elementIsNotLocked_d, cmn_IDOwn< _T >::m_id, and cmn_IDOwn< _T >::m_ownerID.

Referenced by fio_TransGroupLock< _T, _defTransEl >::LockByIDOwn().

00206                                                         {
00207 
00208         assert(a_ID.m_ownerID >= 0);
00209 
00210         cmn_LockIDbyOwn_v_i iter  = this->begin();
00211         cmn_LockIDbyOwn_v_i endel = this->end();
00212         while (iter != endel) {
00213             if (iter->m_id == a_ID.m_id) {
00214                 return iter->m_ownerID;
00215              }
00216              iter++;
00217         }
00218         insert(endel, a_ID);
00219         return elementIsNotLocked_d;
00220     };

Here is the caller graph for this function:

template<class _T, int _size>
void cmn_LockIDbyOwn< _T, _size >::UnLockByID ( const _T  a_ID  )  [inline]

Definition at line 224 of file cmn_lockidbyown.h.

References cmn_Condition::Broadcast(), ie_INVALID_ARG, cmn_LockIDbyOwn< _T, _size >::m_lockID_x, and cmn_LockIDbyOwn< _T, _size >::m_releasedLockID_c.

00224                                    {
00225 
00226         cmn_MutexLock l(m_lockID_x);
00227 
00228         cmn_LockIDbyOwn_v_i endel = this->end();
00229         cmn_LockIDbyOwn_v_i iter  = this->begin();
00230         while (iter != this->end()) {  // call end() is optimized by compiler ??? it is faster than endel use
00231             if (iter->m_id == a_ID) {
00232                 if (iter != --endel) { // endel become last
00233                     *iter = *endel;  // if iter is not last move last to current
00234                 }
00235                 erase(endel);  // remove last
00236 
00237                 m_releasedLockID_c.Broadcast(); //TODO where to set timeout period, use ETIMEDOUT
00238                 return;
00239             }
00240              iter++;
00241         }
00242 //      exit from while loop mean error
00243         throw ivd_InternalError(ie_INVALID_ARG, 
00244             "Try to unlock ID, but has not been locked.", true);
00245     }

Here is the call graph for this function:


Member Data Documentation

template<class _T, int _size>
cmn_Mutex cmn_LockIDbyOwn< _T, _size >::m_lockID_x [private]

template<class _T, int _size>
cmn_Condition cmn_LockIDbyOwn< _T, _size >::m_releasedLockID_c [private]

template<class _T, int _size>
cmn_LockIDbyOwn< _T, _size >::log_CLASSID_m

Definition at line 98 of file cmn_lockidbyown.h.


The documentation for this class was generated from the following file:

Generated on Mon Feb 27 19:05:11 2012 for OPENARCHIVE by  doxygen 1.5.6