aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/thread/je_lua_thread.h
blob: de9a8a88bf4341b5353cf6005fef8aa88fe69b3d (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
#include "libjin/jin.h"
#include "lua/common/je_lua_common.h"

namespace JinEngine
{
    namespace Lua
    {
        namespace thread
        {

            class Thread
            {
            public:
                typedef JinEngine::MultiThread::Thread::Variant Variant;
                typedef JinEngine::MultiThread::Thread::ThreadRunner ThreadRunner;

                Thread(std::string _name, std::string _code, ThreadRunner runner)
                    : name(_name)
                    , code(_code)
                {
                    thread = new JinEngine::MultiThread::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::MultiThread::Thread* thread;

            };

        } // thread
    } // namespace Lua
} // namespace JinEngine