diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-11-20 17:51:49 +0100 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-11-20 17:51:49 +0100 |
commit | 304e4dfabe4555dff4aa72e75b677405fd30d1b3 (patch) | |
tree | ac934000415b46f784bda25ba671e74b9481573b /src/lane.hpp | |
parent | 872826ecaca5370e3492385cff3795d995b33ec7 (diff) | |
download | lanes-304e4dfabe4555dff4aa72e75b677405fd30d1b3.tar.gz lanes-304e4dfabe4555dff4aa72e75b677405fd30d1b3.tar.bz2 lanes-304e4dfabe4555dff4aa72e75b677405fd30d1b3.zip |
Some [[nodiscard]] boyscouting
Diffstat (limited to 'src/lane.hpp')
-rw-r--r-- | src/lane.hpp | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/src/lane.hpp b/src/lane.hpp index b5be9ab..29bf213 100644 --- a/src/lane.hpp +++ b/src/lane.hpp | |||
@@ -139,7 +139,8 @@ class Lane | |||
139 | 139 | ||
140 | ErrorTraceLevel const errorTraceLevel{ Basic }; | 140 | ErrorTraceLevel const errorTraceLevel{ Basic }; |
141 | 141 | ||
142 | [[nodiscard]] static void* operator new(size_t size_, Universe* U_) noexcept { return U_->internalAllocator.alloc(size_); } | 142 | [[nodiscard]] |
143 | static void* operator new(size_t size_, Universe* U_) noexcept { return U_->internalAllocator.alloc(size_); } | ||
143 | // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception | 144 | // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception |
144 | static void operator delete(void* p_, Universe* U_) { U_->internalAllocator.free(p_, sizeof(Lane)); } | 145 | static void operator delete(void* p_, Universe* U_) { U_->internalAllocator.free(p_, sizeof(Lane)); } |
145 | // this one is for us, to make sure memory is freed by the correct allocator | 146 | // this one is for us, to make sure memory is freed by the correct allocator |
@@ -156,7 +157,8 @@ class Lane | |||
156 | 157 | ||
157 | private: | 158 | private: |
158 | 159 | ||
159 | [[nodiscard]] CancelResult internalCancel(CancelRequest rq_, std::chrono::time_point<std::chrono::steady_clock> until_, WakeLane wakeLane_); | 160 | [[nodiscard]] |
161 | CancelResult internalCancel(CancelRequest rq_, std::chrono::time_point<std::chrono::steady_clock> until_, WakeLane wakeLane_); | ||
160 | 162 | ||
161 | public: | 163 | public: |
162 | 164 | ||
@@ -170,33 +172,43 @@ class Lane | |||
170 | nresults = 0; | 172 | nresults = 0; |
171 | lua_close(_L); // this collects our coroutine thread at the same time | 173 | lua_close(_L); // this collects our coroutine thread at the same time |
172 | } | 174 | } |
173 | [[nodiscard]] std::string_view errorTraceLevelString() const; | 175 | [[nodiscard]] |
174 | [[nodiscard]] int errorHandlerCount() const noexcept | 176 | std::string_view errorTraceLevelString() const; |
177 | [[nodiscard]] | ||
178 | int errorHandlerCount() const noexcept | ||
175 | { | 179 | { |
176 | // don't push a error handler when in coroutine mode, as the first lua_resume wants only the function and its arguments on the stack | 180 | // don't push a error handler when in coroutine mode, as the first lua_resume wants only the function and its arguments on the stack |
177 | return ((errorTraceLevel == Lane::Minimal) || isCoroutine()) ? 0 : 1; | 181 | return ((errorTraceLevel == Lane::Minimal) || isCoroutine()) ? 0 : 1; |
178 | } | 182 | } |
179 | [[nodiscard]] bool isCoroutine() const noexcept { return S != L; } | 183 | [[nodiscard]] |
180 | [[nodiscard]] std::string_view getDebugName() const | 184 | bool isCoroutine() const noexcept { return S != L; } |
185 | [[nodiscard]] | ||
186 | std::string_view getDebugName() const | ||
181 | { | 187 | { |
182 | std::lock_guard<std::mutex> _guard{ debugNameMutex }; | 188 | std::lock_guard<std::mutex> _guard{ debugNameMutex }; |
183 | return debugName; | 189 | return debugName; |
184 | } | 190 | } |
185 | static int LuaErrorHandler(lua_State* L_); | 191 | static int LuaErrorHandler(lua_State* L_); |
186 | [[nodiscard]] int pushErrorHandler() const noexcept { return (errorHandlerCount() == 0) ? 0 : (lua_pushcfunction(L, LuaErrorHandler), 1); } | 192 | [[nodiscard]] |
187 | [[nodiscard]] std::string_view pushErrorTraceLevel(lua_State* L_) const; | 193 | int pushErrorHandler() const noexcept { return (errorHandlerCount() == 0) ? 0 : (lua_pushcfunction(L, LuaErrorHandler), 1); } |
194 | [[nodiscard]] | ||
195 | std::string_view pushErrorTraceLevel(lua_State* L_) const; | ||
188 | static void PushMetatable(lua_State* L_); | 196 | static void PushMetatable(lua_State* L_); |
189 | void pushStatusString(lua_State* L_) const; | 197 | void pushStatusString(lua_State* L_) const; |
190 | void pushIndexedResult(lua_State* L_, int key_) const; | 198 | void pushIndexedResult(lua_State* L_, int key_) const; |
191 | void resetResultsStorage(lua_State* L_, StackIndex self_idx_); | 199 | void resetResultsStorage(lua_State* L_, StackIndex self_idx_); |
192 | void selfdestructAdd(); | 200 | void selfdestructAdd(); |
193 | [[nodiscard]] bool selfdestructRemove(); | 201 | [[nodiscard]] |
202 | bool selfdestructRemove(); | ||
194 | void securizeDebugName(lua_State* L_); | 203 | void securizeDebugName(lua_State* L_); |
195 | void startThread(int priority_); | 204 | void startThread(int priority_); |
196 | [[nodiscard]] int storeResults(lua_State* L_); | 205 | [[nodiscard]] |
197 | [[nodiscard]] std::string_view threadStatusString() const; | 206 | int storeResults(lua_State* L_); |
207 | [[nodiscard]] | ||
208 | std::string_view threadStatusString() const; | ||
198 | // wait until the lane stops working with its state (either Suspended or Done+) | 209 | // wait until the lane stops working with its state (either Suspended or Done+) |
199 | [[nodiscard]] bool waitForCompletion(std::chrono::time_point<std::chrono::steady_clock> until_); | 210 | [[nodiscard]] |
211 | bool waitForCompletion(std::chrono::time_point<std::chrono::steady_clock> until_); | ||
200 | }; | 212 | }; |
201 | 213 | ||
202 | // ################################################################################################# | 214 | // ################################################################################################# |
@@ -205,7 +217,8 @@ class Lane | |||
205 | // 'Lane' are malloc/free'd and the handle only carries a pointer. | 217 | // 'Lane' are malloc/free'd and the handle only carries a pointer. |
206 | // This is not deep userdata since the handle is not portable among lanes. | 218 | // This is not deep userdata since the handle is not portable among lanes. |
207 | // | 219 | // |
208 | [[nodiscard]] inline Lane* ToLane(lua_State* const L_, StackIndex const i_) | 220 | [[nodiscard]] |
221 | static inline Lane* ToLane(lua_State* const L_, StackIndex const i_) | ||
209 | { | 222 | { |
210 | return *(static_cast<Lane**>(luaL_checkudata(L_, i_, kLaneMetatableName.data()))); | 223 | return *(static_cast<Lane**>(luaL_checkudata(L_, i_, kLaneMetatableName.data()))); |
211 | } | 224 | } |