aboutsummaryrefslogtreecommitdiff
path: root/src/lanes.cpp
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-06-03 15:53:34 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-06-03 15:53:34 +0200
commit44c617f7b756052c7cd059c96f89b85f0f5ec96c (patch)
treea9ac504d7ffa09500c9ea17bab963f1016f6fe79 /src/lanes.cpp
parent420e50697cd036a0d8ea1601961bd6974703ade1 (diff)
downloadlanes-44c617f7b756052c7cd059c96f89b85f0f5ec96c.tar.gz
lanes-44c617f7b756052c7cd059c96f89b85f0f5ec96c.tar.bz2
lanes-44c617f7b756052c7cd059c96f89b85f0f5ec96c.zip
Moved lanes.sleep implementation to the C-side
Diffstat (limited to 'src/lanes.cpp')
-rw-r--r--src/lanes.cpp38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/lanes.cpp b/src/lanes.cpp
index 41450f3..25f44d9 100644
--- a/src/lanes.cpp
+++ b/src/lanes.cpp
@@ -161,6 +161,33 @@ LUAG_FUNC(set_thread_affinity)
161 161
162// ################################################################################################# 162// #################################################################################################
163 163
164LUAG_FUNC(sleep)
165{
166 extern LUAG_FUNC(linda_receive);
167
168 Universe* const _U{ Universe::Get(L_) };
169 lua_settop(L_, 1);
170 lua_pushcfunction(L_, LG_linda_receive); // L_: duration|nil receive()
171 STACK_CHECK_START_REL(L_, 0); // we pushed the function we intend to call, now prepare the arguments
172 _U->timerLinda->push(L_); // L_: duration|nil receive() timerLinda
173 if (lua_tostringview(L_, 1) == "indefinitely") {
174 lua_pushnil(L_); // L_: duration? receive() timerLinda nil
175 } else if (lua_isnoneornil(L_, 1)) {
176 lua_pushnumber(L_, 0); // L_: duration? receive() timerLinda 0
177 } else if (!lua_isnumber(L_, 1)) {
178 raise_luaL_argerror(L_, 1, "invalid duration");
179 }
180 else {
181 lua_pushnumber(L_, lua_tonumber(L_, 1)); // L_: duration? receive() timerLinda duration
182 }
183 std::ignore = lua_pushstringview(L_, "ac100de1-a696-4619-b2f0-a26de9d58ab8"); // L_: duration? receive() timerLinda duration key
184 STACK_CHECK(L_, 3); // 3 arguments ready
185 lua_call(L_, 3, LUA_MULTRET); // timerLinda:receive(duration,key) // L_: duration? result...
186 return lua_gettop(L_) - 1;
187}
188
189// #################################################################################################
190
164// --- If a client wants to transfer stuff of a given module from the current state to another Lane, the module must be required 191// --- If a client wants to transfer stuff of a given module from the current state to another Lane, the module must be required
165// with lanes.require, that will call the regular 'require', then populate the lookup database in the source lane 192// with lanes.require, that will call the regular 'require', then populate the lookup database in the source lane
166// module = lanes.require( "modname") 193// module = lanes.require( "modname")
@@ -592,15 +619,16 @@ extern LUAG_FUNC(linda);
592namespace { 619namespace {
593 namespace local { 620 namespace local {
594 static struct luaL_Reg const sLanesFunctions[] = { 621 static struct luaL_Reg const sLanesFunctions[] = {
622 { Universe::kFinally, Universe::InitializeFinalizer },
595 { "linda", LG_linda }, 623 { "linda", LG_linda },
596 { "now_secs", LG_now_secs },
597 { "wakeup_conv", LG_wakeup_conv },
598 { "set_thread_priority", LG_set_thread_priority },
599 { "set_thread_affinity", LG_set_thread_affinity },
600 { "nameof", LG_nameof }, 624 { "nameof", LG_nameof },
625 { "now_secs", LG_now_secs },
601 { "register", LG_register }, 626 { "register", LG_register },
602 { Universe::kFinally, Universe::InitializeFinalizer },
603 { "set_singlethreaded", LG_set_singlethreaded }, 627 { "set_singlethreaded", LG_set_singlethreaded },
628 { "set_thread_priority", LG_set_thread_priority },
629 { "set_thread_affinity", LG_set_thread_affinity },
630 { "sleep", LG_sleep },
631 { "wakeup_conv", LG_wakeup_conv },
604 { nullptr, nullptr } 632 { nullptr, nullptr }
605 }; 633 };
606 } // namespace local 634 } // namespace local