aboutsummaryrefslogtreecommitdiff
path: root/src/libjin-lua/modules/thread/l_thread.h
blob: 957abb18a7fb3ebfb76b6e0359532058fb532d7b (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
#include "libjin/jin.h"
#include "common/l_common.h"

namespace JinEngine
{
	namespace Lua
	{

		extern const char* Jin_Lua_Thread;

		class Thread : public Object
		{
		public:
			typedef JinEngine::Threads::Thread::Variant Variant;
			typedef JinEngine::Threads::Thread::ThreadRunner ThreadRunner;

			Thread(std::string _name, std::string _code, ThreadRunner runner)
				: name(_name)
				, code(_code)
			{
				thread = new JinEngine::Threads::Thread(_name, runner);
			}

			~Thread()
			{
				delete thread;
			}

			bool start(void* p)
			{
				return thread->start(p);
			}

			void wait()
			{
				thread->wait();
			}

			void send(int slot, const Variant& value)
			{
				thread->send(slot, value);
			}

			bool receive(int slot)
			{
				return thread->receive(slot);
			}

			Variant fetch(int slot)
			{
				return thread->fetch(slot);
			}

			Variant demand(int slot)
			{
				return thread->demand(slot);
			}

			void remove(int slot)
			{
				thread->remove(slot);
			}

			const char* getName()
			{
				return name.c_str();
			}

			bool isRunning()
			{
				return thread->isRunning();
			}

			void lock()
			{
				thread->lock();
			}

			void unlock()
			{
				thread->unlock();
			}

			const std::string name;
			const std::string code;

		private:
			JinEngine::Threads::Thread* thread;

		};

		int luaopen_thread(lua_State* L);

	} // namespace Lua
} // namespace JinEngine