parent
e313e58ea3
commit
8954dbe115
@ -1,7 +1,7 @@
|
|||||||
language: cpp
|
language: cpp
|
||||||
|
|
||||||
dist: trusty
|
dist: trusty
|
||||||
osx_image: xcode8.3
|
osx_image: xcode10
|
||||||
sudo: required
|
sudo: required
|
||||||
|
|
||||||
env:
|
env:
|
||||||
|
|||||||
@ -10,15 +10,15 @@
|
|||||||
|
|
||||||
namespace effil {
|
namespace effil {
|
||||||
|
|
||||||
using Status = ThreaHandle::Status;
|
using Status = ThreadHandle::Status;
|
||||||
using Command = ThreaHandle::Command;
|
using Command = ThreadHandle::Command;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const sol::optional<std::chrono::milliseconds> NO_TIMEOUT;
|
const sol::optional<std::chrono::milliseconds> NO_TIMEOUT;
|
||||||
|
|
||||||
// Thread specific pointer to current thread
|
// Thread specific pointer to current thread
|
||||||
static thread_local ThreaHandle* thisThreadHandle = nullptr;
|
static thread_local ThreadHandle* thisThreadHandle = nullptr;
|
||||||
|
|
||||||
// Doesn't inherit std::exception
|
// Doesn't inherit std::exception
|
||||||
// to prevent from catching this exception third party lua C++ libs
|
// to prevent from catching this exception third party lua C++ libs
|
||||||
@ -86,14 +86,14 @@ void luaHook(lua_State*, lua_Debug*) {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ThreaHandle::ThreaHandle()
|
ThreadHandle::ThreadHandle()
|
||||||
: status_(Status::Running)
|
: status_(Status::Running)
|
||||||
, command_(Command::Run)
|
, command_(Command::Run)
|
||||||
, lua_(std::make_unique<sol::state>(luaErrorHandlerPtr)) {
|
, lua_(std::make_unique<sol::state>(luaErrorHandlerPtr)) {
|
||||||
luaL_openlibs(*lua_);
|
luaL_openlibs(*lua_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreaHandle::putCommand(Command cmd) {
|
void ThreadHandle::putCommand(Command cmd) {
|
||||||
std::unique_lock<std::mutex> lock(stateLock_);
|
std::unique_lock<std::mutex> lock(stateLock_);
|
||||||
if (isFinishStatus(status_))
|
if (isFinishStatus(status_))
|
||||||
return;
|
return;
|
||||||
@ -103,7 +103,7 @@ void ThreaHandle::putCommand(Command cmd) {
|
|||||||
commandNotifier_.notify();
|
commandNotifier_.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreaHandle::changeStatus(Status stat) {
|
void ThreadHandle::changeStatus(Status stat) {
|
||||||
std::unique_lock<std::mutex> lock(stateLock_);
|
std::unique_lock<std::mutex> lock(stateLock_);
|
||||||
status_ = stat;
|
status_ = stat;
|
||||||
commandNotifier_.reset();
|
commandNotifier_.reset();
|
||||||
|
|||||||
@ -13,7 +13,7 @@ std::string threadId();
|
|||||||
void yield();
|
void yield();
|
||||||
void sleep(const sol::stack_object& duration, const sol::stack_object& metric);
|
void sleep(const sol::stack_object& duration, const sol::stack_object& metric);
|
||||||
|
|
||||||
class ThreaHandle : public GCData {
|
class ThreadHandle : public GCData {
|
||||||
public:
|
public:
|
||||||
enum class Status {
|
enum class Status {
|
||||||
Running,
|
Running,
|
||||||
@ -30,7 +30,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ThreaHandle();
|
ThreadHandle();
|
||||||
Command command() const { return command_; }
|
Command command() const { return command_; }
|
||||||
void putCommand(Command cmd);
|
void putCommand(Command cmd);
|
||||||
void changeStatus(Status stat);
|
void changeStatus(Status stat);
|
||||||
@ -87,7 +87,7 @@ private:
|
|||||||
std::unique_ptr<sol::state> lua_;
|
std::unique_ptr<sol::state> lua_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Thread : public GCObject<ThreaHandle> {
|
class Thread : public GCObject<ThreadHandle> {
|
||||||
public:
|
public:
|
||||||
static void exportAPI(sol::state_view& lua);
|
static void exportAPI(sol::state_view& lua);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user