aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/thread/Thread.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-08-20 11:51:32 +0800
committerchai <chaifix@163.com>2018-08-20 11:51:32 +0800
commit65bafdc682db46f0f115374ad39f1fbc348832ac (patch)
tree7862548cdf01060e89a45c9817afc6e5d263acd7 /src/lua/modules/thread/Thread.h
parent9593ae6ecdfcfb876fa7953f25e19f0a97e1453a (diff)
*update
Diffstat (limited to 'src/lua/modules/thread/Thread.h')
-rw-r--r--src/lua/modules/thread/Thread.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/lua/modules/thread/Thread.h b/src/lua/modules/thread/Thread.h
new file mode 100644
index 0000000..645d4a1
--- /dev/null
+++ b/src/lua/modules/thread/Thread.h
@@ -0,0 +1,94 @@
+#include "libjin/jin.h"
+#include "lua/common/common.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 \ No newline at end of file