Main Page Modules Class Hierarchy Data Structures File List Data Fields Globals Related Pages

# oscl_lock_base.h

Go to the documentation of this file.

    00001 // -*- c++ -*-
    00002 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    00003
    00004 //               O S C L _ L O C K _ B A S E
    00005
    00006 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    00007
    00023 #ifndef OSCL_LOCK_BASE_H_INCLUDED
    00024 #define OSCL_LOCK_BASE_H_INCLUDED
    00025
    00026
    00027 class OsclLockBase
    00028 {
    00029
    00030     public:
    00031         virtual void Lock() = 0;
    00032         virtual void Unlock() = 0;
    00033         virtual ~OsclLockBase() {}
    00034
    00035 };
    00036
    00037 class OsclNullLock: public OsclLockBase
    00038 {
    00039
    00040     public:
    00041         virtual void Lock() {};
    00042         virtual void Unlock() {};
    00043         virtual ~OsclNullLock() {}
    00044
    00045 };
    00046
    00047
    00048
    00060 template<class LockClass> class OsclScopedLock
    00061 {
    00062     private:
    00063         LockClass* _Ptr;
    00064
    00065         // make copy constructor private so no default is created.
    00073         OsclScopedLock(const OsclScopedLock<LockClass>&) {}
    00074
    00075
    00081         void release()
    00082         {
    00083             if (_Ptr)
    00084             {
    00085                 _Ptr->Unlock();
    00086                 _Ptr = NULL;
    00087             }
    00088         }
    00089
    00090
    00095         void acquire()
    00096         {
    00097             if (_Ptr)
    00098             {
    00099                 _Ptr->Lock();
    00100             }
    00101         }
    00102
    00103
    00104     public:
    00105
    00110         explicit OsclScopedLock(LockClass& inLock) : _Ptr(&inLock)
    00111         {
    00112             acquire();
    00113         };
    00114
    00120         ~OsclScopedLock()
    00121         {
    00122             release();
    00123         }
    00124
    00125
    00126
    00127 };
    00128
    00129
    00133 #endif