blob: 1bd5f150b682554b3880f3b6d646ea4fe5ea1ed0 (
plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#ifndef __ASURA_THREAD_H__
#define __ASURA_THREAD_H__
#include <string>
#include <queue>
#include <asura-lib-utils/scripting/portable.hpp>
#include "task.h"
#include "mutex.h"
namespace AsuraEngine
{
namespace Threading
{
class ThreadImpl;
///
/// ߳壬ÿ߳άһtask queue
///
class Thread ASURA_FINAL
: public AEScripting::Portable<Thread>
{
public:
LUAX_DECL_FACTORY(Thread);
Thread(Luax::LuaxState& father, const std::string& name = "");
~Thread();
bool AddTask(Task* task);
void Start(uint32 stacksize = 0);
///
/// ǿֹ̡߳עҪnewdeleteִ֮TerminateThreadڼʹnewˡ
/// https://blog.csdn.net/anye3000/article/details/7470674
///
void Kill();
///
/// ̵߳ȴ߳̽żִС
///
void Join();
bool IsRunning();
bool IsCurrent();
///
/// ִС
///
void Execute();
const std::string& GetName();
private:
LUAX_DECL_METHOD(_New);
LUAX_DECL_METHOD(_Start);
LUAX_DECL_METHOD(_Join);
LUAX_DECL_METHOD(_Kill);
LUAX_DECL_METHOD(_AddTask);
LUAX_DECL_METHOD(_IsRunning);
LUAX_DECL_METHOD(_IsCurrent);
LUAX_DECL_METHOD(_GetName);
ThreadImpl* mImpl;
std::string mName;
///
/// С
///
std::queue<Task*> mTaskQueue;
Mutex mMutex;
///
/// ̵߳luaִջΪ˱ִջͻ
///
lua_State* mState;
Luax::LuaxMemberRef mStateRef;
};
///
/// ̵߳ľʵ֣ûģһֲԣ
/// 1: win32
/// 2: posix
/// 3: SDL
/// 4: std::thread
///
ASURA_ABSTRACT class ThreadImpl
{
public:
ThreadImpl() {};
virtual ~ThreadImpl() {};
virtual bool Start(Thread* thread, uint32 stacksize = 0) = 0;
virtual void Join() = 0;
virtual void Kill() = 0;
virtual bool IsRunning() = 0;
virtual bool IsCurrent() = 0;
};
}
}
#endif
|