ZenLib
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
ZenLib
Thread.h
Go to the documentation of this file.
1
// ZenLib::Thread - Thread functions
2
// Copyright (C) 2007-2011 MediaArea.net SARL, Info@MediaArea.net
3
//
4
// This software is provided 'as-is', without any express or implied
5
// warranty. In no event will the authors be held liable for any damages
6
// arising from the use of this software.
7
//
8
// Permission is granted to anyone to use this software for any purpose,
9
// including commercial applications, and to alter it and redistribute it
10
// freely, subject to the following restrictions:
11
//
12
// 1. The origin of this software must not be misrepresented; you must not
13
// claim that you wrote the original software. If you use this software
14
// in a product, an acknowledgment in the product documentation would be
15
// appreciated but is not required.
16
// 2. Altered source versions must be plainly marked as such, and must not be
17
// misrepresented as being the original software.
18
// 3. This notice may not be removed or altered from any source distribution.
19
//
20
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22
//
23
// Thread functions
24
//
25
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26
27
//---------------------------------------------------------------------------
28
#ifndef ZenLib_ThreadH
29
#define ZenLib_ThreadH
30
//---------------------------------------------------------------------------
31
#include "
ZenLib/Conf.h
"
32
#include "
ZenLib/CriticalSection.h
"
33
#ifdef _WINDOWS
34
#undef Yield
35
#endif
36
//---------------------------------------------------------------------------
37
38
#include <stdlib.h>
39
40
namespace
ZenLib
41
{
42
43
//***************************************************************************
44
/// @brief Thread manipulation
45
//***************************************************************************
46
47
class
Thread
48
{
49
public
:
50
//Constructor/Destructor
51
Thread
();
52
virtual
~Thread
();
53
54
//Control
55
enum
returnvalue
56
{
57
Ok
,
58
IsNotRunning
,
59
Incoherent
,
60
Resource
,
61
};
62
returnvalue
Run
();
63
returnvalue
RunAgain
();
64
returnvalue
Pause
();
65
returnvalue
RequestTerminate
();
66
returnvalue
ForceTerminate
();
67
68
//Status
69
bool
IsRunning
();
70
bool
IsTerminating
();
71
bool
IsExited
();
72
73
//Configuration
74
void
Priority_Set
(int8s Priority);
//-100 to +100
75
76
//Main Entry
77
virtual
void
Entry
();
78
79
//Internal
80
returnvalue
Internal_Exit
();
//Do not use it
81
82
protected
:
83
84
//Communicating
85
void
Sleep
(std::size_t Millisecond);
86
void
Yield
();
87
88
private
:
89
//Internal
90
void
* ThreadPointer;
91
92
//The possible states of the thread ("-->" shows all possible transitions from this state)
93
enum
state
94
{
95
State_New,
// didn't start execution yet (--> Running)
96
State_Running,
// thread is running (--> Paused, Terminating)
97
State_Paused,
// thread is temporarily suspended (--> Running)
98
State_Terminating,
// thread should terminate a.s.a.p. (--> Terminated)
99
State_Terminated,
// thread is terminated
100
};
101
state State;
102
CriticalSection C;
103
};
104
105
}
//NameSpace
106
107
#endif
Generated on Sat Feb 16 2013 20:59:28 for ZenLib by
1.8.3