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
ZenLib::Thread::Pause
returnvalue Pause()
ZenLib::Thread::IsTerminating
bool IsTerminating()
ZenLib::Thread::Resource
@ Resource
Definition: Thread.h:46
ZenLib::Thread::Run
returnvalue Run()
ZenLib::Thread::Sleep
void Sleep(std::size_t Millisecond)
ZenLib::Thread::Incoherent
@ Incoherent
Definition: Thread.h:45
ZenLib::Thread::Priority_Set
void Priority_Set(int8s Priority)
ZenLib::Thread
Thread manipulation.
Definition: Thread.h:33
ZenLib::Thread::Ok
@ Ok
Definition: Thread.h:43
ZenLib::Thread::RequestTerminate
returnvalue RequestTerminate()
ZenLib::Thread::Thread
Thread()
ZenLib::Thread::IsNotRunning
@ IsNotRunning
Definition: Thread.h:44
ZenLib::Thread::~Thread
virtual ~Thread()
Conf.h
ZenLib::Thread::returnvalue
returnvalue
Definition: Thread.h:41
ZenLib::Thread::IsRunning
bool IsRunning()
ZenLib
Definition: BitStream.h:23
ZenLib::Thread::IsExited
bool IsExited()
ZenLib::Thread::ForceTerminate
returnvalue ForceTerminate()
ZenLib::Thread::RunAgain
returnvalue RunAgain()
CriticalSection.h
ZenLib::Thread::Internal_Exit
returnvalue Internal_Exit()
ZenLib::Thread::Yield
void Yield()
ZenLib::Thread::Entry
virtual void Entry()