Skip to content

Commit

Permalink
using itc::sys::sched_yield() instead of asm(pause)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Kraynyukhov committed Jun 16, 2019
1 parent 44f677e commit 726a075
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion include/LuaStandaloneService.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace LAppS
itc::getLog()->info(__FILE__,__LINE__,"Shutdown is requested for the instance %u of the service %s",this->getInstanceId(), mContext.getName().c_str());
mContext.stop();

while(mContext.isRunning()) asm("pause");
while(mContext.isRunning()) itc::sys::sched_yield(10);

itc::getLog()->info(__FILE__,__LINE__,"Instance %u of the service %s is down",this->getInstanceId(), mContext.getName().c_str());
}
Expand Down
15 changes: 6 additions & 9 deletions include/LuaStandaloneServiceContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ extern "C" {

LUA_API int must_stop(lua_State* L)
{
if(mustStop&&mustStop.load())
if(mustStop.load()&&(mustStop.load()->load()))
{
lua_pushboolean(L,mustStop.load()->load());
lua_pushboolean(L,true);
return 1;
}
lua_pushboolean(L,false);
Expand Down Expand Up @@ -149,7 +149,7 @@ namespace LAppS

void run()
{
mustStop=&mMustStop;
mustStop.store(&mMustStop);
lua_getglobal(mLState, this->getName().c_str());
lua_getfield(mLState, -1, "run");
int ret = lua_pcall(mLState, 0, 0, 0);
Expand All @@ -172,23 +172,20 @@ namespace LAppS

const bool isRunning() const
{
return !(mMustStop.load()&&mCanStop.load());
return !mCanStop.load();
}

void shutdown()
{
if(isRunning())
{
this->stop();
while(!mCanStop.load())
{
asm("pause");
}
while(isRunning())
itc::sys::sched_yield(1000);
}
}
~LuaStandaloneServiceContext() noexcept
{
if(!isRunning())
this->shutdown();
}
};
Expand Down

0 comments on commit 726a075

Please # to comment.