diff options
Diffstat (limited to 'src/lua/thread/Thread.h')
-rw-r--r-- | src/lua/thread/Thread.h | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/lua/thread/Thread.h b/src/lua/thread/Thread.h new file mode 100644 index 0000000..63f7524 --- /dev/null +++ b/src/lua/thread/Thread.h @@ -0,0 +1,94 @@ +#include "libjin/jin.h" +#include "../luaopen_types.h" + +namespace jin +{ +namespace lua +{ +namespace thread +{ + + class Thread : public Object + { + public: + typedef jin::thread::Thread::Variant Variant; + + Thread(std::string _name, std::string _code, jin::thread::Thread::ThreadRunner runner) + : name(_name) + , code(_code) + { + thread = new jin::thread::Thread(_name, runner); + } + + bool start() + { + return thread->start(); + } + + 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(); + } + + static void threadRunner(jin::thread::Thread* t); + + private: + ~Thread() + { + delete thread; + } + + jin::thread::Thread* thread; + + const std::string name; + const std::string code; + }; + +} // thread +} // lua +} // jin
\ No newline at end of file |