ZenLib
Thread.h
Go to the documentation of this file.
1 /* Copyright (c) MediaArea.net SARL. All Rights Reserved.
2  *
3  * Use of this source code is governed by a zlib-style license that can
4  * be found in the License.txt file in the root of the source tree.
5  */
6 
7 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 //
9 // Thread functions
10 //
11 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12 
13 //---------------------------------------------------------------------------
14 #ifndef ZenLib_ThreadH
15 #define ZenLib_ThreadH
16 //---------------------------------------------------------------------------
17 #include "ZenLib/Conf.h"
18 #include "ZenLib/CriticalSection.h"
19 #ifdef _WINDOWS
20  #undef Yield
21 #endif
22 //---------------------------------------------------------------------------
23 
24 #include <stdlib.h>
25 
26 namespace ZenLib
27 {
28 
29 //***************************************************************************
30 /// @brief Thread manipulation
31 //***************************************************************************
32 
33 class Thread
34 {
35 public :
36  //Constructor/Destructor
37  Thread ();
38  virtual ~Thread ();
39 
40  //Control
42  {
43  Ok,
47  };
48  returnvalue Run();
53 
54  //Status
55  bool IsRunning();
56  bool IsTerminating();
57  bool IsExited();
58 
59  //Configuration
60  void Priority_Set(int8s Priority); //-100 to +100
61 
62  //Main Entry
63  virtual void Entry();
64 
65  //Internal
66  returnvalue Internal_Exit(); //Do not use it
67 
68 protected :
69 
70  //Communicating
71  void Sleep(std::size_t Millisecond);
72  void Yield();
73 
74 private :
75  //Internal
76  void* ThreadPointer;
77 
78  //The possible states of the thread ("-->" shows all possible transitions from this state)
79  enum state
80  {
81  State_New, // didn't start execution yet (--> Running)
82  State_Running, // thread is running (--> Paused, Terminating)
83  State_Paused, // thread is temporarily suspended (--> Running)
84  State_Terminating, // thread should terminate a.s.a.p. (--> Terminated)
85  State_Terminated, // thread is terminated
86  };
87  state State;
88  CriticalSection C;
89 };
90 
91 } //NameSpace
92 
93 #endif
virtual void Entry()
returnvalue ForceTerminate()
Definition: Thread.h:45
returnvalue
Definition: Thread.h:41
returnvalue RequestTerminate()
Definition: Thread.h:46
Definition: Thread.h:44
virtual ~Thread()
Definition: BitStream.h:23
Definition: Thread.h:43
bool IsTerminating()
returnvalue Pause()
void Sleep(std::size_t Millisecond)
Thread manipulation.
Definition: Thread.h:33
void Priority_Set(int8s Priority)
returnvalue Run()
returnvalue RunAgain()
returnvalue Internal_Exit()