#include <cmn_LockID.h>


Alghorith use vector<_T> for locking elements, thus ID can be any type that vector can handle it.
Instantiation of lockID object
cmn_LockID<ivd_RecordIDX_t> m_LockByRecordIdx;
Lock element with index 1
ivd_RecordIdx_t idx = 1;
m_LockByRecordIdx.LockByID(idx);
Try to lock and if lock it. The return value is true if locked othervice is false.
bool locked = m_LockByRecordIdx.CanLockByID(<elementID>);
UnLock element with index 1
ivd_RecordIdx_t idx = 1;
m_LockByRecordIdx.UnLockByID(idx);
Definition at line 68 of file cmn_LockID.h.
Public Member Functions | |
| cmn_LockID () | |
| cmn_LockID (int a_size) | |
| void | LockByID (register _T &a_ID) |
| bool | CanLockByID (_T &a_ID) |
| void | UnLockByID (register _T &a_ID) |
Private Types | |
| typedef cmn_LockID< _T >::iterator | cmn_LockID_v_i |
Private Attributes | |
| cmn_Mutex | m_lockID_x |
| cmn_Condition | m_releasedLockID_c |
typedef cmn_LockID<_T>::iterator cmn_LockID< _T >::cmn_LockID_v_i [private] |
Definition at line 85 of file cmn_LockID.h.
| cmn_LockID< _T >::cmn_LockID | ( | ) | [inline] |
Definition at line 70 of file cmn_LockID.h.
00071 : 00072 m_releasedLockID_c(&m_lockID_x) { 00073 this->reserve(100); 00074 // Empty 00075 }
| cmn_LockID< _T >::cmn_LockID | ( | int | a_size | ) | [inline] |
Definition at line 76 of file cmn_LockID.h.
00077 : 00078 m_releasedLockID_c(&m_lockID_x) { 00079 this->reserve(a_size); 00080 // Empty 00081 }
| void cmn_LockID< _T >::LockByID | ( | register _T & | a_ID | ) | [inline] |
Definition at line 93 of file cmn_LockID.h.
References cmn_LockID< _T >::m_lockID_x, cmn_LockID< _T >::m_releasedLockID_c, and cmn_Condition::Wait().
Referenced by fsc_fileIDLock::fsc_fileIDLock().
00093 { 00094 cmn_MutexLock l(m_lockID_x); 00095 00096 loop: 00097 cmn_LockID_v_i endel = this->end(); 00098 cmn_LockID_v_i iter = this->begin(); 00099 while (iter != this->end()) { // don't know why but using end() is faster than endel 00100 if (*iter == a_ID) { 00101 m_releasedLockID_c.Wait(); 00102 goto loop; 00103 } 00104 iter++; 00105 } 00106 insert(endel, a_ID); // here is oposite 00107 };


| bool cmn_LockID< _T >::CanLockByID | ( | _T & | a_ID | ) | [inline] |
Definition at line 111 of file cmn_LockID.h.
References cmn_LockID< _T >::m_lockID_x.
00111 { 00112 cmn_MutexLock l(m_lockID_x); 00113 00114 cmn_LockID_v_i iter = this->begin(); 00115 cmn_LockID_v_i endel = this->end(); 00116 while (iter != endel) { 00117 if (*iter == a_ID) { 00118 return false; 00119 } 00120 iter++; 00121 } 00122 insert(endel, a_ID); 00123 return true; 00124 };
| void cmn_LockID< _T >::UnLockByID | ( | register _T & | a_ID | ) | [inline] |
Definition at line 128 of file cmn_LockID.h.
References cmn_Condition::Broadcast(), ie_INVALID_ARG, cmn_LockID< _T >::m_lockID_x, and cmn_LockID< _T >::m_releasedLockID_c.
Referenced by fsc_fileIDLock::~fsc_fileIDLock().
00128 { 00129 cmn_MutexLock l(m_lockID_x); 00130 00131 cmn_LockID_v_i endel = this->end(); 00132 cmn_LockID_v_i iter = this->begin(); 00133 while (iter != this->end()) { // call end() is optimized by compiler ??? it is faster than endel use 00134 if (*iter == a_ID) { 00135 goto remove; 00136 } 00137 iter++; 00138 } 00139 // exit from while loop mean error 00140 throw ivd_InternalError(ie_INVALID_ARG, 00141 "Tried to unlock ID which hasn't been locked."); 00142 00143 remove: 00144 if (iter != --endel) { // endel become last 00145 *iter = *endel; // if iter is not last move last to current 00146 } 00147 erase(endel); // remove last 00148 00149 m_releasedLockID_c.Broadcast(); //TODO where to set timeout period, use ETIMEDOUT 00150 }


cmn_Mutex cmn_LockID< _T >::m_lockID_x [private] |
Definition at line 88 of file cmn_LockID.h.
Referenced by cmn_LockID< _T >::CanLockByID(), cmn_LockID< _T >::LockByID(), and cmn_LockID< _T >::UnLockByID().
cmn_Condition cmn_LockID< _T >::m_releasedLockID_c [private] |
Definition at line 89 of file cmn_LockID.h.
Referenced by cmn_LockID< _T >::LockByID(), and cmn_LockID< _T >::UnLockByID().
1.5.6