This repository was archived by the owner on Apr 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThread.h
More file actions
81 lines (60 loc) · 1.27 KB
/
Thread.h
File metadata and controls
81 lines (60 loc) · 1.27 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
80
81
/*
* Thread.h
*
* Created on: 2011-2-16
* Author: simophin
*/
#ifndef THREAD_H_
#define THREAD_H_
#include <memory>
#include "utils/NonCopyable.hpp"
#include "Error.h"
class ThreadImpl;
class Thread: public Utils::NonCopyable {
friend class ThreadImpl;
public:
Thread();
virtual ~Thread();
virtual Error entry () = 0;
Error run();
Error wait(Error *returned = 0,int ms = -1);
Error stop(int ms = -1);
void stopNoWait();
bool isRunning() const;
protected:
bool shouldStop() const;
void sleep(int ms);
private:
std::auto_ptr<ThreadImpl> d;
};
class MutexImpl;
class Condition;
class Mutex: public Utils::NonCopyable {
friend class MutexImpl;
friend class Condition;
public:
enum Type {
Normal,
Recursive
};
Mutex(Type t = Normal);
virtual ~Mutex();
virtual Error lock(int ms = -1);
virtual void unlock();
virtual bool trylock();
private:
std::auto_ptr<MutexImpl> d;
};
class ConditionImpl;
class Condition: public Utils::NonCopyable {
friend class ConditionImpl;
public:
Condition();
virtual ~Condition();
virtual Error wait(Mutex &,int ms = -1);
virtual void signal();
virtual void broadcast();
private:
std::auto_ptr<ConditionImpl> d;
};
#endif /* THREAD_H_ */