diff options
Diffstat (limited to 'src/lanes.cpp')
-rw-r--r-- | src/lanes.cpp | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/src/lanes.cpp b/src/lanes.cpp index f0ec84c..9c9d7d1 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
@@ -864,43 +864,43 @@ LUAG_FUNC(lane_new) | |||
864 | class OnExit | 864 | class OnExit |
865 | { | 865 | { |
866 | private: | 866 | private: |
867 | lua_State* const m_L; | 867 | lua_State* const L; |
868 | Lane* m_lane{ nullptr }; | 868 | Lane* lane{ nullptr }; |
869 | int const m_gc_cb_idx; | 869 | int const gc_cb_idx; |
870 | int const m_name_idx; | 870 | int const name_idx; |
871 | DEBUGSPEW_CODE(Universe* const U); | 871 | DEBUGSPEW_CODE(Universe* const U); |
872 | DEBUGSPEW_CODE(DebugSpewIndentScope m_scope); | 872 | DEBUGSPEW_CODE(DebugSpewIndentScope scope); |
873 | 873 | ||
874 | public: | 874 | public: |
875 | OnExit(lua_State* L_, Lane* lane_, int gc_cb_idx_, int name_idx_ DEBUGSPEW_COMMA_PARAM(Universe* U_)) | 875 | OnExit(lua_State* L_, Lane* lane_, int gc_cb_idx_, int name_idx_ DEBUGSPEW_COMMA_PARAM(Universe* U_)) |
876 | : m_L{ L_ } | 876 | : L{ L_ } |
877 | , m_lane{ lane_ } | 877 | , lane{ lane_ } |
878 | , m_gc_cb_idx{ gc_cb_idx_ } | 878 | , gc_cb_idx{ gc_cb_idx_ } |
879 | , m_name_idx{ name_idx_ } | 879 | , name_idx{ name_idx_ } |
880 | DEBUGSPEW_COMMA_PARAM(U{ U_ }) | 880 | DEBUGSPEW_COMMA_PARAM(U{ U_ }) |
881 | DEBUGSPEW_COMMA_PARAM(m_scope{ U_ }) | 881 | DEBUGSPEW_COMMA_PARAM(scope{ U_ }) |
882 | { | 882 | { |
883 | } | 883 | } |
884 | 884 | ||
885 | ~OnExit() | 885 | ~OnExit() |
886 | { | 886 | { |
887 | if (m_lane) { | 887 | if (lane) { |
888 | STACK_CHECK_START_REL(m_L, 0); | 888 | STACK_CHECK_START_REL(L, 0); |
889 | // we still need a full userdata so that garbage collection can do its thing | 889 | // we still need a full userdata so that garbage collection can do its thing |
890 | prepareUserData(); | 890 | prepareUserData(); |
891 | // remove it immediately from the stack so that the error that landed us here is at the top | 891 | // remove it immediately from the stack so that the error that landed us here is at the top |
892 | lua_pop(m_L, 1); | 892 | lua_pop(L, 1); |
893 | STACK_CHECK(m_L, 0); | 893 | STACK_CHECK(L, 0); |
894 | // leave a single cancel_error on the stack for the caller | 894 | // leave a single cancel_error on the stack for the caller |
895 | lua_settop(m_lane->L, 0); | 895 | lua_settop(lane->L, 0); |
896 | kCancelError.pushKey(m_lane->L); | 896 | kCancelError.pushKey(lane->L); |
897 | { | 897 | { |
898 | std::lock_guard lock{ m_lane->doneMutex }; | 898 | std::lock_guard _guard{ lane->doneMutex }; |
899 | // this will cause lane_main to skip actual running (because we are not Pending anymore) | 899 | // this will cause lane_main to skip actual running (because we are not Pending anymore) |
900 | m_lane->status = Lane::Running; | 900 | lane->status = Lane::Running; |
901 | } | 901 | } |
902 | // unblock the thread so that it can terminate gracefully | 902 | // unblock the thread so that it can terminate gracefully |
903 | m_lane->ready.count_down(); | 903 | lane->ready.count_down(); |
904 | } | 904 | } |
905 | } | 905 | } |
906 | 906 | ||
@@ -908,56 +908,56 @@ LUAG_FUNC(lane_new) | |||
908 | void prepareUserData() | 908 | void prepareUserData() |
909 | { | 909 | { |
910 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lane_new: preparing lane userdata\n" INDENT_END(U))); | 910 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lane_new: preparing lane userdata\n" INDENT_END(U))); |
911 | STACK_CHECK_START_REL(m_L, 0); | 911 | STACK_CHECK_START_REL(L, 0); |
912 | // a Lane full userdata needs a single uservalue | 912 | // a Lane full userdata needs a single uservalue |
913 | Lane** const ud{ lua_newuserdatauv<Lane*>(m_L, 1) }; // m_L: ... lane | 913 | Lane** const _ud{ lua_newuserdatauv<Lane*>(L, 1) }; // L: ... lane |
914 | *ud = m_lane; // don't forget to store the pointer in the userdata! | 914 | *_ud = lane; // don't forget to store the pointer in the userdata! |
915 | 915 | ||
916 | // Set metatable for the userdata | 916 | // Set metatable for the userdata |
917 | // | 917 | // |
918 | lua_pushvalue(m_L, lua_upvalueindex(1)); // m_L: ... lane mt | 918 | lua_pushvalue(L, lua_upvalueindex(1)); // L: ... lane mt |
919 | lua_setmetatable(m_L, -2); // m_L: ... lane | 919 | lua_setmetatable(L, -2); // L: ... lane |
920 | STACK_CHECK(m_L, 1); | 920 | STACK_CHECK(L, 1); |
921 | 921 | ||
922 | // Create uservalue for the userdata | 922 | // Create uservalue for the userdata |
923 | // (this is where lane body return values will be stored when the handle is indexed by a numeric key) | 923 | // (this is where lane body return values will be stored when the handle is indexed by a numeric key) |
924 | lua_newtable(m_L); // m_L: ... lane {uv} | 924 | lua_newtable(L); // L: ... lane {uv} |
925 | 925 | ||
926 | // Store the gc_cb callback in the uservalue | 926 | // Store the gc_cb callback in the uservalue |
927 | if (m_gc_cb_idx > 0) { | 927 | if (gc_cb_idx > 0) { |
928 | kLaneGC.pushKey(m_L); // m_L: ... lane {uv} k | 928 | kLaneGC.pushKey(L); // L: ... lane {uv} k |
929 | lua_pushvalue(m_L, m_gc_cb_idx); // m_L: ... lane {uv} k gc_cb | 929 | lua_pushvalue(L, gc_cb_idx); // L: ... lane {uv} k gc_cb |
930 | lua_rawset(m_L, -3); // m_L: ... lane {uv} | 930 | lua_rawset(L, -3); // L: ... lane {uv} |
931 | } | 931 | } |
932 | 932 | ||
933 | lua_setiuservalue(m_L, -2, 1); // m_L: ... lane | 933 | lua_setiuservalue(L, -2, 1); // L: ... lane |
934 | 934 | ||
935 | lua_State* L2{ m_lane->L }; | 935 | lua_State* _L2{ lane->L }; |
936 | STACK_CHECK_START_REL(L2, 0); | 936 | STACK_CHECK_START_REL(_L2, 0); |
937 | char const* const debugName{ (m_name_idx > 0) ? lua_tostring(m_L, m_name_idx) : nullptr }; | 937 | char const* const debugName{ (name_idx > 0) ? lua_tostring(L, name_idx) : nullptr }; |
938 | if (debugName) | 938 | if (debugName) |
939 | { | 939 | { |
940 | if (strcmp(debugName, "auto") != 0) { | 940 | if (strcmp(debugName, "auto") != 0) { |
941 | lua_pushstring(L2, debugName); // m_L: ... lane L2: "<name>" | 941 | lua_pushstring(_L2, debugName); // L: ... lane L2: "<name>" |
942 | } else { | 942 | } else { |
943 | lua_Debug ar; | 943 | lua_Debug ar; |
944 | lua_pushvalue(m_L, 1); // m_L: ... lane func | 944 | lua_pushvalue(L, 1); // L: ... lane func |
945 | lua_getinfo(m_L, ">S", &ar); // m_L: ... lane | 945 | lua_getinfo(L, ">S", &ar); // L: ... lane |
946 | lua_pushfstring(L2, "%s:%d", ar.short_src, ar.linedefined); // m_L: ... lane L2: "<name>" | 946 | lua_pushfstring(_L2, "%s:%d", ar.short_src, ar.linedefined); // L: ... lane L2: "<name>" |
947 | } | 947 | } |
948 | m_lane->changeDebugName(-1); | 948 | lane->changeDebugName(-1); |
949 | lua_pop(L2, 1); // m_L: ... lane L2: | 949 | lua_pop(_L2, 1); // L: ... lane L2: |
950 | } | 950 | } |
951 | STACK_CHECK(L2, 0); | 951 | STACK_CHECK(_L2, 0); |
952 | STACK_CHECK(m_L, 1); | 952 | STACK_CHECK(L, 1); |
953 | } | 953 | } |
954 | 954 | ||
955 | public: | 955 | public: |
956 | void success() | 956 | void success() |
957 | { | 957 | { |
958 | prepareUserData(); | 958 | prepareUserData(); |
959 | m_lane->ready.count_down(); | 959 | lane->ready.count_down(); |
960 | m_lane = nullptr; | 960 | lane = nullptr; |
961 | } | 961 | } |
962 | } onExit{ L_, _lane, _gc_cb_idx, _name_idx DEBUGSPEW_COMMA_PARAM(_U) }; | 962 | } onExit{ L_, _lane, _gc_cb_idx, _name_idx DEBUGSPEW_COMMA_PARAM(_U) }; |
963 | // launch the thread early, it will sync with a std::latch to parallelize OS thread warmup and L2 preparation | 963 | // launch the thread early, it will sync with a std::latch to parallelize OS thread warmup and L2 preparation |