Public Types | Public Member Functions | Public Attributes | Private Attributes

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.

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

Detailed Description

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

Definition at line 93 of file cmn_lockidbyown.h.


Member Typedef Documentation

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

Definition at line 96 of file cmn_lockidbyown.h.

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

Definition at line 95 of file cmn_lockidbyown.h.


Constructor & Destructor Documentation

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

Definition at line 98 of file cmn_lockidbyown.h.

        : 
        m_releasedLockID_c(&m_lockID_x) {
        reserve(_size);
    };


Member Function Documentation

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 175 of file cmn_lockidbyown.h.

References cmn_LockIDbyOwn< _T, _size >::m_lockID_x.

                                    {

        cmn_MutexLock l(m_lockID_x);

        cmn_LockIDbyOwn_v_i iter  = this->begin();
        cmn_LockIDbyOwn_v_i endel = this->end();
        while (iter != endel) {
            if (iter->m_id == a_ID) {
                return false;
             }
             iter++;
        }
        // doesn't matter who is owner
        insert(endel, cmn_LockEl_t(a_ID, -1));
        return true;
    };

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

Definition at line 194 of file cmn_lockidbyown.h.

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

                                                        {

        assert(a_ID.m_ownerID >= 0);
        cmn_MutexLock l(m_lockID_x);

        cmn_LockIDbyOwn_v_i iter  = this->begin();
        cmn_LockIDbyOwn_v_i endel = this->end();
        while (iter != endel) {
            if (iter->m_id == a_ID.m_id) {
                if (iter->m_ownerID == a_ID.m_ownerID) {
                    return eLckSameOwn;
                }
                return eLckOtherOwn;
             }
             iter++;
        }
        insert(endel, a_ID);
        return eNotLocked;
    };

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 220 of file cmn_lockidbyown.h.

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

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

                                                        {

        assert(a_ID.m_ownerID >= 0);

        cmn_LockIDbyOwn_v_i iter  = this->begin();
        cmn_LockIDbyOwn_v_i endel = this->end();
        while (iter != endel) {
            if (iter->m_id == a_ID.m_id) {
                return iter->m_ownerID;
             }
             iter++;
        }
        insert(endel, a_ID);
        return elementIsNotLocked_d;
    };

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 129 of file cmn_lockidbyown.h.

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

                                 {

        cmn_MutexLock l(m_lockID_x);

loop:
        cmn_LockIDbyOwn_v_i iter  = this->begin();
        cmn_LockIDbyOwn_v_i endel = this->end();
        while (iter != endel) {
            if (iter->m_id == a_ID) {
                m_releasedLockID_c.Wait();
                goto loop;
             }
             iter++;
        }
        // doesn't matter who is owner
        insert(endel, cmn_LockEl_t(a_ID, -1));
    };

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 149 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().

                                               {

        assert(a_ID.m_ownerID >= 0);
        cmn_MutexLock l(m_lockID_x);

loop:
        cmn_LockIDbyOwn_v_i endel = this->end();
        cmn_LockIDbyOwn_v_i iter  = this->begin();
        while (iter != this->end()) { // don't know why but using end() is faster than endel
            if (   iter->m_id == a_ID.m_id
                && iter->m_ownerID != a_ID.m_ownerID) {
                // and flush 
                m_releasedLockID_c.Wait();
                goto loop;
             }
             iter++;
        }
        insert(endel, a_ID); // here is oposite
    };

Here is the call graph for this function:

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

Definition at line 120 of file cmn_lockidbyown.h.

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

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

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 >::SetMutex (  )  [inline]

Definition at line 116 of file cmn_lockidbyown.h.

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

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

                    {
        m_lockID_x.Lock();
    }

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 >::UnLockByID ( const _T  a_ID  )  [inline]

Definition at line 238 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.

                                   {

        cmn_MutexLock l(m_lockID_x);

        cmn_LockIDbyOwn_v_i endel = this->end();
        cmn_LockIDbyOwn_v_i iter  = this->begin();
        while (iter != this->end()) {  // call end() is optimized by compiler ??? it is faster than endel use
            if (iter->m_id == a_ID) {
                if (iter != --endel) { // endel become last
                    *iter = *endel;  // if iter is not last move last to current
                }
                erase(endel);  // remove last

                m_releasedLockID_c.Broadcast(); //TODO where to set timeout period, use ETIMEDOUT
                return;
            }
             iter++;
        }
//      exit from while loop mean error
        throw ivd_InternalError(ie_INVALID_ARG, 
            "Try to unlock ID, but has not been locked.", true);
    }

Here is the call graph for this function:


Member Data Documentation

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

Definition at line 112 of file cmn_lockidbyown.h.

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]

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