add HLH_Ref
[HLH_utils.git] / HLH_Mutex.h
blob5a4c623e5f1824f2533ef072745dccea9e7d873c
1 /*******************************************************************************
2 * File : HLH_Mutex.h
3 *
4 * Author : Henry He
5 * Created : 2009-10-8 11:08:38
6 * Description :
7 ******************************************************************************/
9 #ifndef __HLH_MUTEX_INC_20091008_110838_HENRY__
10 #define __HLH_MUTEX_INC_20091008_110838_HENRY__
13 /*******************************************************************************
14 * Desc : Includes Files
15 ******************************************************************************/
16 #include <pthread.h>
19 /*******************************************************************************
20 * Desc : Macro Definations
21 ******************************************************************************/
22 #define HLH_MUTEX_ERR_FAILED (-1)
23 #define HLH_MUTEX_ERR_ALREADY_INITED (-2)
24 #define HLH_MUTEX_ERR_NOT_INIT (-3)
25 #define HLH_MUTEX_ERR_CANT_INIT (-4)
29 /*******************************************************************************
30 * Desc : Type Definations
31 ******************************************************************************/
34 /*******************************************************************************
35 * Desc : Global Variables
36 ******************************************************************************/
39 /*******************************************************************************
40 * Desc : Classes
41 ******************************************************************************/
42 class HLH_Mutex
45 friend class HLH_Cond;
47 public:
48 /******************************************************************************
49 * Desc : Constructor / Deconstructor of HLH_Mutex
50 ******************************************************************************/
52 // Constructor of HLH_Mutex
53 HLH_Mutex();
55 // Deconstructor of HLH_Mutex
56 ~HLH_Mutex();
58 public:
59 /******************************************************************************
60 * Desc : Operations
61 ******************************************************************************/
63 // Init this mutex
64 int Init ();
66 // Destroy this mutex
67 void Destroy ();
69 // Lock this mutex
70 int Lock ();
72 // Unlock this mutex
73 int Unlock ();
75 // Whether this mutex initialized
76 bool IsInited () { return m_bInited; }
78 bool IsLocked () { return m_bLocked; }
80 private:
81 /******************************************************************************
82 * Desc : Private Data
83 ******************************************************************************/
84 // Whether this mutex created
85 bool m_bInited;
87 // Whether this mutex locked;
88 bool m_bLocked;
90 // Internal mutex of HLH_Mutex
91 pthread_mutex_t m_mMutex;
97 /******************************************************************************
98 * Desc : Auto initialized HLH_Mutex
99 ******************************************************************************/
100 class HLH_AutoMutex : public HLH_Mutex
102 public:
103 HLH_AutoMutex () { HLH_Mutex::Init (); }
112 #endif /* __HLH_MUTEX_INC_20091008_110838_HENRY__ */