diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-13 18:11:21 +0200 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-13 18:15:46 +0200 |
| commit | f3e3d48b8d7a9c4eaee969e6ea36e038179d2497 (patch) | |
| tree | 15931bbaafa8cd06e9d0928bf939b36ee9231d99 /src | |
| parent | 2e27d4153943145f9102d5d56782ad6e20b76182 (diff) | |
| download | lanes-f3e3d48b8d7a9c4eaee969e6ea36e038179d2497.tar.gz lanes-f3e3d48b8d7a9c4eaee969e6ea36e038179d2497.tar.bz2 lanes-f3e3d48b8d7a9c4eaee969e6ea36e038179d2497.zip | |
Progressively applying the coding rules
Diffstat (limited to 'src')
| -rw-r--r-- | src/intercopycontext.cpp | 5 | ||||
| -rw-r--r-- | src/lanes.cpp | 88 | ||||
| -rw-r--r-- | src/macros_and_utils.h | 42 |
3 files changed, 68 insertions, 67 deletions
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 10d620e..8dd914c 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp | |||
| @@ -1157,12 +1157,13 @@ static char const* vt_names[] = { | |||
| 1157 | private: | 1157 | private: |
| 1158 | lua_State* const L2; | 1158 | lua_State* const L2; |
| 1159 | int const top_L2; | 1159 | int const top_L2; |
| 1160 | DEBUGSPEW_CODE(DebugSpewIndentScope m_scope); | 1160 | DEBUGSPEW_CODE(DebugSpewIndentScope scope); |
| 1161 | 1161 | ||
| 1162 | public: | 1162 | public: |
| 1163 | OnExit(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L2_) | 1163 | OnExit(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L2_) |
| 1164 | : L2{ L2_ } | 1164 | : L2{ L2_ } |
| 1165 | , top_L2{ lua_gettop(L2) } DEBUGSPEW_COMMA_PARAM(m_scope{ U_ }) | 1165 | , top_L2{ lua_gettop(L2) } |
| 1166 | DEBUGSPEW_COMMA_PARAM(scope{ U_ }) | ||
| 1166 | { | 1167 | { |
| 1167 | } | 1168 | } |
| 1168 | 1169 | ||
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 |
diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h index aa81db4..5987e73 100644 --- a/src/macros_and_utils.h +++ b/src/macros_and_utils.h | |||
| @@ -100,48 +100,48 @@ inline void LUA_ASSERT_IMPL(lua_State* L_, bool cond_, char const* file_, size_t | |||
| 100 | class StackChecker | 100 | class StackChecker |
| 101 | { | 101 | { |
| 102 | private: | 102 | private: |
| 103 | lua_State* const m_L; | 103 | lua_State* const L; |
| 104 | int m_oldtop; | 104 | int oldtop; |
| 105 | 105 | ||
| 106 | public: | 106 | public: |
| 107 | struct Relative | 107 | struct Relative |
| 108 | { | 108 | { |
| 109 | int const m_offset; | 109 | int const offset; |
| 110 | 110 | ||
| 111 | operator int() const { return m_offset; } | 111 | operator int() const { return offset; } |
| 112 | }; | 112 | }; |
| 113 | 113 | ||
| 114 | struct Absolute | 114 | struct Absolute |
| 115 | { | 115 | { |
| 116 | int const m_offset; | 116 | int const offset; |
| 117 | 117 | ||
| 118 | operator int() const { return m_offset; } | 118 | operator int() const { return offset; } |
| 119 | }; | 119 | }; |
| 120 | 120 | ||
| 121 | StackChecker(lua_State* const L_, Relative offset_, char const* file_, size_t const line_) | 121 | StackChecker(lua_State* const L_, Relative offset_, char const* file_, size_t const line_) |
| 122 | : m_L{ L_ } | 122 | : L{ L_ } |
| 123 | , m_oldtop{ lua_gettop(L_) - offset_ } | 123 | , oldtop{ lua_gettop(L_) - offset_ } |
| 124 | { | 124 | { |
| 125 | if ((offset_ < 0) || (m_oldtop < 0)) { | 125 | if ((offset_ < 0) || (oldtop < 0)) { |
| 126 | assert(false); | 126 | assert(false); |
| 127 | raise_luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%llu", lua_gettop(m_L), offset_, file_, line_); | 127 | raise_luaL_error(L, "STACK INIT ASSERT failed (%d not %d): %s:%llu", lua_gettop(L), offset_, file_, line_); |
| 128 | } | 128 | } |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | StackChecker(lua_State* const L_, Absolute pos_, char const* file_, size_t const line_) | 131 | StackChecker(lua_State* const L_, Absolute pos_, char const* file_, size_t const line_) |
| 132 | : m_L{ L_ } | 132 | : L{ L_ } |
| 133 | , m_oldtop{ 0 } | 133 | , oldtop{ 0 } |
| 134 | { | 134 | { |
| 135 | if (lua_gettop(m_L) != pos_) { | 135 | if (lua_gettop(L) != pos_) { |
| 136 | assert(false); | 136 | assert(false); |
| 137 | raise_luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%llu", lua_gettop(m_L), pos_, file_, line_); | 137 | raise_luaL_error(L, "STACK INIT ASSERT failed (%d not %d): %s:%llu", lua_gettop(L), pos_, file_, line_); |
| 138 | } | 138 | } |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | StackChecker& operator=(StackChecker const& rhs_) | 141 | StackChecker& operator=(StackChecker const& rhs_) |
| 142 | { | 142 | { |
| 143 | assert(m_L == rhs_.m_L); | 143 | assert(L == rhs_.L); |
| 144 | m_oldtop = rhs_.m_oldtop; | 144 | oldtop = rhs_.oldtop; |
| 145 | return *this; | 145 | return *this; |
| 146 | } | 146 | } |
| 147 | 147 | ||
| @@ -149,10 +149,10 @@ class StackChecker | |||
| 149 | void check(int expected_, char const* file_, size_t const line_) | 149 | void check(int expected_, char const* file_, size_t const line_) |
| 150 | { | 150 | { |
| 151 | if (expected_ != LUA_MULTRET) { | 151 | if (expected_ != LUA_MULTRET) { |
| 152 | int const actual{ lua_gettop(m_L) - m_oldtop }; | 152 | int const actual{ lua_gettop(L) - oldtop }; |
| 153 | if (actual != expected_) { | 153 | if (actual != expected_) { |
| 154 | assert(false); | 154 | assert(false); |
| 155 | raise_luaL_error(m_L, "STACK ASSERT failed (%d not %d): %s:%llu", actual, expected_, file_, line_); | 155 | raise_luaL_error(L, "STACK ASSERT failed (%d not %d): %s:%llu", actual, expected_, file_, line_); |
| 156 | } | 156 | } |
| 157 | } | 157 | } |
| 158 | } | 158 | } |
| @@ -233,13 +233,13 @@ template <typename T, auto = [] {}, typename specialization = void> | |||
| 233 | class Unique | 233 | class Unique |
| 234 | { | 234 | { |
| 235 | private: | 235 | private: |
| 236 | T m_val; | 236 | T val; |
| 237 | 237 | ||
| 238 | public: | 238 | public: |
| 239 | Unique() = default; | 239 | Unique() = default; |
| 240 | operator T() const { return m_val; } | 240 | operator T() const { return val; } |
| 241 | explicit Unique(T b_) | 241 | explicit Unique(T b_) |
| 242 | : m_val{ b_ } | 242 | : val{ b_ } |
| 243 | { | 243 | { |
| 244 | } | 244 | } |
| 245 | }; | 245 | }; |
