1 /*******************************************************************************
5 * Created : 2009-10-8 11:14:55
7 ******************************************************************************/
9 #ifndef __HLH_THREAD_INC_20091008_111455_HENRY__
10 #define __HLH_THREAD_INC_20091008_111455_HENRY__
13 /*******************************************************************************
14 * Desc : Includes Files
15 ******************************************************************************/
16 #include "HLH_utils/typedef.h"
17 #include "HLH_utils/HLH_Mutex.h"
20 /*******************************************************************************
21 * Desc : Macro Definations
22 ******************************************************************************/
23 #define HLH_THREAD_ERR_FAILED (-1)
24 #define HLH_THREAD_ERR_CANT_START_THREAD (-2)
25 #define HLH_THREAD_ERR_NOT_RUNNING (-3)
26 #define HLH_THREAD_ERR_ALREADY_RUNNING (-4)
27 #define HLH_THREAD_ERR_ALREADY_STOPPING (-5)
31 /*******************************************************************************
32 * Desc : Type Definations
33 ******************************************************************************/
35 typedef void * (*ThreadFunc
) (HLH_Thread
&zhtThread
, void *pvParam
);
38 /*******************************************************************************
39 * Desc : Global Variables
40 ******************************************************************************/
43 /*******************************************************************************
45 ******************************************************************************/
51 /******************************************************************************
52 * Desc : Constructor / Deconstructor
53 ******************************************************************************/
55 virtual ~HLH_Thread ();
58 /******************************************************************************
60 ******************************************************************************/
62 // ztfThreadFunc () should call zhtThread.ThreadStarted () after thread prepared
63 // and should handle the stop request ( zhtThread.IsStopping() == ture )
64 int Start (ThreadFunc ztfThreadFunc
, void *pvThreadParam
);
72 void *GetReturnValue ();
75 // Should be call by ThreadFunc () to notify that it has start
76 void ThreadStarted ();
79 /******************************************************************************
80 * Desc : Private Operations
81 ******************************************************************************/
82 static void * TheThread (void *pvThis
);
85 /******************************************************************************
87 ******************************************************************************/
90 pthread_t m_zpThreadId
;
93 // Functions to execute during thread
94 ThreadFunc m_ztfThreadFunc
;
96 // Parameter for m_ztfThreadFunc ()
97 void *m_pvThreadParam
;
100 // Return value of \c m_ztfThreadFunc ()
103 // Whether this thread is running
106 // Whether stop is requested
110 HLH_Mutex m_zhmRunMutex
;
111 HLH_Mutex m_zhmContinueMutex
;
112 HLH_Mutex m_zhmContinueMutex2
;
119 #endif /* __HLH_THREAD_INC_20091008_111455_HENRY__ */