aboutsummaryrefslogtreecommitdiff
path: root/src/lanes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lanes.cpp')
-rw-r--r--src/lanes.cpp86
1 files changed, 43 insertions, 43 deletions
diff --git a/src/lanes.cpp b/src/lanes.cpp
index 8a76217..8890b06 100644
--- a/src/lanes.cpp
+++ b/src/lanes.cpp
@@ -464,7 +464,7 @@ static int universe_gc( lua_State* L)
464 while (lane != SELFDESTRUCT_END) 464 while (lane != SELFDESTRUCT_END)
465 { 465 {
466 // attempt a regular unforced hard cancel with a small timeout 466 // attempt a regular unforced hard cancel with a small timeout
467 bool const cancelled = THREAD_ISNULL(lane->thread) || thread_cancel(L, lane, CO_Hard, 0.0001, false, 0.0) != CancelResult::Timeout; 467 bool const cancelled{ THREAD_ISNULL(lane->thread) || thread_cancel(L, lane, CancelOp::Hard, 0.0001, false, 0.0) != CancelResult::Timeout };
468 // if we failed, and we know the thread is waiting on a linda 468 // if we failed, and we know the thread is waiting on a linda
469 if (cancelled == false && lane->status == WAITING && lane->waiting_on != nullptr) 469 if (cancelled == false && lane->status == WAITING && lane->waiting_on != nullptr)
470 { 470 {
@@ -1085,7 +1085,7 @@ LUAG_FUNC(lane_new)
1085 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); 1085 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);
1086 1086
1087 // populate with selected libraries at the same time 1087 // populate with selected libraries at the same time
1088 lua_State* const L2{ luaG_newstate(U, L, libs_str) }; // L // L2 1088 lua_State* const L2{ luaG_newstate(U, L, libs_str) }; // L // L2
1089 1089
1090 // 'lane' is allocated from heap, not Lua, since its life span may surpass the handle's (if free running thread) 1090 // 'lane' is allocated from heap, not Lua, since its life span may surpass the handle's (if free running thread)
1091 Lane* const lane{ new (U) Lane{ U, L2 } }; 1091 Lane* const lane{ new (U) Lane{ U, L2 } };
@@ -1122,23 +1122,23 @@ LUAG_FUNC(lane_new)
1122 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lane_new: launching thread\n" INDENT_END)); 1122 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lane_new: launching thread\n" INDENT_END));
1123 THREAD_CREATE(&lane->thread, lane_main, lane, priority); 1123 THREAD_CREATE(&lane->thread, lane_main, lane, priority);
1124 1124
1125 STACK_GROW( L2, nargs + 3); // 1125 STACK_GROW( L2, nargs + 3); //
1126 STACK_CHECK_START_REL(L2, 0); 1126 STACK_CHECK_START_REL(L2, 0);
1127 1127
1128 STACK_GROW(L, 3); // func libs priority globals package required gc_cb [... args ...] 1128 STACK_GROW(L, 3); // func libs priority globals package required gc_cb [... args ...]
1129 STACK_CHECK_START_REL(L, 0); 1129 STACK_CHECK_START_REL(L, 0);
1130 1130
1131 // give a default "Lua" name to the thread to see VM name in Decoda debugger 1131 // give a default "Lua" name to the thread to see VM name in Decoda debugger
1132 lua_pushfstring( L2, "Lane #%p", L2); // "..." 1132 lua_pushfstring( L2, "Lane #%p", L2); // "..."
1133 lua_setglobal( L2, "decoda_name"); // 1133 lua_setglobal( L2, "decoda_name"); //
1134 ASSERT_L( lua_gettop( L2) == 0); 1134 ASSERT_L( lua_gettop( L2) == 0);
1135 1135
1136 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lane_new: update 'package'\n" INDENT_END)); 1136 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lane_new: update 'package'\n" INDENT_END));
1137 // package 1137 // package
1138 if (package_idx != 0) 1138 if (package_idx != 0)
1139 { 1139 {
1140 // when copying with mode eLM_LaneBody, should raise an error in case of problem, not leave it one the stack 1140 // when copying with mode LookupMode::LaneBody, should raise an error in case of problem, not leave it one the stack
1141 (void) luaG_inter_copy_package( U, L, L2, package_idx, eLM_LaneBody); 1141 (void) luaG_inter_copy_package(U, L, L2, package_idx, LookupMode::LaneBody);
1142 } 1142 }
1143 1143
1144 // modules to require in the target lane *before* the function is transfered! 1144 // modules to require in the target lane *before* the function is transfered!
@@ -1154,8 +1154,8 @@ LUAG_FUNC(lane_new)
1154 return luaL_error(L, "expected required module list as a table, got %s", luaL_typename(L, required_idx)); 1154 return luaL_error(L, "expected required module list as a table, got %s", luaL_typename(L, required_idx));
1155 } 1155 }
1156 1156
1157 lua_pushnil(L); // func libs priority globals package required gc_cb [... args ...] nil 1157 lua_pushnil(L); // func libs priority globals package required gc_cb [... args ...] nil
1158 while( lua_next(L, required_idx) != 0) // func libs priority globals package required gc_cb [... args ...] n "modname" 1158 while( lua_next(L, required_idx) != 0) // func libs priority globals package required gc_cb [... args ...] n "modname"
1159 { 1159 {
1160 if (lua_type(L, -1) != LUA_TSTRING || lua_type(L, -2) != LUA_TNUMBER || lua_tonumber(L, -2) != nbRequired) 1160 if (lua_type(L, -1) != LUA_TSTRING || lua_type(L, -2) != LUA_TNUMBER || lua_tonumber(L, -2) != nbRequired)
1161 { 1161 {
@@ -1169,33 +1169,33 @@ LUAG_FUNC(lane_new)
1169 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lane_new: require '%s'\n" INDENT_END, name)); 1169 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lane_new: require '%s'\n" INDENT_END, name));
1170 1170
1171 // require the module in the target lane 1171 // require the module in the target lane
1172 lua_getglobal( L2, "require"); // require()? 1172 lua_getglobal( L2, "require"); // require()?
1173 if (lua_isnil( L2, -1)) 1173 if (lua_isnil( L2, -1))
1174 { 1174 {
1175 lua_pop( L2, 1); // 1175 lua_pop( L2, 1); //
1176 return luaL_error(L, "cannot pre-require modules without loading 'package' library first"); 1176 return luaL_error(L, "cannot pre-require modules without loading 'package' library first");
1177 } 1177 }
1178 else 1178 else
1179 { 1179 {
1180 lua_pushlstring( L2, name, len); // require() name 1180 lua_pushlstring( L2, name, len); // require() name
1181 if (lua_pcall( L2, 1, 1, 0) != LUA_OK) // ret/errcode 1181 if (lua_pcall( L2, 1, 1, 0) != LUA_OK) // ret/errcode
1182 { 1182 {
1183 // propagate error to main state if any 1183 // propagate error to main state if any
1184 luaG_inter_move(U, L2, L, 1, eLM_LaneBody); // func libs priority globals package required gc_cb [... args ...] n "modname" error 1184 luaG_inter_move(U, L2, L, 1, LookupMode::LaneBody); // func libs priority globals package required gc_cb [... args ...] n "modname" error
1185 raise_lua_error(L); 1185 raise_lua_error(L);
1186 } 1186 }
1187 // after requiring the module, register the functions it exported in our name<->function database 1187 // after requiring the module, register the functions it exported in our name<->function database
1188 populate_func_lookup_table( L2, -1, name); 1188 populate_func_lookup_table( L2, -1, name);
1189 lua_pop( L2, 1); // 1189 lua_pop( L2, 1); //
1190 } 1190 }
1191 } 1191 }
1192 lua_pop(L, 1); // func libs priority globals package required gc_cb [... args ...] n 1192 lua_pop(L, 1); // func libs priority globals package required gc_cb [... args ...] n
1193 ++ nbRequired; 1193 ++ nbRequired;
1194 } // func libs priority globals package required gc_cb [... args ...] 1194 } // func libs priority globals package required gc_cb [... args ...]
1195 DEBUGSPEW_CODE( -- U->debugspew_indent_depth); 1195 DEBUGSPEW_CODE( -- U->debugspew_indent_depth);
1196 } 1196 }
1197 STACK_CHECK(L, 0); 1197 STACK_CHECK(L, 0);
1198 STACK_CHECK(L2, 0); // 1198 STACK_CHECK(L2, 0); //
1199 1199
1200 // Appending the specified globals to the global environment 1200 // Appending the specified globals to the global environment
1201 // *after* stdlibs have been loaded and modules required, in case we transfer references to native functions they exposed... 1201 // *after* stdlibs have been loaded and modules required, in case we transfer references to native functions they exposed...
@@ -1209,17 +1209,17 @@ LUAG_FUNC(lane_new)
1209 } 1209 }
1210 1210
1211 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); 1211 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);
1212 lua_pushnil(L); // func libs priority globals package required gc_cb [... args ...] nil 1212 lua_pushnil(L); // func libs priority globals package required gc_cb [... args ...] nil
1213 // Lua 5.2 wants us to push the globals table on the stack 1213 // Lua 5.2 wants us to push the globals table on the stack
1214 lua_pushglobaltable(L2); // _G 1214 lua_pushglobaltable(L2); // _G
1215 while( lua_next(L, globals_idx)) // func libs priority globals package required gc_cb [... args ...] k v 1215 while( lua_next(L, globals_idx)) // func libs priority globals package required gc_cb [... args ...] k v
1216 { 1216 {
1217 luaG_inter_copy(U, L, L2, 2, eLM_LaneBody); // _G k v 1217 luaG_inter_copy(U, L, L2, 2, LookupMode::LaneBody); // _G k v
1218 // assign it in L2's globals table 1218 // assign it in L2's globals table
1219 lua_rawset(L2, -3); // _G 1219 lua_rawset(L2, -3); // _G
1220 lua_pop(L, 1); // func libs priority globals package required gc_cb [... args ...] k 1220 lua_pop(L, 1); // func libs priority globals package required gc_cb [... args ...] k
1221 } // func libs priority globals package required gc_cb [... args ...] 1221 } // func libs priority globals package required gc_cb [... args ...]
1222 lua_pop( L2, 1); // 1222 lua_pop( L2, 1); //
1223 1223
1224 DEBUGSPEW_CODE( -- U->debugspew_indent_depth); 1224 DEBUGSPEW_CODE( -- U->debugspew_indent_depth);
1225 } 1225 }
@@ -1232,8 +1232,8 @@ LUAG_FUNC(lane_new)
1232 int res; 1232 int res;
1233 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lane_new: transfer lane body\n" INDENT_END)); 1233 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lane_new: transfer lane body\n" INDENT_END));
1234 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); 1234 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);
1235 lua_pushvalue(L, 1); // func libs priority globals package required gc_cb [... args ...] func 1235 lua_pushvalue(L, 1); // func libs priority globals package required gc_cb [... args ...] func
1236 res = luaG_inter_move(U, L, L2, 1, eLM_LaneBody); // func libs priority globals package required gc_cb [... args ...] // func 1236 res = luaG_inter_move(U, L, L2, 1, LookupMode::LaneBody); // func libs priority globals package required gc_cb [... args ...] // func
1237 DEBUGSPEW_CODE( -- U->debugspew_indent_depth); 1237 DEBUGSPEW_CODE( -- U->debugspew_indent_depth);
1238 if (res != 0) 1238 if (res != 0)
1239 { 1239 {
@@ -1243,7 +1243,7 @@ LUAG_FUNC(lane_new)
1243 else if (lua_type(L, 1) == LUA_TSTRING) 1243 else if (lua_type(L, 1) == LUA_TSTRING)
1244 { 1244 {
1245 // compile the string 1245 // compile the string
1246 if (luaL_loadstring(L2, lua_tostring(L, 1)) != 0) // func 1246 if (luaL_loadstring(L2, lua_tostring(L, 1)) != 0) // func
1247 { 1247 {
1248 return luaL_error(L, "error when parsing lane function code"); 1248 return luaL_error(L, "error when parsing lane function code");
1249 } 1249 }
@@ -1258,7 +1258,7 @@ LUAG_FUNC(lane_new)
1258 int res; 1258 int res;
1259 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lane_new: transfer lane arguments\n" INDENT_END)); 1259 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lane_new: transfer lane arguments\n" INDENT_END));
1260 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); 1260 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);
1261 res = luaG_inter_move(U, L, L2, nargs, eLM_LaneBody); // func libs priority globals package required gc_cb // func [... args ...] 1261 res = luaG_inter_move(U, L, L2, nargs, LookupMode::LaneBody); // func libs priority globals package required gc_cb // func [... args ...]
1262 DEBUGSPEW_CODE( -- U->debugspew_indent_depth); 1262 DEBUGSPEW_CODE( -- U->debugspew_indent_depth);
1263 if (res != 0) 1263 if (res != 0)
1264 { 1264 {
@@ -1271,31 +1271,31 @@ LUAG_FUNC(lane_new)
1271 STACK_CHECK( L2, 1 + nargs); 1271 STACK_CHECK( L2, 1 + nargs);
1272 1272
1273 // a Lane full userdata needs a single uservalue 1273 // a Lane full userdata needs a single uservalue
1274 Lane** const ud{ lua_newuserdatauv<Lane*>(L, 1) }; // func libs priority globals package required gc_cb lane 1274 Lane** const ud{ lua_newuserdatauv<Lane*>(L, 1) }; // func libs priority globals package required gc_cb lane
1275 *ud = lane; // don't forget to store the pointer in the userdata! 1275 *ud = lane; // don't forget to store the pointer in the userdata!
1276 1276
1277 // Set metatable for the userdata 1277 // Set metatable for the userdata
1278 // 1278 //
1279 lua_pushvalue(L, lua_upvalueindex( 1)); // func libs priority globals package required gc_cb lane mt 1279 lua_pushvalue(L, lua_upvalueindex( 1)); // func libs priority globals package required gc_cb lane mt
1280 lua_setmetatable(L, -2); // func libs priority globals package required gc_cb lane 1280 lua_setmetatable(L, -2); // func libs priority globals package required gc_cb lane
1281 STACK_CHECK(L, 1); 1281 STACK_CHECK(L, 1);
1282 1282
1283 // Create uservalue for the userdata 1283 // Create uservalue for the userdata
1284 // (this is where lane body return values will be stored when the handle is indexed by a numeric key) 1284 // (this is where lane body return values will be stored when the handle is indexed by a numeric key)
1285 lua_newtable(L); // func libs cancelstep priority globals package required gc_cb lane uv 1285 lua_newtable(L); // func libs cancelstep priority globals package required gc_cb lane uv
1286 1286
1287 // Store the gc_cb callback in the uservalue 1287 // Store the gc_cb callback in the uservalue
1288 if (gc_cb_idx > 0) 1288 if (gc_cb_idx > 0)
1289 { 1289 {
1290 GCCB_KEY.pushKey(L); // func libs priority globals package required gc_cb lane uv k 1290 GCCB_KEY.pushKey(L); // func libs priority globals package required gc_cb lane uv k
1291 lua_pushvalue(L, gc_cb_idx); // func libs priority globals package required gc_cb lane uv k gc_cb 1291 lua_pushvalue(L, gc_cb_idx); // func libs priority globals package required gc_cb lane uv k gc_cb
1292 lua_rawset(L, -3); // func libs priority globals package required gc_cb lane uv 1292 lua_rawset(L, -3); // func libs priority globals package required gc_cb lane uv
1293 } 1293 }
1294 1294
1295 lua_setiuservalue(L, -2, 1); // func libs priority globals package required gc_cb lane 1295 lua_setiuservalue(L, -2, 1); // func libs priority globals package required gc_cb lane
1296 1296
1297 // Store 'lane' in the lane's registry, for 'cancel_test()' (we do cancel tests at pending send/receive). 1297 // Store 'lane' in the lane's registry, for 'cancel_test()' (we do cancel tests at pending send/receive).
1298 LANE_POINTER_REGKEY.setValue(L2, [lane](lua_State* L) { lua_pushlightuserdata(L, lane); }); // func [... args ...] 1298 LANE_POINTER_REGKEY.setValue(L2, [lane](lua_State* L) { lua_pushlightuserdata(L, lane); }); // func [... args ...]
1299 1299
1300 STACK_CHECK(L, 1); 1300 STACK_CHECK(L, 1);
1301 STACK_CHECK(L2, 1 + nargs); 1301 STACK_CHECK(L2, 1 + nargs);
@@ -1482,7 +1482,7 @@ LUAG_FUNC(thread_join)
1482 case DONE: 1482 case DONE:
1483 { 1483 {
1484 int const n{ lua_gettop(L2) }; // whole L2 stack 1484 int const n{ lua_gettop(L2) }; // whole L2 stack
1485 if ((n > 0) && (luaG_inter_move(U, L2, L, n, eLM_LaneBody) != 0)) 1485 if ((n > 0) && (luaG_inter_move(U, L2, L, n, LookupMode::LaneBody) != 0))
1486 { 1486 {
1487 return luaL_error(L, "tried to copy unsupported types"); 1487 return luaL_error(L, "tried to copy unsupported types");
1488 } 1488 }
@@ -1496,7 +1496,7 @@ LUAG_FUNC(thread_join)
1496 STACK_GROW(L, 3); 1496 STACK_GROW(L, 3);
1497 lua_pushnil(L); 1497 lua_pushnil(L);
1498 // even when ERROR_FULL_STACK, if the error is not LUA_ERRRUN, the handler wasn't called, and we only have 1 error message on the stack ... 1498 // even when ERROR_FULL_STACK, if the error is not LUA_ERRRUN, the handler wasn't called, and we only have 1 error message on the stack ...
1499 if (luaG_inter_move(U, L2, L, n, eLM_LaneBody) != 0) // nil "err" [trace] 1499 if (luaG_inter_move(U, L2, L, n, LookupMode::LaneBody) != 0) // nil "err" [trace]
1500 { 1500 {
1501 return luaL_error(L, "tried to copy unsupported types: %s", lua_tostring(L, -n)); 1501 return luaL_error(L, "tried to copy unsupported types: %s", lua_tostring(L, -n));
1502 } 1502 }
@@ -1967,7 +1967,7 @@ LUAG_FUNC(configure)
1967 STACK_CHECK(L, 2); 1967 STACK_CHECK(L, 2);
1968 1968
1969 { 1969 {
1970 char const* errmsg{ push_deep_proxy(L, U->timer_deep, 0, eLM_LaneBody) }; // settings M timer_deep 1970 char const* errmsg{ push_deep_proxy(L, U->timer_deep, 0, LookupMode::LaneBody) }; // settings M timer_deep
1971 if (errmsg != nullptr) 1971 if (errmsg != nullptr)
1972 { 1972 {
1973 return luaL_error(L, errmsg); 1973 return luaL_error(L, errmsg);