-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfbThread.h
More file actions
79 lines (64 loc) · 2 KB
/
fbThread.h
File metadata and controls
79 lines (64 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* $Id: fbThread.h,v 1.10 2008/03/29 19:05:26 wyverex Exp $ */
#ifndef fbTHREAD_H
#define fbTHREAD_H
#include "global.h"
#include "fbData.h"
/**
* fbThread
* Base Thread object
* @author Byron Heads
* @date March 05, 2008
* @note 3/5/08 - Created fbThread
*/
class fbThread
{
public:
fbThread(fbData* _data); /// < Overloaded Constructor, ErrorLogger
virtual ~fbThread(); /// < Destructor
void start(); /// < starts the thread
void startDelete(); /// < starts the thread
void stop(); /// < tell thread to stop
void forceStop(); /// < force the thread to stop
void pause(); /// < pause the thread, if running
void resume(); /// < resumes a paused thread
bool isRunning(); /// < is the thread running
bool isPaused(); /// < is the thread paused
bool isStopping(); /// < is the thread stopping?
void _sleep(int sec); /// < thread sleeps for the given number of seconds
void _usleep(int msec); /// < thread sleeps for the given number of milliseconds
void _yield(); /// < thread yieids for other threads to run
private:
bool _running; /// < is thread running
bool _stopping; /// < did we get a stop?
bool _paused; /// < has the thread been paused
fbData* data; /// < Threads Error Logger
#ifdef Win32
HANDLE _hThread; /// < handle to running thread
static DWORD WINAPI threadStart(LPVOID thread); /// < Real thread func
static DWORD WINAPI threadStartDelete(LPVOID thread); /// < Real thread func, deletes thread when done
#else
pthread_t _hThread; /// < handle to running thread
static void* threadStart(void* thread); /// < Real thread func
static void* threadStartDelete(void* thread); /// < Real thread func, deletes thread when done
#endif
virtual void run(); /// < Overload this function to run your thread in
};
#endif
/*
//example usage
#include "fbThread.h"
class foo: public fbThread
{
private:
void run()
{
cout << "Thread Starting.." << endl;
while(!isStopping())
{
sleep(1);
cout << "Still.. running!" << endl;
}
cout << "Thread stopping.." << endl;
}
};
*/