diff options
Diffstat (limited to 'src/lanes.cpp')
-rw-r--r-- | src/lanes.cpp | 134 |
1 files changed, 67 insertions, 67 deletions
diff --git a/src/lanes.cpp b/src/lanes.cpp index 38fe2b9..d027cff 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
@@ -106,7 +106,7 @@ THE SOFTWARE. | |||
106 | #if HAVE_LANE_TRACKING() | 106 | #if HAVE_LANE_TRACKING() |
107 | 107 | ||
108 | // The chain is ended by '(Lane*)(-1)', not nullptr: | 108 | // The chain is ended by '(Lane*)(-1)', not nullptr: |
109 | // 'tracking_first -> ... -> ... -> (-1)' | 109 | // 'trackingFirst -> ... -> ... -> (-1)' |
110 | #define TRACKING_END ((Lane*) (-1)) | 110 | #define TRACKING_END ((Lane*) (-1)) |
111 | 111 | ||
112 | /* | 112 | /* |
@@ -115,11 +115,11 @@ THE SOFTWARE. | |||
115 | */ | 115 | */ |
116 | static void tracking_add(Lane* lane_) | 116 | static void tracking_add(Lane* lane_) |
117 | { | 117 | { |
118 | std::lock_guard<std::mutex> guard{ lane_->U->tracking_cs }; | 118 | std::lock_guard<std::mutex> guard{ lane_->U->trackingMutex }; |
119 | assert(lane_->tracking_next == nullptr); | 119 | assert(lane_->tracking_next == nullptr); |
120 | 120 | ||
121 | lane_->tracking_next = lane_->U->tracking_first; | 121 | lane_->tracking_next = lane_->U->trackingFirst; |
122 | lane_->U->tracking_first = lane_; | 122 | lane_->U->trackingFirst = lane_; |
123 | } | 123 | } |
124 | 124 | ||
125 | // ################################################################################################# | 125 | // ################################################################################################# |
@@ -130,13 +130,13 @@ static void tracking_add(Lane* lane_) | |||
130 | [[nodiscard]] static bool tracking_remove(Lane* lane_) | 130 | [[nodiscard]] static bool tracking_remove(Lane* lane_) |
131 | { | 131 | { |
132 | bool found{ false }; | 132 | bool found{ false }; |
133 | std::lock_guard<std::mutex> guard{ lane_->U->tracking_cs }; | 133 | std::lock_guard<std::mutex> guard{ lane_->U->trackingMutex }; |
134 | // Make sure (within the MUTEX) that we actually are in the chain | 134 | // Make sure (within the MUTEX) that we actually are in the chain |
135 | // still (at process exit they will remove us from chain and then | 135 | // still (at process exit they will remove us from chain and then |
136 | // cancel/kill). | 136 | // cancel/kill). |
137 | // | 137 | // |
138 | if (lane_->tracking_next != nullptr) { | 138 | if (lane_->tracking_next != nullptr) { |
139 | Lane** ref = (Lane**) &lane_->U->tracking_first; | 139 | Lane** ref = (Lane**) &lane_->U->trackingFirst; |
140 | 140 | ||
141 | while (*ref != TRACKING_END) { | 141 | while (*ref != TRACKING_END) { |
142 | if (*ref == lane_) { | 142 | if (*ref == lane_) { |
@@ -161,7 +161,7 @@ Lane::Lane(Universe* U_, lua_State* L_) | |||
161 | , L{ L_ } | 161 | , L{ L_ } |
162 | { | 162 | { |
163 | #if HAVE_LANE_TRACKING() | 163 | #if HAVE_LANE_TRACKING() |
164 | if (U->tracking_first) { | 164 | if (U->trackingFirst) { |
165 | tracking_add(this); | 165 | tracking_add(this); |
166 | } | 166 | } |
167 | #endif // HAVE_LANE_TRACKING() | 167 | #endif // HAVE_LANE_TRACKING() |
@@ -176,10 +176,10 @@ bool Lane::waitForCompletion(lua_Duration duration_) | |||
176 | until = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(duration_); | 176 | until = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(duration_); |
177 | } | 177 | } |
178 | 178 | ||
179 | std::unique_lock lock{ done_mutex }; | 179 | std::unique_lock lock{ doneMutex }; |
180 | // std::stop_token token{ thread.get_stop_token() }; | 180 | // std::stop_token token{ thread.get_stop_token() }; |
181 | // return done_signal.wait_until(lock, token, secs_, [this](){ return status >= Lane::Done; }); | 181 | // return doneCondVar.wait_until(lock, token, secs_, [this](){ return status >= Lane::Done; }); |
182 | return done_signal.wait_until(lock, until, [this]() { return status >= Lane::Done; }); | 182 | return doneCondVar.wait_until(lock, until, [this]() { return status >= Lane::Done; }); |
183 | } | 183 | } |
184 | 184 | ||
185 | // ################################################################################################# | 185 | // ################################################################################################# |
@@ -189,7 +189,7 @@ void Lane::startThread(int priority_) | |||
189 | { | 189 | { |
190 | thread = std::jthread([this]() { lane_main(this); }); | 190 | thread = std::jthread([this]() { lane_main(this); }); |
191 | if (priority_ != kThreadPrioDefault) { | 191 | if (priority_ != kThreadPrioDefault) { |
192 | JTHREAD_SET_PRIORITY(thread, priority_, U->m_sudo); | 192 | JTHREAD_SET_PRIORITY(thread, priority_, U->sudo); |
193 | } | 193 | } |
194 | } | 194 | } |
195 | 195 | ||
@@ -208,9 +208,9 @@ 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_->debugName = lua_pushstring(L_, lane_->debugName);' |
212 | lua_pushstring(L_, lane_->debug_name); | 212 | lua_pushstring(L_, lane_->debugName); |
213 | lane_->debug_name = lua_tostring(L_, -1); | 213 | lane_->debugName = lua_tostring(L_, -1); |
214 | lua_rawset(L_, -3); | 214 | lua_rawset(L_, -3); |
215 | lua_pop(L_, 1); | 215 | lua_pop(L_, 1); |
216 | STACK_CHECK(L_, 0); | 216 | STACK_CHECK(L_, 0); |
@@ -242,7 +242,7 @@ Lane::~Lane() | |||
242 | // Clean up after a (finished) thread | 242 | // Clean up after a (finished) thread |
243 | // | 243 | // |
244 | #if HAVE_LANE_TRACKING() | 244 | #if HAVE_LANE_TRACKING() |
245 | if (U->tracking_first != nullptr) { | 245 | if (U->trackingFirst != nullptr) { |
246 | // Lane was cleaned up, no need to handle at process termination | 246 | // Lane was cleaned up, no need to handle at process termination |
247 | std::ignore = tracking_remove(this); | 247 | std::ignore = tracking_remove(this); |
248 | } | 248 | } |
@@ -414,7 +414,7 @@ static void push_stack_trace(lua_State* L_, int rc_, int stk_base_) | |||
414 | #define SELFDESTRUCT_END ((Lane*) (-1)) | 414 | #define SELFDESTRUCT_END ((Lane*) (-1)) |
415 | // | 415 | // |
416 | // The chain is ended by '(Lane*)(-1)', not nullptr: | 416 | // The chain is ended by '(Lane*)(-1)', not nullptr: |
417 | // 'selfdestruct_first -> ... -> ... -> (-1)' | 417 | // 'selfdestructFirst -> ... -> ... -> (-1)' |
418 | 418 | ||
419 | /* | 419 | /* |
420 | * Add the lane to selfdestruct chain; the ones still running at the end of the | 420 | * Add the lane to selfdestruct chain; the ones still running at the end of the |
@@ -422,11 +422,11 @@ static void push_stack_trace(lua_State* L_, int rc_, int stk_base_) | |||
422 | */ | 422 | */ |
423 | static void selfdestruct_add(Lane* lane_) | 423 | static void selfdestruct_add(Lane* lane_) |
424 | { | 424 | { |
425 | std::lock_guard<std::mutex> guard{ lane_->U->selfdestruct_cs }; | 425 | std::lock_guard<std::mutex> guard{ lane_->U->selfdestructMutex }; |
426 | assert(lane_->selfdestruct_next == nullptr); | 426 | assert(lane_->selfdestruct_next == nullptr); |
427 | 427 | ||
428 | lane_->selfdestruct_next = lane_->U->selfdestruct_first; | 428 | lane_->selfdestruct_next = lane_->U->selfdestructFirst; |
429 | lane_->U->selfdestruct_first = lane_; | 429 | lane_->U->selfdestructFirst = lane_; |
430 | } | 430 | } |
431 | 431 | ||
432 | // ################################################################################################# | 432 | // ################################################################################################# |
@@ -435,20 +435,20 @@ static void selfdestruct_add(Lane* lane_) | |||
435 | [[nodiscard]] static bool selfdestruct_remove(Lane* lane_) | 435 | [[nodiscard]] static bool selfdestruct_remove(Lane* lane_) |
436 | { | 436 | { |
437 | bool found{ false }; | 437 | bool found{ false }; |
438 | std::lock_guard<std::mutex> guard{ lane_->U->selfdestruct_cs }; | 438 | std::lock_guard<std::mutex> guard{ lane_->U->selfdestructMutex }; |
439 | // Make sure (within the MUTEX) that we actually are in the chain | 439 | // Make sure (within the MUTEX) that we actually are in the chain |
440 | // still (at process exit they will remove us from chain and then | 440 | // still (at process exit they will remove us from chain and then |
441 | // cancel/kill). | 441 | // cancel/kill). |
442 | // | 442 | // |
443 | if (lane_->selfdestruct_next != nullptr) { | 443 | if (lane_->selfdestruct_next != nullptr) { |
444 | Lane* volatile* ref = static_cast<Lane* volatile*>(&lane_->U->selfdestruct_first); | 444 | Lane* volatile* ref = static_cast<Lane* volatile*>(&lane_->U->selfdestructFirst); |
445 | 445 | ||
446 | while (*ref != SELFDESTRUCT_END) { | 446 | while (*ref != SELFDESTRUCT_END) { |
447 | if (*ref == lane_) { | 447 | if (*ref == lane_) { |
448 | *ref = lane_->selfdestruct_next; | 448 | *ref = lane_->selfdestruct_next; |
449 | lane_->selfdestruct_next = nullptr; | 449 | lane_->selfdestruct_next = nullptr; |
450 | // the terminal shutdown should wait until the lane is done with its lua_close() | 450 | // the terminal shutdown should wait until the lane is done with its lua_close() |
451 | lane_->U->selfdestructing_count.fetch_add(1, std::memory_order_release); | 451 | lane_->U->selfdestructingCount.fetch_add(1, std::memory_order_release); |
452 | found = true; | 452 | found = true; |
453 | break; | 453 | break; |
454 | } | 454 | } |
@@ -469,11 +469,11 @@ static void selfdestruct_add(Lane* lane_) | |||
469 | [[maybe_unused]] char const* const op_string{ lua_tostring(L_, lua_upvalueindex(2)) }; | 469 | [[maybe_unused]] char const* const op_string{ lua_tostring(L_, lua_upvalueindex(2)) }; |
470 | CancelOp const op{ which_cancel_op(op_string) }; | 470 | CancelOp const op{ which_cancel_op(op_string) }; |
471 | 471 | ||
472 | if (U->selfdestruct_first != SELFDESTRUCT_END) { | 472 | if (U->selfdestructFirst != SELFDESTRUCT_END) { |
473 | // Signal _all_ still running threads to exit (including the timer thread) | 473 | // Signal _all_ still running threads to exit (including the timer thread) |
474 | { | 474 | { |
475 | std::lock_guard<std::mutex> guard{ U->selfdestruct_cs }; | 475 | std::lock_guard<std::mutex> guard{ U->selfdestructMutex }; |
476 | Lane* lane{ U->selfdestruct_first }; | 476 | Lane* lane{ U->selfdestructFirst }; |
477 | lua_Duration timeout{ 1us }; | 477 | lua_Duration timeout{ 1us }; |
478 | while (lane != SELFDESTRUCT_END) { | 478 | while (lane != SELFDESTRUCT_END) { |
479 | // attempt the requested cancel with a small timeout. | 479 | // attempt the requested cancel with a small timeout. |
@@ -490,16 +490,16 @@ static void selfdestruct_add(Lane* lane_) | |||
490 | { | 490 | { |
491 | std::chrono::time_point<std::chrono::steady_clock> t_until{ std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(shutdown_timeout) }; | 491 | std::chrono::time_point<std::chrono::steady_clock> t_until{ std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(shutdown_timeout) }; |
492 | 492 | ||
493 | while (U->selfdestruct_first != SELFDESTRUCT_END) { | 493 | while (U->selfdestructFirst != SELFDESTRUCT_END) { |
494 | // give threads time to act on their cancel | 494 | // give threads time to act on their cancel |
495 | std::this_thread::yield(); | 495 | std::this_thread::yield(); |
496 | // count the number of cancelled thread that didn't have the time to act yet | 496 | // count the number of cancelled thread that didn't have the time to act yet |
497 | int n{ 0 }; | 497 | int n{ 0 }; |
498 | { | 498 | { |
499 | std::lock_guard<std::mutex> guard{ U->selfdestruct_cs }; | 499 | std::lock_guard<std::mutex> guard{ U->selfdestructMutex }; |
500 | Lane* lane{ U->selfdestruct_first }; | 500 | Lane* lane{ U->selfdestructFirst }; |
501 | while (lane != SELFDESTRUCT_END) { | 501 | while (lane != SELFDESTRUCT_END) { |
502 | if (lane->cancel_request != CancelRequest::None) | 502 | if (lane->cancelRequest != CancelRequest::None) |
503 | ++n; | 503 | ++n; |
504 | lane = lane->selfdestruct_next; | 504 | lane = lane->selfdestruct_next; |
505 | } | 505 | } |
@@ -515,33 +515,33 @@ static void selfdestruct_add(Lane* lane_) | |||
515 | 515 | ||
516 | // If some lanes are currently cleaning after themselves, wait until they are done. | 516 | // If some lanes are currently cleaning after themselves, wait until they are done. |
517 | // They are no longer listed in the selfdestruct chain, but they still have to lua_close(). | 517 | // They are no longer listed in the selfdestruct chain, but they still have to lua_close(). |
518 | while (U->selfdestructing_count.load(std::memory_order_acquire) > 0) { | 518 | while (U->selfdestructingCount.load(std::memory_order_acquire) > 0) { |
519 | std::this_thread::yield(); | 519 | std::this_thread::yield(); |
520 | } | 520 | } |
521 | } | 521 | } |
522 | 522 | ||
523 | // If after all this, we still have some free-running lanes, it's an external user error, they should have stopped appropriately | 523 | // If after all this, we still have some free-running lanes, it's an external user error, they should have stopped appropriately |
524 | { | 524 | { |
525 | std::lock_guard<std::mutex> guard{ U->selfdestruct_cs }; | 525 | std::lock_guard<std::mutex> guard{ U->selfdestructMutex }; |
526 | Lane* lane{ U->selfdestruct_first }; | 526 | Lane* lane{ U->selfdestructFirst }; |
527 | if (lane != SELFDESTRUCT_END) { | 527 | if (lane != SELFDESTRUCT_END) { |
528 | // this causes a leak because we don't call U's destructor (which could be bad if the still running lanes are accessing it) | 528 | // this causes a leak because we don't call U's destructor (which could be bad if the still running lanes are accessing it) |
529 | raise_luaL_error(L_, "Zombie thread %s refuses to die!", lane->debug_name); | 529 | raise_luaL_error(L_, "Zombie thread %s refuses to die!", lane->debugName); |
530 | } | 530 | } |
531 | } | 531 | } |
532 | 532 | ||
533 | // no need to mutex-protect this as all threads in the universe are gone at that point | 533 | // no need to mutex-protect this as all threads in the universe are gone at that point |
534 | if (U->timer_deep != nullptr) { // test ins case some early internal error prevented Lanes from creating the deep timer | 534 | if (U->timerLinda != nullptr) { // test in case some early internal error prevented Lanes from creating the deep timer |
535 | [[maybe_unused]] int const prev_ref_count{ U->timer_deep->refcount.fetch_sub(1, std::memory_order_relaxed) }; | 535 | [[maybe_unused]] int const prev_ref_count{ U->timerLinda->refcount.fetch_sub(1, std::memory_order_relaxed) }; |
536 | LUA_ASSERT(L_, prev_ref_count == 1); // this should be the last reference | 536 | LUA_ASSERT(L_, prev_ref_count == 1); // this should be the last reference |
537 | DeepFactory::DeleteDeepObject(L_, U->timer_deep); | 537 | DeepFactory::DeleteDeepObject(L_, U->timerLinda); |
538 | U->timer_deep = nullptr; | 538 | U->timerLinda = nullptr; |
539 | } | 539 | } |
540 | 540 | ||
541 | close_keepers(U); | 541 | close_keepers(U); |
542 | 542 | ||
543 | // remove the protected allocator, if any | 543 | // remove the protected allocator, if any |
544 | U->protected_allocator.removeFrom(L_); | 544 | U->protectedAllocator.removeFrom(L_); |
545 | 545 | ||
546 | U->Universe::~Universe(); | 546 | U->Universe::~Universe(); |
547 | 547 | ||
@@ -701,9 +701,9 @@ LUAG_FUNC(set_debug_threadname) | |||
701 | // store a hidden reference in the registry to make sure the string is kept around even if a lane decides to manually change the "decoda_name" global... | 701 | // store a hidden reference in the registry to make sure the string is kept around even if a lane decides to manually change the "decoda_name" global... |
702 | hidden_regkey.setValue(L_, [](lua_State* L_) { lua_pushvalue(L_, -2); }); | 702 | hidden_regkey.setValue(L_, [](lua_State* L_) { lua_pushvalue(L_, -2); }); |
703 | STACK_CHECK(L_, 1); | 703 | STACK_CHECK(L_, 1); |
704 | lane->debug_name = lua_tostring(L_, -1); | 704 | lane->debugName = lua_tostring(L_, -1); |
705 | // keep a direct pointer on the string | 705 | // keep a direct pointer on the string |
706 | THREAD_SETNAME(lane->debug_name); | 706 | THREAD_SETNAME(lane->debugName); |
707 | // to see VM name in Decoda debugger Virtual Machine window | 707 | // to see VM name in Decoda debugger Virtual Machine window |
708 | lua_setglobal(L_, "decoda_name"); // | 708 | lua_setglobal(L_, "decoda_name"); // |
709 | STACK_CHECK(L_, 0); | 709 | STACK_CHECK(L_, 0); |
@@ -716,7 +716,7 @@ LUAG_FUNC(get_debug_threadname) | |||
716 | { | 716 | { |
717 | Lane* const lane{ ToLane(L_, 1) }; | 717 | Lane* const lane{ ToLane(L_, 1) }; |
718 | luaL_argcheck(L_, lua_gettop(L_) == 1, 2, "too many arguments"); | 718 | luaL_argcheck(L_, lua_gettop(L_) == 1, 2, "too many arguments"); |
719 | lua_pushstring(L_, lane->debug_name); | 719 | lua_pushstring(L_, lane->debugName); |
720 | return 1; | 720 | return 1; |
721 | } | 721 | } |
722 | 722 | ||
@@ -731,7 +731,7 @@ LUAG_FUNC(set_thread_priority) | |||
731 | if (prio < kThreadPrioMin || prio > kThreadPrioMax) { | 731 | if (prio < kThreadPrioMin || prio > kThreadPrioMax) { |
732 | raise_luaL_error(L_, "priority out of range: %d..+%d (%d)", kThreadPrioMin, kThreadPrioMax, prio); | 732 | raise_luaL_error(L_, "priority out of range: %d..+%d (%d)", kThreadPrioMin, kThreadPrioMax, prio); |
733 | } | 733 | } |
734 | THREAD_SET_PRIORITY(static_cast<int>(prio), universe_get(L_)->m_sudo); | 734 | THREAD_SET_PRIORITY(static_cast<int>(prio), universe_get(L_)->sudo); |
735 | return 0; | 735 | return 0; |
736 | } | 736 | } |
737 | 737 | ||
@@ -843,10 +843,10 @@ static void lane_main(Lane* lane_) | |||
843 | // We're a free-running thread and no-one's there to clean us up. | 843 | // We're a free-running thread and no-one's there to clean us up. |
844 | lua_close(lane_->L); | 844 | lua_close(lane_->L); |
845 | lane_->L = nullptr; // just in case | 845 | lane_->L = nullptr; // just in case |
846 | lane_->U->selfdestruct_cs.lock(); | 846 | lane_->U->selfdestructMutex.lock(); |
847 | // done with lua_close(), terminal shutdown sequence may proceed | 847 | // done with lua_close(), terminal shutdown sequence may proceed |
848 | lane_->U->selfdestructing_count.fetch_sub(1, std::memory_order_release); | 848 | lane_->U->selfdestructingCount.fetch_sub(1, std::memory_order_release); |
849 | lane_->U->selfdestruct_cs.unlock(); | 849 | lane_->U->selfdestructMutex.unlock(); |
850 | 850 | ||
851 | // 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 | 851 | // 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 |
852 | lane_->thread.detach(); | 852 | lane_->thread.detach(); |
@@ -860,10 +860,10 @@ static void lane_main(Lane* lane_) | |||
860 | Lane::Status const st = (rc == LUA_OK) ? Lane::Done : kCancelError.equals(L, 1) ? Lane::Cancelled : Lane::Error; | 860 | Lane::Status const st = (rc == LUA_OK) ? Lane::Done : kCancelError.equals(L, 1) ? Lane::Cancelled : Lane::Error; |
861 | 861 | ||
862 | { | 862 | { |
863 | // 'done_mutex' protects the -> Done|Error|Cancelled state change | 863 | // 'doneMutex' protects the -> Done|Error|Cancelled state change |
864 | std::lock_guard lock{ lane_->done_mutex }; | 864 | std::lock_guard lock{ lane_->doneMutex }; |
865 | lane_->status = st; | 865 | lane_->status = st; |
866 | lane_->done_signal.notify_one(); // wake up master (while 'lane_->done_mutex' is on) | 866 | lane_->doneCondVar.notify_one(); // wake up master (while 'lane_->doneMutex' is on) |
867 | } | 867 | } |
868 | } | 868 | } |
869 | } | 869 | } |
@@ -994,9 +994,9 @@ LUAG_FUNC(lane_new) | |||
994 | lua_settop(m_lane->L, 0); | 994 | lua_settop(m_lane->L, 0); |
995 | kCancelError.pushKey(m_lane->L); | 995 | kCancelError.pushKey(m_lane->L); |
996 | { | 996 | { |
997 | std::lock_guard lock{ m_lane->done_mutex }; | 997 | std::lock_guard lock{ m_lane->doneMutex }; |
998 | m_lane->status = Lane::Cancelled; | 998 | m_lane->status = Lane::Cancelled; |
999 | m_lane->done_signal.notify_one(); // wake up master (while 'lane->done_mutex' is on) | 999 | m_lane->doneCondVar.notify_one(); // wake up master (while 'lane->doneMutex' is on) |
1000 | } | 1000 | } |
1001 | // unblock the thread so that it can terminate gracefully | 1001 | // unblock the thread so that it can terminate gracefully |
1002 | m_lane->ready.count_down(); | 1002 | m_lane->ready.count_down(); |
@@ -1207,7 +1207,7 @@ LUAG_FUNC(lane_new) | |||
1207 | lua_rawget(L_, -2); // L_: ud uservalue gc_cb|nil | 1207 | lua_rawget(L_, -2); // L_: ud uservalue gc_cb|nil |
1208 | if (!lua_isnil(L_, -1)) { | 1208 | if (!lua_isnil(L_, -1)) { |
1209 | lua_remove(L_, -2); // L_: ud gc_cb|nil | 1209 | lua_remove(L_, -2); // L_: ud gc_cb|nil |
1210 | lua_pushstring(L_, lane->debug_name); // L_: ud gc_cb name | 1210 | lua_pushstring(L_, lane->debugName); // L_: ud gc_cb name |
1211 | have_gc_cb = true; | 1211 | have_gc_cb = true; |
1212 | } else { | 1212 | } else { |
1213 | lua_pop(L_, 2); // L_: ud | 1213 | lua_pop(L_, 2); // L_: ud |
@@ -1228,7 +1228,7 @@ LUAG_FUNC(lane_new) | |||
1228 | lua_close(lane->L); | 1228 | lua_close(lane->L); |
1229 | lane->L = nullptr; | 1229 | lane->L = nullptr; |
1230 | // just in case, but s will be freed soon so... | 1230 | // just in case, but s will be freed soon so... |
1231 | lane->debug_name = "<gc>"; | 1231 | lane->debugName = "<gc>"; |
1232 | } | 1232 | } |
1233 | 1233 | ||
1234 | // Clean up after a (finished) thread | 1234 | // Clean up after a (finished) thread |
@@ -1307,7 +1307,7 @@ LUAG_FUNC(thread_join) | |||
1307 | 1307 | ||
1308 | int ret{ 0 }; | 1308 | int ret{ 0 }; |
1309 | Universe* const U{ lane->U }; | 1309 | Universe* const U{ lane->U }; |
1310 | // debug_name is a pointer to string possibly interned in the lane's state, that no longer exists when the state is closed | 1310 | // debugName is a pointer to string possibly interned in the lane's state, that no longer exists when the state is closed |
1311 | // so store it in the userdata uservalue at a key that can't possibly collide | 1311 | // so store it in the userdata uservalue at a key that can't possibly collide |
1312 | securize_debug_threadname(L_, lane); | 1312 | securize_debug_threadname(L_, lane); |
1313 | switch (lane->status) { | 1313 | switch (lane->status) { |
@@ -1508,15 +1508,15 @@ LUAG_FUNC(threads) | |||
1508 | 1508 | ||
1509 | // List _all_ still running threads | 1509 | // List _all_ still running threads |
1510 | // | 1510 | // |
1511 | std::lock_guard<std::mutex> guard{ U->tracking_cs }; | 1511 | std::lock_guard<std::mutex> guard{ U->trackingMutex }; |
1512 | if (U->tracking_first && U->tracking_first != TRACKING_END) { | 1512 | if (U->trackingFirst && U->trackingFirst != TRACKING_END) { |
1513 | Lane* lane{ U->tracking_first }; | 1513 | Lane* lane{ U->trackingFirst }; |
1514 | int index = 0; | 1514 | int index{ 0 }; |
1515 | lua_newtable(L_); // L_: {} | 1515 | lua_newtable(L_); // L_: {} |
1516 | while (lane != TRACKING_END) { | 1516 | while (lane != TRACKING_END) { |
1517 | // insert a { name, status } tuple, so that several lanes with the same name can't clobber each other | 1517 | // insert a { name, status } tuple, so that several lanes with the same name can't clobber each other |
1518 | lua_newtable(L_); // L_: {} {} | 1518 | lua_newtable(L_); // L_: {} {} |
1519 | lua_pushstring(L_, lane->debug_name); // L_: {} {} "name" | 1519 | lua_pushstring(L_, lane->debugName); // L_: {} {} "name" |
1520 | lua_setfield(L_, -2, "name"); // L_: {} {} | 1520 | lua_setfield(L_, -2, "name"); // L_: {} {} |
1521 | lane->pushThreadStatus(L_); // L_: {} {} "status" | 1521 | lane->pushThreadStatus(L_); // L_: {} {} "status" |
1522 | lua_setfield(L_, -2, "status"); // L_: {} {} | 1522 | lua_setfield(L_, -2, "status"); // L_: {} {} |
@@ -1663,26 +1663,26 @@ LUAG_FUNC(configure) | |||
1663 | lua_pop(L_, 1); // L_: settings | 1663 | lua_pop(L_, 1); // L_: settings |
1664 | #if HAVE_LANE_TRACKING() | 1664 | #if HAVE_LANE_TRACKING() |
1665 | lua_getfield(L_, 1, "track_lanes"); // L_: settings track_lanes | 1665 | lua_getfield(L_, 1, "track_lanes"); // L_: settings track_lanes |
1666 | U->tracking_first = lua_toboolean(L_, -1) ? TRACKING_END : nullptr; | 1666 | U->trackingFirst = lua_toboolean(L_, -1) ? TRACKING_END : nullptr; |
1667 | lua_pop(L_, 1); // L_: settings | 1667 | lua_pop(L_, 1); // L_: settings |
1668 | #endif // HAVE_LANE_TRACKING() | 1668 | #endif // HAVE_LANE_TRACKING() |
1669 | // Linked chains handling | 1669 | // Linked chains handling |
1670 | U->selfdestruct_first = SELFDESTRUCT_END; | 1670 | U->selfdestructFirst = SELFDESTRUCT_END; |
1671 | initialize_allocator_function(U, L_); | 1671 | initialize_allocator_function(U, L_); |
1672 | initialize_on_state_create(U, L_); | 1672 | initializeOnStateCreate(U, L_); |
1673 | init_keepers(U, L_); | 1673 | init_keepers(U, L_); |
1674 | STACK_CHECK(L_, 1); | 1674 | STACK_CHECK(L_, 1); |
1675 | 1675 | ||
1676 | // Initialize 'timer_deep'; a common Linda object shared by all states | 1676 | // Initialize 'timerLinda'; a common Linda object shared by all states |
1677 | lua_pushcfunction(L_, LG_linda); // L_: settings lanes.linda | 1677 | lua_pushcfunction(L_, LG_linda); // L_: settings lanes.linda |
1678 | lua_pushliteral(L_, "lanes-timer"); // L_: settings lanes.linda "lanes-timer" | 1678 | lua_pushliteral(L_, "lanes-timer"); // L_: settings lanes.linda "lanes-timer" |
1679 | lua_call(L_, 1, 1); // L_: settings linda | 1679 | lua_call(L_, 1, 1); // L_: settings linda |
1680 | STACK_CHECK(L_, 2); | 1680 | STACK_CHECK(L_, 2); |
1681 | 1681 | ||
1682 | // Proxy userdata contents is only a 'DeepPrelude*' pointer | 1682 | // Proxy userdata contents is only a 'DeepPrelude*' pointer |
1683 | U->timer_deep = *lua_tofulluserdata<DeepPrelude*>(L_, -1); | 1683 | U->timerLinda = *lua_tofulluserdata<DeepPrelude*>(L_, -1); |
1684 | // increment refcount so that this linda remains alive as long as the universe exists. | 1684 | // increment refcount so that this linda remains alive as long as the universe exists. |
1685 | U->timer_deep->refcount.fetch_add(1, std::memory_order_relaxed); | 1685 | U->timerLinda->refcount.fetch_add(1, std::memory_order_relaxed); |
1686 | lua_pop(L_, 1); // L_: settings | 1686 | lua_pop(L_, 1); // L_: settings |
1687 | } | 1687 | } |
1688 | STACK_CHECK(L_, 1); | 1688 | STACK_CHECK(L_, 1); |
@@ -1699,7 +1699,7 @@ LUAG_FUNC(configure) | |||
1699 | luaG_registerlibfuncs(L_, lanes_functions); | 1699 | luaG_registerlibfuncs(L_, lanes_functions); |
1700 | #if HAVE_LANE_TRACKING() | 1700 | #if HAVE_LANE_TRACKING() |
1701 | // register core.threads() only if settings say it should be available | 1701 | // register core.threads() only if settings say it should be available |
1702 | if (U->tracking_first != nullptr) { | 1702 | if (U->trackingFirst != nullptr) { |
1703 | lua_pushcfunction(L_, LG_threads); // L_: settings M LG_threads() | 1703 | lua_pushcfunction(L_, LG_threads); // L_: settings M LG_threads() |
1704 | lua_setfield(L_, -2, "threads"); // L_: settings M | 1704 | lua_setfield(L_, -2, "threads"); // L_: settings M |
1705 | } | 1705 | } |
@@ -1708,8 +1708,8 @@ LUAG_FUNC(configure) | |||
1708 | 1708 | ||
1709 | { | 1709 | { |
1710 | char const* errmsg{ | 1710 | char const* errmsg{ |
1711 | DeepFactory::PushDeepProxy(DestState{ L_ }, U->timer_deep, 0, LookupMode::LaneBody) | 1711 | DeepFactory::PushDeepProxy(DestState{ L_ }, U->timerLinda, 0, LookupMode::LaneBody) |
1712 | }; // L_: settings M timer_deep | 1712 | }; // L_: settings M timerLinda |
1713 | if (errmsg != nullptr) { | 1713 | if (errmsg != nullptr) { |
1714 | raise_luaL_error(L_, errmsg); | 1714 | raise_luaL_error(L_, errmsg); |
1715 | } | 1715 | } |