diff options
Diffstat (limited to 'src/lanes.cpp')
-rw-r--r-- | src/lanes.cpp | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/lanes.cpp b/src/lanes.cpp index d87d93e..16c8e47 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
@@ -208,7 +208,7 @@ static void securize_debug_threadname(lua_State* L_, Lane* lane_) | |||
208 | STACK_GROW(L_, 3); | 208 | STACK_GROW(L_, 3); |
209 | lua_getiuservalue(L_, 1, 1); | 209 | lua_getiuservalue(L_, 1, 1); |
210 | lua_newtable(L_); | 210 | lua_newtable(L_); |
211 | // Lua 5.1 can't do 'lane_->debug_name = lua_pushstring(L, lane_->debug_name);' | 211 | // Lua 5.1 can't do 'lane_->debug_name = lua_pushstring(L_, lane_->debug_name);' |
212 | lua_pushstring(L_, lane_->debug_name); | 212 | lua_pushstring(L_, lane_->debug_name); |
213 | lane_->debug_name = lua_tostring(L_, -1); | 213 | lane_->debug_name = lua_tostring(L_, -1); |
214 | lua_rawset(L_, -3); | 214 | lua_rawset(L_, -3); |
@@ -371,7 +371,7 @@ static void push_stack_trace(lua_State* L_, int rc_, int stk_base_) | |||
371 | if (lua_rc_ != LUA_OK) // we have an error message and an optional stack trace at the bottom of the stack | 371 | if (lua_rc_ != LUA_OK) // we have an error message and an optional stack trace at the bottom of the stack |
372 | { | 372 | { |
373 | LUA_ASSERT(L_, finalizers_index == 2 || finalizers_index == 3); | 373 | LUA_ASSERT(L_, finalizers_index == 2 || finalizers_index == 3); |
374 | //char const* err_msg = lua_tostring(L, 1); | 374 | //char const* err_msg = lua_tostring(L_, 1); |
375 | lua_pushvalue(L_, 1); // ... finalizers lane_error finalizer err_msg | 375 | lua_pushvalue(L_, 1); // ... finalizers lane_error finalizer err_msg |
376 | // note we don't always have a stack trace for example when kCancelError, or when we got an error that doesn't call our handler, such as LUA_ERRMEM | 376 | // note we don't always have a stack trace for example when kCancelError, or when we got an error that doesn't call our handler, such as LUA_ERRMEM |
377 | if (finalizers_index == 3) | 377 | if (finalizers_index == 3) |
@@ -819,18 +819,18 @@ static char const* get_errcode_name( int _code) | |||
819 | } | 819 | } |
820 | #endif // USE_DEBUG_SPEW() | 820 | #endif // USE_DEBUG_SPEW() |
821 | 821 | ||
822 | static void lane_main(Lane* lane) | 822 | static void lane_main(Lane* lane_) |
823 | { | 823 | { |
824 | lua_State* const L{ lane->L }; | 824 | lua_State* const L{ lane_->L }; |
825 | // wait until the launching thread has finished preparing L | 825 | // wait until the launching thread has finished preparing L |
826 | lane->m_ready.wait(); | 826 | lane_->m_ready.wait(); |
827 | int rc{ LUA_ERRRUN }; | 827 | int rc{ LUA_ERRRUN }; |
828 | if (lane->m_status == Lane::Pending) // nothing wrong happened during preparation, we can work | 828 | if (lane_->m_status == Lane::Pending) // nothing wrong happened during preparation, we can work |
829 | { | 829 | { |
830 | // At this point, the lane function and arguments are on the stack | 830 | // At this point, the lane function and arguments are on the stack |
831 | int const nargs{ lua_gettop(L) - 1 }; | 831 | int const nargs{ lua_gettop(L) - 1 }; |
832 | DEBUGSPEW_CODE(Universe* U = universe_get(L)); | 832 | DEBUGSPEW_CODE(Universe* U = universe_get(L)); |
833 | lane->m_status = Lane::Running; // Pending -> Running | 833 | lane_->m_status = Lane::Running; // Pending -> Running |
834 | 834 | ||
835 | // Tie "set_finalizer()" to the state | 835 | // Tie "set_finalizer()" to the state |
836 | lua_pushcfunction(L, LG_set_finalizer); | 836 | lua_pushcfunction(L, LG_set_finalizer); |
@@ -839,7 +839,7 @@ static void lane_main(Lane* lane) | |||
839 | 839 | ||
840 | // Tie "set_debug_threadname()" to the state | 840 | // Tie "set_debug_threadname()" to the state |
841 | // But don't register it in the lookup database because of the Lane pointer upvalue | 841 | // But don't register it in the lookup database because of the Lane pointer upvalue |
842 | lua_pushlightuserdata(L, lane); | 842 | lua_pushlightuserdata(L, lane_); |
843 | lua_pushcclosure(L, LG_set_debug_threadname, 1); | 843 | lua_pushcclosure(L, LG_set_debug_threadname, 1); |
844 | lua_setglobal(L, "set_debug_threadname"); | 844 | lua_setglobal(L, "set_debug_threadname"); |
845 | 845 | ||
@@ -879,24 +879,24 @@ static void lane_main(Lane* lane) | |||
879 | // the finalizer generated an error, and left its own error message [and stack trace] on the stack | 879 | // the finalizer generated an error, and left its own error message [and stack trace] on the stack |
880 | rc = rc2; // we're overruling the earlier script error or normal return | 880 | rc = rc2; // we're overruling the earlier script error or normal return |
881 | } | 881 | } |
882 | lane->m_waiting_on = nullptr; // just in case | 882 | lane_->m_waiting_on = nullptr; // just in case |
883 | if (selfdestruct_remove(lane)) // check and remove (under lock!) | 883 | if (selfdestruct_remove(lane_)) // check and remove (under lock!) |
884 | { | 884 | { |
885 | // We're a free-running thread and no-one's there to clean us up. | 885 | // We're a free-running thread and no-one's there to clean us up. |
886 | lua_close(lane->L); | 886 | lua_close(lane_->L); |
887 | lane->L = nullptr; // just in case | 887 | lane_->L = nullptr; // just in case |
888 | lane->U->selfdestruct_cs.lock(); | 888 | lane_->U->selfdestruct_cs.lock(); |
889 | // done with lua_close(), terminal shutdown sequence may proceed | 889 | // done with lua_close(), terminal shutdown sequence may proceed |
890 | lane->U->selfdestructing_count.fetch_sub(1, std::memory_order_release); | 890 | lane_->U->selfdestructing_count.fetch_sub(1, std::memory_order_release); |
891 | lane->U->selfdestruct_cs.unlock(); | 891 | lane_->U->selfdestruct_cs.unlock(); |
892 | 892 | ||
893 | // we destroy our jthread member from inside the thread body, so we have to detach so that we don't try to join, as this doesn't seem a good idea | 893 | // we destroy our jthread member from inside the thread body, so we have to detach so that we don't try to join, as this doesn't seem a good idea |
894 | lane->m_thread.detach(); | 894 | lane_->m_thread.detach(); |
895 | delete lane; | 895 | delete lane_; |
896 | lane = nullptr; | 896 | lane_ = nullptr; |
897 | } | 897 | } |
898 | } | 898 | } |
899 | if (lane) | 899 | if (lane_) |
900 | { | 900 | { |
901 | // leave results (1..top) or error message + stack trace (1..2) on the stack - master will copy them | 901 | // leave results (1..top) or error message + stack trace (1..2) on the stack - master will copy them |
902 | 902 | ||
@@ -904,9 +904,9 @@ static void lane_main(Lane* lane) | |||
904 | 904 | ||
905 | { | 905 | { |
906 | // 'm_done_mutex' protects the -> Done|Error|Cancelled state change | 906 | // 'm_done_mutex' protects the -> Done|Error|Cancelled state change |
907 | std::lock_guard lock{ lane->m_done_mutex }; | 907 | std::lock_guard lock{ lane_->m_done_mutex }; |
908 | lane->m_status = st; | 908 | lane_->m_status = st; |
909 | lane->m_done_signal.notify_one();// wake up master (while 'lane->m_done_mutex' is on) | 909 | lane_->m_done_signal.notify_one();// wake up master (while 'lane_->m_done_mutex' is on) |
910 | } | 910 | } |
911 | } | 911 | } |
912 | } | 912 | } |
@@ -946,7 +946,7 @@ LUAG_FUNC(register) | |||
946 | // ignore extra parameters, just in case | 946 | // ignore extra parameters, just in case |
947 | lua_settop(L_, 2); | 947 | lua_settop(L_, 2); |
948 | luaL_argcheck(L_, (mod_type == LuaType::TABLE) || (mod_type == LuaType::FUNCTION), 2, "unexpected module type"); | 948 | luaL_argcheck(L_, (mod_type == LuaType::TABLE) || (mod_type == LuaType::FUNCTION), 2, "unexpected module type"); |
949 | DEBUGSPEW_CODE(Universe* U = universe_get(L)); | 949 | DEBUGSPEW_CODE(Universe* U = universe_get(L_)); |
950 | STACK_CHECK_START_REL(L_, 0); // "name" mod_table | 950 | STACK_CHECK_START_REL(L_, 0); // "name" mod_table |
951 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lanes.register %s BEGIN\n" INDENT_END, name)); | 951 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lanes.register %s BEGIN\n" INDENT_END, name)); |
952 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); | 952 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); |
@@ -1747,7 +1747,7 @@ LUAG_FUNC(configure) | |||
1747 | STACK_GROW(L_, 4); | 1747 | STACK_GROW(L_, 4); |
1748 | STACK_CHECK_START_ABS(L_, 1); // settings | 1748 | STACK_CHECK_START_ABS(L_, 1); // settings |
1749 | 1749 | ||
1750 | DEBUGSPEW_CODE(fprintf( stderr, INDENT_BEGIN "%p: lanes.configure() BEGIN\n" INDENT_END, L)); | 1750 | DEBUGSPEW_CODE(fprintf( stderr, INDENT_BEGIN "%p: lanes.configure() BEGIN\n" INDENT_END, L_)); |
1751 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); | 1751 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); |
1752 | 1752 | ||
1753 | if (U == nullptr) | 1753 | if (U == nullptr) |
@@ -1898,7 +1898,7 @@ LUAG_FUNC(configure) | |||
1898 | // set _R[kConfigRegKey] = settings | 1898 | // set _R[kConfigRegKey] = settings |
1899 | kConfigRegKey.setValue(L_, [](lua_State* L_) { lua_pushvalue(L_, -2); }); | 1899 | kConfigRegKey.setValue(L_, [](lua_State* L_) { lua_pushvalue(L_, -2); }); |
1900 | STACK_CHECK(L_, 1); | 1900 | STACK_CHECK(L_, 1); |
1901 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%p: lanes.configure() END\n" INDENT_END, L)); | 1901 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%p: lanes.configure() END\n" INDENT_END, L_)); |
1902 | // Return the settings table | 1902 | // Return the settings table |
1903 | return 1; | 1903 | return 1; |
1904 | } | 1904 | } |