Skip to content

Commit

Permalink
bugfix: skynet.coroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu committed May 3, 2017
1 parent 4b2efd4 commit ea129cd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lualib-src/lua-profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ lstop(lua_State *L) {
total_time += ti;
lua_pushnumber(L, total_time);
#ifdef DEBUG_LOG
fprintf(stderr, "PROFILE [%p] stop (%lf / %lf)\n", L, ti, total_time);
fprintf(stderr, "PROFILE [%p] stop (%lf / %lf)\n", lua_tothread(L,1), ti, total_time);
#endif

return 1;
Expand Down Expand Up @@ -157,14 +157,15 @@ timing_yield(lua_State *L) {
#ifdef DEBUG_LOG
lua_State *from = lua_tothread(L, -1);
#endif
lua_pushvalue(L, -1);
lua_rawget(L, lua_upvalueindex(2)); // check total time
if (lua_isnil(L, -1)) {
lua_pop(L,1);
lua_pop(L,2);
} else {
double ti = lua_tonumber(L, -1);
lua_pop(L,1);

lua_pushthread(L);
lua_pushvalue(L, -1); // push coroutine
lua_rawget(L, lua_upvalueindex(1));
double starttime = lua_tonumber(L, -1);
lua_pop(L,1);
Expand All @@ -175,9 +176,10 @@ timing_yield(lua_State *L) {
fprintf(stderr, "PROFILE [%p] yield (%lf/%lf)\n", from, diff, ti);
#endif

lua_pushthread(L);
lua_pushvalue(L, -1); // push coroutine
lua_pushnumber(L, ti);
lua_rawset(L, lua_upvalueindex(2));
lua_pop(L, 1); // pop coroutine
}

lua_CFunction co_yield = lua_tocfunction(L, lua_upvalueindex(3));
Expand Down

0 comments on commit ea129cd

Please sign in to comment.