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

# oscl_mutex.h

Go to the documentation of this file.

    00001
    00002 // -*- c++ -*-
    00003 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    00004
    00005 //                     O S C L _ M U T E X
    00006
    00007 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    00008
    00015 #ifndef OSCL_MUTEX_H_INCLUDED
    00016 #define OSCL_MUTEX_H_INCLUDED
    00017
    00018 #ifndef OSCLCONFIG_PROC_H_INCLUDED
    00019 #include "osclconfig_proc.h"
    00020 #endif
    00021 #ifndef OSCL_TYPES_H_INCLUDED
    00022 #include "oscl_types.h"
    00023 #endif
    00024 #ifndef OSCL_BASE_H_INCLUDED
    00025 #include "oscl_base.h"
    00026 #endif
    00027 #ifndef OSCL_THREAD_H_INCLUDED
    00028 #include "oscl_thread.h"
    00029 #endif
    00030 #ifndef OSCL_LOCK_BASE_H_INCLUDED
    00031 #include "oscl_lock_base.h"
    00032 #endif
    00033
    00034
    00038 class OsclMutex : public OsclLockBase
    00039 {
    00040     public:
    00041
    00045         OSCL_IMPORT_REF OsclMutex();
    00046
    00050         OSCL_IMPORT_REF virtual ~OsclMutex();
    00051
    00060         OSCL_IMPORT_REF OsclProcStatus::eOsclProcError Create(void);
    00061
    00062
    00070         OSCL_IMPORT_REF void Lock();
    00071
    00083         OSCL_IMPORT_REF OsclProcStatus::eOsclProcError TryLock();
    00084
    00085
    00093         OSCL_IMPORT_REF void Unlock();
    00094
    00095
    00104         OSCL_IMPORT_REF OsclProcStatus::eOsclProcError Close(void);
    00105
    00106     private:
    00107
    00115         OsclProcStatus::eOsclProcError ErrorMapping(int32 Error);
    00116
    00117         TOsclMutexObject    ObjMutex;
    00118         bool bCreated;
    00119
    00120 };
    00121
    00136 #if !OSCL_HAS_NON_PREEMPTIVE_THREAD_SUPPORT
    00137 //In pre-emptive threading, OsclNoYieldMutex is identical to OsclMutex
    00138 typedef OsclMutex OsclNoYieldMutex;
    00139 #else
    00140 //In non-pre-emptive threading, OsclNoYieldMutex is a NO-OP.
    00141 class OsclNoYieldMutex : public OsclLockBase
    00142 {
    00143     public:
    00144
    00148         OsclNoYieldMutex()
    00149         {
    00150 #if (!OSCL_RELEASE_BUILD)
    00151             iNumLock = 0;
    00152             bCreated = false;
    00153 #endif
    00154         }
    00155
    00159         virtual ~OsclNoYieldMutex()
    00160         {}
    00161
    00170         OsclProcStatus::eOsclProcError Create(void)
    00171         {
    00172 #if (!OSCL_RELEASE_BUILD)
    00173             if (bCreated)
    00174                 return OsclProcStatus::INVALID_OPERATION_ERROR;
    00175             bCreated = true;
    00176 #endif
    00177             return OsclProcStatus::SUCCESS_ERROR;
    00178         }
    00179
    00180
    00188         void Lock()
    00189         {
    00190 #if (!OSCL_RELEASE_BUILD)
    00191             OSCL_ASSERT(bCreated);
    00192             OSCL_ASSERT(iNumLock == 0);//detect deadlock condition.
    00193             iNumLock++;
    00194 #endif
    00195         }
    00196
    00208         OsclProcStatus::eOsclProcError TryLock()
    00209         {
    00210 #if (!OSCL_RELEASE_BUILD)
    00211             if (!bCreated)
    00212                 return OsclProcStatus::INVALID_OPERATION_ERROR;
    00213             if (iNumLock)
    00214                 return OsclProcStatus::MUTEX_LOCKED_ERROR;
    00215             else
    00216                 Lock();
    00217             return OsclProcStatus::SUCCESS_ERROR;
    00218 #endif
    00219         }
    00220
    00221
    00229         void Unlock()
    00230         {
    00231 #if (!OSCL_RELEASE_BUILD)
    00232             OSCL_ASSERT(bCreated);
    00233             OSCL_ASSERT(iNumLock);
    00234             if (iNumLock > 0)
    00235                 iNumLock--;
    00236 #endif
    00237         }
    00238
    00239
    00248         OsclProcStatus::eOsclProcError Close(void)
    00249         {
    00250 #if (!OSCL_RELEASE_BUILD)
    00251             if (!bCreated)
    00252                 return OsclProcStatus::INVALID_OPERATION_ERROR;
    00253             bCreated = false;
    00254 #endif
    00255             return OsclProcStatus::SUCCESS_ERROR;
    00256         }
    00257
    00258     private:
    00259
    00260 #if (!OSCL_RELEASE_BUILD)
    00261         uint32 iNumLock;
    00262         bool bCreated;
    00263 #endif
    00264
    00265 };
    00266 #endif //OSCL_HAS_NON_PREEMPTIVE_THREAD_SUPPORT
    00267
    00271 class OsclThreadLock: public OsclLockBase
    00272 {
    00273     public:
    00274         OSCL_IMPORT_REF OsclThreadLock();
    00275         OSCL_IMPORT_REF virtual ~OsclThreadLock();
    00276         OSCL_IMPORT_REF void Lock();
    00277         OSCL_IMPORT_REF void Unlock();
    00278     private:
    00279         OsclMutex iMutex;
    00280 };
    00281
    00282 #endif
    00283
    00284
    00285