aboutsummaryrefslogtreecommitdiff
path: root/src/lua/thread/Thread.h
blob: 4e39c3421d71d75c9421822fff9a4788b84c439d (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 "../luaopen_types.h"

namespace jin
{
namespace lua
{
namespace thread
{

    class Thread
    {
    public:
        typedef jin::thread::Thread::Variant Variant;
        typedef jin::thread::Thread::ThreadRunner ThreadRunner;

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

    };

} // thread
} // lua
} // jin