diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-14 12:25:23 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-14 12:25:23 +0200 |
commit | 792128255b6c6add22f97ea60734181cb915f2ae (patch) | |
tree | c3d8e3a3466639591245495ec0148d49732193c3 /src | |
parent | 6177a3c6b5a05ac2c64978ccf3ca11de9793505b (diff) | |
download | lanes-792128255b6c6add22f97ea60734181cb915f2ae.tar.gz lanes-792128255b6c6add22f97ea60734181cb915f2ae.tar.bz2 lanes-792128255b6c6add22f97ea60734181cb915f2ae.zip |
More fixes to make clang happy
Diffstat (limited to 'src')
-rw-r--r-- | src/_pch.h | 1 | ||||
-rw-r--r-- | src/compat.h | 229 | ||||
-rw-r--r-- | src/intercopycontext.cpp | 3 | ||||
-rw-r--r-- | src/keeper.h | 2 | ||||
-rw-r--r-- | src/lane.cpp | 14 | ||||
-rw-r--r-- | src/lane.h | 2 | ||||
-rw-r--r-- | src/threading.cpp | 36 | ||||
-rw-r--r-- | src/threading.h | 2 | ||||
-rw-r--r-- | src/tools.cpp | 4 |
9 files changed, 122 insertions, 171 deletions
@@ -7,6 +7,7 @@ | |||
7 | #include <cassert> | 7 | #include <cassert> |
8 | #include <chrono> | 8 | #include <chrono> |
9 | #include <compare> | 9 | #include <compare> |
10 | #include <concepts> | ||
10 | #include <condition_variable> | 11 | #include <condition_variable> |
11 | #include <functional> | 12 | #include <functional> |
12 | #include <iostream> | 13 | #include <iostream> |
diff --git a/src/compat.h b/src/compat.h index 3b0ebf4..bcea225 100644 --- a/src/compat.h +++ b/src/compat.h | |||
@@ -128,188 +128,119 @@ inline LuaType luaG_type(lua_State* const L_, int const idx_) | |||
128 | return static_cast<LuaType>(lua_type(L_, idx_)); | 128 | return static_cast<LuaType>(lua_type(L_, idx_)); |
129 | } | 129 | } |
130 | 130 | ||
131 | // ------------------------------------------------------------------------------------------------- | 131 | // ################################################################################################# |
132 | // ################################################################################################# | ||
133 | // All the compatibility wrappers we expose start with luaG_ | ||
134 | // ################################################################################################# | ||
135 | // ################################################################################################# | ||
132 | 136 | ||
133 | // Default matches Lua 5.4 as of now | 137 | // use this in place of lua_absindex to save a function call |
134 | template <int VERSION, typename SPECIALIZE = void> | 138 | inline int luaG_absindex(lua_State* L_, int idx_) |
135 | struct Wrap | ||
136 | { | 139 | { |
137 | static inline int lua_dump(lua_State* const L_, lua_Writer const writer_, void* const data_, int const strip_) | 140 | return (((idx_) >= 0 || (idx_) <= LUA_REGISTRYINDEX) ? (idx_) : lua_gettop(L_) + (idx_) + 1); |
138 | { | 141 | } |
139 | return ::lua_dump(L_, writer_, data_, strip_); | ||
140 | } | ||
141 | 142 | ||
142 | static inline LuaType lua_getfield(lua_State* L_, int idx_, std::string_view const& k_) | 143 | // ################################################################################################# |
143 | { | ||
144 | // starting with Lua 5.3, lua_getfield returns the type of the pushed value | ||
145 | return static_cast<LuaType>(::lua_getfield(L_, idx_, k_.data())); | ||
146 | } | ||
147 | 144 | ||
148 | template <size_t N> | 145 | template <typename LUA_DUMP> |
149 | static inline void (luaL_newlib)(lua_State* const L_, luaL_Reg const (&funcs_)[N]) | 146 | concept RequiresOldLuaDump = requires(LUA_DUMP f_) { { f_(nullptr, nullptr, nullptr) } -> std::same_as<int>; }; |
150 | { | ||
151 | lua_createtable(L_, 0, N - 1); | ||
152 | ::luaL_setfuncs(L_, funcs_, 0); | ||
153 | } | ||
154 | 147 | ||
155 | static void luaL_setfuncs(lua_State* const L_, luaL_Reg const funcs_[], int nup_) | 148 | template <RequiresOldLuaDump LUA_DUMP> |
156 | { | 149 | static inline int WrapLuaDump(LUA_DUMP f_, lua_State* const L_, lua_Writer const writer_, void* const data_, [[maybe_unused]] int const strip_) |
157 | ::luaL_setfuncs(L_, funcs_, nup_); | 150 | { |
158 | } | 151 | return f_(L_, writer_, data_); |
152 | } | ||
159 | 153 | ||
160 | static void luaL_setmetatable(lua_State* const L_, std::string_view const& tname_) | 154 | // ------------------------------------------------------------------------------------------------- |
161 | { | ||
162 | ::luaL_setmetatable(L_, tname_.data()); | ||
163 | } | ||
164 | }; | ||
165 | 155 | ||
166 | // ################################################################################################# | 156 | template <typename LUA_DUMP> |
157 | concept RequiresNewLuaDump = requires(LUA_DUMP f_) { { f_(nullptr, nullptr, nullptr, 0) } -> std::same_as<int>; }; | ||
167 | 158 | ||
168 | template <int VERSION> | 159 | template <RequiresNewLuaDump LUA_DUMP> |
169 | struct Wrap<VERSION, typename std::enable_if_t<VERSION == 503>> | 160 | static inline int WrapLuaDump(LUA_DUMP f_, lua_State* const L_, lua_Writer const writer_, void* const data_, int const strip_) |
170 | { | 161 | { |
171 | static inline int lua_dump(lua_State* L_, lua_Writer writer_, void* data_, int strip_) | 162 | return f_(L_, writer_, data_, strip_); |
172 | { | 163 | } |
173 | return ::lua_dump(L_, writer_, data_, strip_); | ||
174 | } | ||
175 | 164 | ||
176 | static inline LuaType lua_getfield(lua_State* L_, int idx_, std::string_view const& k_) | 165 | // ------------------------------------------------------------------------------------------------- |
177 | { | ||
178 | // starting with Lua 5.3, lua_getfield returns the type of the pushed value | ||
179 | return static_cast<LuaType>(::lua_getfield(L_, idx_, k_.data())); | ||
180 | } | ||
181 | 166 | ||
182 | template <size_t N> | 167 | static inline int luaG_dump(lua_State* const L_, lua_Writer const writer_, void* const data_, int const strip_) |
183 | static inline void (luaL_newlib)(lua_State* const L_, luaL_Reg const (&funcs_)[N]) | 168 | { |
184 | { | 169 | return WrapLuaDump(lua_dump, L_, writer_, data_, strip_); |
185 | lua_createtable(L_, 0, N - 1); | 170 | } |
186 | ::luaL_setfuncs(L_, funcs_, 0); | ||
187 | } | ||
188 | 171 | ||
189 | static void luaL_setfuncs(lua_State* const L_, luaL_Reg const funcs_[], int const nup_) | 172 | // ################################################################################################# |
190 | { | ||
191 | ::luaL_setfuncs(L_, funcs_, nup_); | ||
192 | } | ||
193 | 173 | ||
194 | static void luaL_setmetatable(lua_State* const L_, std::string_view const& tname_) | 174 | int luaG_getalluservalues(lua_State* L_, int idx_); |
195 | { | ||
196 | ::luaL_setmetatable(L_, tname_.data()); | ||
197 | } | ||
198 | }; | ||
199 | 175 | ||
200 | // ################################################################################################# | 176 | // ################################################################################################# |
201 | 177 | ||
202 | template <int VERSION> | 178 | template <typename LUA_GETFIELD> |
203 | struct Wrap<VERSION, typename std::enable_if_t<VERSION == 502>> | 179 | concept RequiresOldLuaGetfield = requires(LUA_GETFIELD f_) |
204 | { | 180 | { |
205 | static inline int lua_dump(lua_State* const L_, lua_Writer const writer_, void* const data_, [[maybe_unused]] int const strip_) | ||
206 | { | 181 | { |
207 | return ::lua_dump(L_, writer_, data_); | 182 | f_(nullptr, 0, nullptr) |
208 | } | 183 | } -> std::same_as<void>; |
209 | |||
210 | static inline LuaType lua_getfield(lua_State* L_, int idx_, std::string_view const& k_) | ||
211 | { | ||
212 | // before Lua 5.3, lua_getfield returns nothing | ||
213 | ::lua_getfield(L_, idx_, k_.data()); | ||
214 | return luaG_type(L_, -1); | ||
215 | } | ||
216 | |||
217 | template <size_t N> | ||
218 | static inline void (luaL_newlib)(lua_State* const L_, luaL_Reg const (&funcs_)[N]) | ||
219 | { | ||
220 | ::lua_createtable(L_, 0, N - 1); | ||
221 | ::luaL_setfuncs(L_, funcs_, 0); | ||
222 | } | ||
223 | |||
224 | static void luaL_setfuncs(lua_State* const L_, luaL_Reg const funcs_[], int const nup_) | ||
225 | { | ||
226 | ::luaL_setfuncs(L_, funcs_, nup_); | ||
227 | } | ||
228 | |||
229 | static void luaL_setmetatable(lua_State* const L_, std::string_view const& tname_) | ||
230 | { | ||
231 | ::luaL_setmetatable(L_, tname_.data()); | ||
232 | } | ||
233 | }; | 184 | }; |
234 | 185 | ||
235 | // ################################################################################################# | 186 | template <RequiresOldLuaGetfield LUA_GETFIELD> |
236 | 187 | static inline int WrapLuaGetField(LUA_GETFIELD f_, lua_State* const L_, int const idx_, char const* const name_) | |
237 | template <int VERSION> | ||
238 | struct Wrap<VERSION, typename std::enable_if_t<VERSION == 501>> | ||
239 | { | 188 | { |
240 | static inline int lua_dump(lua_State* const L_, lua_Writer const writer_, void* const data_, [[maybe_unused]] int const strip_) | 189 | f_(L_, idx_, name_); |
241 | { | 190 | return lua_type(L_, -1); |
242 | return ::lua_dump(L_, writer_, data_); | 191 | } |
243 | } | ||
244 | |||
245 | static inline LuaType lua_getfield(lua_State* L_, int idx_, std::string_view const& k_) | ||
246 | { | ||
247 | // before Lua 5.3, lua_getfield returns nothing | ||
248 | ::lua_getfield(L_, idx_, k_.data()); | ||
249 | return luaG_type(L_, -1); | ||
250 | } | ||
251 | |||
252 | template<size_t N> | ||
253 | static inline void (luaL_newlib)(lua_State* const L_, luaL_Reg const (&funcs_)[N]) | ||
254 | { | ||
255 | lua_createtable(L_, 0, N - 1); | ||
256 | ::luaL_register(L_, nullptr, funcs_); | ||
257 | } | ||
258 | 192 | ||
259 | static void luaL_setfuncs(lua_State* const L_, luaL_Reg const funcs_[], [[maybe_unused]] int const nup_) | 193 | // ------------------------------------------------------------------------------------------------- |
260 | { | ||
261 | ::luaL_register(L_, nullptr, funcs_); | ||
262 | } | ||
263 | 194 | ||
264 | static void luaL_setmetatable(lua_State* const L_, std::string_view const& tname_) | 195 | template <typename LUA_GETFIELD> |
196 | concept RequiresNewLuaGetfield = requires(LUA_GETFIELD f_) | ||
197 | { | ||
265 | { | 198 | { |
266 | luaL_getmetatable(L_, tname_.data()); | 199 | f_(nullptr, 0, nullptr) |
267 | lua_setmetatable(L_, -2); | 200 | } -> std::same_as<int>; |
268 | } | ||
269 | }; | 201 | }; |
270 | 202 | ||
271 | // ################################################################################################# | 203 | template <RequiresNewLuaGetfield LUA_GETFIELD> |
272 | // All the compatibility wrappers we expose start with luaG_ | 204 | static inline int WrapLuaGetField(LUA_GETFIELD f_, lua_State* const L_, int const idx_, char const* const name_) |
273 | |||
274 | // ------------------------------------------------------------------------------------------------- | ||
275 | |||
276 | // use this in place of lua_absindex to save a function call | ||
277 | inline int luaG_absindex(lua_State* L_, int idx_) | ||
278 | { | 205 | { |
279 | return (((idx_) >= 0 || (idx_) <= LUA_REGISTRYINDEX) ? (idx_) : lua_gettop(L_) + (idx_) + 1); | 206 | return f_(L_, idx_, name_); |
280 | } | 207 | } |
281 | 208 | ||
282 | // ------------------------------------------------------------------------------------------------- | 209 | // ------------------------------------------------------------------------------------------------- |
283 | 210 | ||
284 | inline int luaG_dump(lua_State* L_, lua_Writer writer_, void* data_, int strip_) | 211 | static inline LuaType luaG_getfield(lua_State* const L_, int const idx_, std::string_view const& name_) |
285 | { | 212 | { |
286 | return Wrap<LUA_VERSION_NUM>::lua_dump(L_, writer_, data_, strip_); | 213 | return static_cast<LuaType>(WrapLuaGetField(lua_getfield, L_, idx_, name_.data())); |
287 | } | 214 | } |
288 | 215 | ||
289 | // ------------------------------------------------------------------------------------------------- | 216 | // ################################################################################################# |
290 | 217 | ||
291 | int luaG_getalluservalues(lua_State* L_, int idx_); | 218 | LuaType luaG_getmodule(lua_State* L_, std::string_view const& name_); |
292 | 219 | ||
293 | // ------------------------------------------------------------------------------------------------- | 220 | // ################################################################################################# |
294 | 221 | ||
295 | [[nodiscard]] inline LuaType luaG_getfield(lua_State* L_, int idx_, std::string_view const& k_) | 222 | inline void luaG_registerlibfuncs(lua_State* L_, luaL_Reg const* funcs_) |
296 | { | 223 | { |
297 | return Wrap<LUA_VERSION_NUM>::lua_getfield(L_, idx_, k_); | 224 | // fake externs to make clang happy... |
225 | extern void luaL_register(lua_State*, char const*, luaL_Reg const*); // Lua 5.1 | ||
226 | extern void luaL_setfuncs(lua_State* const L_, luaL_Reg const funcs_[], int nup_); // Lua 5.2+ | ||
227 | if constexpr (LUA_VERSION_NUM == 501) { | ||
228 | luaL_register(L_, nullptr, funcs_); | ||
229 | } else { | ||
230 | luaL_setfuncs(L_, funcs_, 0); | ||
231 | } | ||
298 | } | 232 | } |
299 | 233 | ||
300 | // ------------------------------------------------------------------------------------------------- | 234 | // ################################################################################################# |
301 | |||
302 | LuaType luaG_getmodule(lua_State* L_, std::string_view const& name_); | ||
303 | |||
304 | // ------------------------------------------------------------------------------------------------- | ||
305 | 235 | ||
306 | template<size_t N> | 236 | template <size_t N> |
307 | inline void luaG_newlib(lua_State* const L_, luaL_Reg const (&funcs_)[N]) | 237 | static inline void luaG_newlib(lua_State* const L_, luaL_Reg const (&funcs_)[N]) |
308 | { | 238 | { |
309 | (Wrap<LUA_VERSION_NUM>::luaL_newlib)(L_, funcs_); | 239 | lua_createtable(L_, 0, N - 1); |
240 | luaG_registerlibfuncs(L_, funcs_); | ||
310 | } | 241 | } |
311 | 242 | ||
312 | // ------------------------------------------------------------------------------------------------- | 243 | // ################################################################################################# |
313 | 244 | ||
314 | template <typename T> | 245 | template <typename T> |
315 | [[nodiscard]] T* luaG_newuserdatauv(lua_State* L_, int nuvalue_) | 246 | [[nodiscard]] T* luaG_newuserdatauv(lua_State* L_, int nuvalue_) |
@@ -317,7 +248,7 @@ template <typename T> | |||
317 | return static_cast<T*>(lua_newuserdatauv(L_, sizeof(T), nuvalue_)); | 248 | return static_cast<T*>(lua_newuserdatauv(L_, sizeof(T), nuvalue_)); |
318 | } | 249 | } |
319 | 250 | ||
320 | // ------------------------------------------------------------------------------------------------- | 251 | // ################################################################################################# |
321 | 252 | ||
322 | inline void luaG_pushglobaltable(lua_State* const L_) | 253 | inline void luaG_pushglobaltable(lua_State* const L_) |
323 | { | 254 | { |
@@ -328,21 +259,21 @@ inline void luaG_pushglobaltable(lua_State* const L_) | |||
328 | #endif // LUA_GLOBALSINDEX | 259 | #endif // LUA_GLOBALSINDEX |
329 | } | 260 | } |
330 | 261 | ||
331 | // ------------------------------------------------------------------------------------------------- | 262 | // ################################################################################################# |
332 | |||
333 | inline void luaG_registerlibfuncs(lua_State* L_, luaL_Reg const funcs_[]) | ||
334 | { | ||
335 | Wrap<LUA_VERSION_NUM>::luaL_setfuncs(L_, funcs_, 0); | ||
336 | } | ||
337 | |||
338 | // ------------------------------------------------------------------------------------------------- | ||
339 | 263 | ||
340 | inline void luaG_setmetatable(lua_State* const L_, std::string_view const& tname_) | 264 | inline void luaG_setmetatable(lua_State* const L_, std::string_view const& tname_) |
341 | { | 265 | { |
342 | return Wrap<LUA_VERSION_NUM>::luaL_setmetatable(L_, tname_); | 266 | // fake externs to make clang happy... |
267 | extern void luaL_setmetatable(lua_State* const L_, char const* const tname_); // Lua 5.2+ | ||
268 | if constexpr (LUA_VERSION_NUM == 501) { | ||
269 | luaL_setmetatable(L_, tname_.data()); | ||
270 | } else { | ||
271 | luaL_getmetatable(L_, tname_.data()); | ||
272 | lua_setmetatable(L_, -2); | ||
273 | } | ||
343 | } | 274 | } |
344 | 275 | ||
345 | // ------------------------------------------------------------------------------------------------- | 276 | // ################################################################################################# |
346 | 277 | ||
347 | // a small helper to extract a full userdata pointer from the stack in a safe way | 278 | // a small helper to extract a full userdata pointer from the stack in a safe way |
348 | template <typename T> | 279 | template <typename T> |
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 190e15e..1ccef80 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp | |||
@@ -183,7 +183,7 @@ void InterCopyContext::copyFunction() const | |||
183 | STACK_GROW(L1, 2); | 183 | STACK_GROW(L1, 2); |
184 | STACK_CHECK_START_REL(L1, 0); | 184 | STACK_CHECK_START_REL(L1, 0); |
185 | 185 | ||
186 | // 'lua_dump()' needs the function at top of stack | 186 | // 'luaG_dump()' needs the function at top of stack |
187 | // if already on top of the stack, no need to push again | 187 | // if already on top of the stack, no need to push again |
188 | bool const _needToPush{ L1_i != lua_gettop(L1) }; | 188 | bool const _needToPush{ L1_i != lua_gettop(L1) }; |
189 | if (_needToPush) { | 189 | if (_needToPush) { |
@@ -1136,7 +1136,6 @@ namespace { | |||
1136 | */ | 1136 | */ |
1137 | [[nodiscard]] InterCopyResult InterCopyContext::interCopyOne() const | 1137 | [[nodiscard]] InterCopyResult InterCopyContext::interCopyOne() const |
1138 | { | 1138 | { |
1139 | static constexpr int kPODmask = (1 << LUA_TNIL) | (1 << LUA_TBOOLEAN) | (1 << LUA_TLIGHTUSERDATA) | (1 << LUA_TNUMBER) | (1 << LUA_TSTRING); | ||
1140 | STACK_GROW(L2, 1); | 1139 | STACK_GROW(L2, 1); |
1141 | STACK_CHECK_START_REL(L1, 0); | 1140 | STACK_CHECK_START_REL(L1, 0); |
1142 | STACK_CHECK_START_REL(L2, 0); | 1141 | STACK_CHECK_START_REL(L2, 0); |
diff --git a/src/keeper.h b/src/keeper.h index 1ad84d7..1a194e8 100644 --- a/src/keeper.h +++ b/src/keeper.h | |||
@@ -44,7 +44,7 @@ struct Keepers | |||
44 | // can't use std::vector<Keeper> because Keeper contains a mutex, so we need a raw memory buffer | 44 | // can't use std::vector<Keeper> because Keeper contains a mutex, so we need a raw memory buffer |
45 | struct KV | 45 | struct KV |
46 | { | 46 | { |
47 | std::unique_ptr<Keeper[], DeleteKV> keepers{}; | 47 | std::unique_ptr<Keeper[], DeleteKV> keepers; |
48 | size_t nbKeepers{}; | 48 | size_t nbKeepers{}; |
49 | }; | 49 | }; |
50 | std::variant<std::monostate, Keeper, KV> keeper_array; | 50 | std::variant<std::monostate, Keeper, KV> keeper_array; |
diff --git a/src/lane.cpp b/src/lane.cpp index c2cbbac..8f31973 100644 --- a/src/lane.cpp +++ b/src/lane.cpp | |||
@@ -677,7 +677,7 @@ static void lane_main(Lane* const lane_) | |||
677 | #ifndef __PROSPERO__ | 677 | #ifndef __PROSPERO__ |
678 | lane_->ready.wait(); | 678 | lane_->ready.wait(); |
679 | #else // __PROSPERO__ | 679 | #else // __PROSPERO__ |
680 | while (!lane_->ready._My_flag) { | 680 | while (!lane_->ready.test()) { |
681 | std::this_thread::yield(); | 681 | std::this_thread::yield(); |
682 | } | 682 | } |
683 | #endif // __PROSPERO__ | 683 | #endif // __PROSPERO__ |
@@ -719,7 +719,8 @@ static void lane_main(Lane* const lane_) | |||
719 | lane_->U->selfdestructingCount.fetch_sub(1, std::memory_order_release); | 719 | lane_->U->selfdestructingCount.fetch_sub(1, std::memory_order_release); |
720 | lane_->U->selfdestructMutex.unlock(); | 720 | lane_->U->selfdestructMutex.unlock(); |
721 | 721 | ||
722 | // we destroy our jthread member from inside the thread body, so we have to detach so that we don't try to join, as this doesn't seem a good idea | 722 | // we destroy ourselves, therefore our thread member too, from inside the thread body |
723 | // detach so that we don't try to join, as this doesn't seem a good idea | ||
723 | lane_->thread.detach(); | 724 | lane_->thread.detach(); |
724 | delete lane_; | 725 | delete lane_; |
725 | return; | 726 | return; |
@@ -828,6 +829,11 @@ Lane::Lane(Universe* U_, lua_State* L_, ErrorTraceLevel errorTraceLevel_) | |||
828 | 829 | ||
829 | Lane::~Lane() | 830 | Lane::~Lane() |
830 | { | 831 | { |
832 | // not necessary when using a jthread | ||
833 | if (thread.joinable()) { | ||
834 | thread.join(); | ||
835 | } | ||
836 | // no longer tracked | ||
831 | std::ignore = U->tracker.tracking_remove(this); | 837 | std::ignore = U->tracker.tracking_remove(this); |
832 | } | 838 | } |
833 | 839 | ||
@@ -1032,9 +1038,9 @@ void Lane::securizeDebugName(lua_State* L_) | |||
1032 | 1038 | ||
1033 | void Lane::startThread(int priority_) | 1039 | void Lane::startThread(int priority_) |
1034 | { | 1040 | { |
1035 | thread = std::jthread([this]() { lane_main(this); }); | 1041 | thread = std::thread([this]() { lane_main(this); }); |
1036 | if (priority_ != kThreadPrioDefault) { | 1042 | if (priority_ != kThreadPrioDefault) { |
1037 | JTHREAD_SET_PRIORITY(thread, priority_, U->sudo); | 1043 | THREAD_SET_PRIORITY(thread, priority_, U->sudo); |
1038 | } | 1044 | } |
1039 | } | 1045 | } |
1040 | 1046 | ||
@@ -68,7 +68,7 @@ class Lane | |||
68 | using enum ErrorTraceLevel; | 68 | using enum ErrorTraceLevel; |
69 | 69 | ||
70 | // the thread | 70 | // the thread |
71 | std::jthread thread; | 71 | std::thread thread; // use jthread if we ever need a stop_source |
72 | #ifndef __PROSPERO__ | 72 | #ifndef __PROSPERO__ |
73 | // a latch to wait for the lua_State to be ready | 73 | // a latch to wait for the lua_State to be ready |
74 | std::latch ready{ 1 }; | 74 | std::latch ready{ 1 }; |
diff --git a/src/threading.cpp b/src/threading.cpp index ebac0da..af2142b 100644 --- a/src/threading.cpp +++ b/src/threading.cpp | |||
@@ -131,11 +131,11 @@ void THREAD_SET_PRIORITY(int prio_, [[maybe_unused]] bool sudo_) | |||
131 | 131 | ||
132 | // ################################################################################################# | 132 | // ################################################################################################# |
133 | 133 | ||
134 | void JTHREAD_SET_PRIORITY(std::jthread& thread_, int prio_, [[maybe_unused]] bool sudo_) | 134 | void THREAD_SET_PRIORITY(std::thread& thread_, int prio_, [[maybe_unused]] bool sudo_) |
135 | { | 135 | { |
136 | // prio range [-3,+3] was checked by the caller | 136 | // prio range [-3,+3] was checked by the caller |
137 | if (!SetThreadPriority(thread_.native_handle(), gs_prio_remap[prio_ + 3])) { | 137 | if (!SetThreadPriority(thread_.native_handle(), gs_prio_remap[prio_ + 3])) { |
138 | FAIL("JTHREAD_SET_PRIORITY", GetLastError()); | 138 | FAIL("THREAD_SET_PRIORITY", GetLastError()); |
139 | } | 139 | } |
140 | } | 140 | } |
141 | 141 | ||
@@ -349,14 +349,6 @@ static int const gs_prio_remap[] = { | |||
349 | #endif // _PRIO_0 | 349 | #endif // _PRIO_0 |
350 | }; | 350 | }; |
351 | 351 | ||
352 | [[nodiscard]] static int select_prio(int prio /* -3..+3 */) | ||
353 | { | ||
354 | if (prio == kThreadPrioDefault) | ||
355 | prio = 0; | ||
356 | // prio range [-3,+3] was checked by the caller | ||
357 | return gs_prio_remap[prio + 3]; | ||
358 | } | ||
359 | |||
360 | void THREAD_SET_PRIORITY(int prio_, [[maybe_unused]] bool sudo_) | 352 | void THREAD_SET_PRIORITY(int prio_, [[maybe_unused]] bool sudo_) |
361 | { | 353 | { |
362 | #ifdef PLATFORM_LINUX | 354 | #ifdef PLATFORM_LINUX |
@@ -372,7 +364,7 @@ void THREAD_SET_PRIORITY(int prio_, [[maybe_unused]] bool sudo_) | |||
372 | 364 | ||
373 | // ################################################################################################# | 365 | // ################################################################################################# |
374 | 366 | ||
375 | void JTHREAD_SET_PRIORITY(std::jthread& thread_, int prio_, [[maybe_unused]] bool sudo_) | 367 | void THREAD_SET_PRIORITY(std::thread& thread_, int prio_, [[maybe_unused]] bool sudo_) |
376 | { | 368 | { |
377 | #ifdef PLATFORM_LINUX | 369 | #ifdef PLATFORM_LINUX |
378 | if (!sudo_) // only root-privileged process can change priorities | 370 | if (!sudo_) // only root-privileged process can change priorities |
@@ -387,6 +379,15 @@ void JTHREAD_SET_PRIORITY(std::jthread& thread_, int prio_, [[maybe_unused]] boo | |||
387 | 379 | ||
388 | // ################################################################################################# | 380 | // ################################################################################################# |
389 | 381 | ||
382 | #ifdef __PROSPERO__ | ||
383 | |||
384 | void THREAD_SET_AFFINITY(unsigned int aff_) | ||
385 | { | ||
386 | scePthreadSetaffinity(scePthreadSelf(), aff_); | ||
387 | } | ||
388 | |||
389 | #else // __PROSPERO__ | ||
390 | |||
390 | void THREAD_SET_AFFINITY(unsigned int aff_) | 391 | void THREAD_SET_AFFINITY(unsigned int aff_) |
391 | { | 392 | { |
392 | int bit = 0; | 393 | int bit = 0; |
@@ -416,8 +417,19 @@ void THREAD_SET_AFFINITY(unsigned int aff_) | |||
416 | #endif | 417 | #endif |
417 | } | 418 | } |
418 | 419 | ||
420 | #endif // __PROSPERO__ | ||
421 | |||
419 | // ################################################################################################# | 422 | // ################################################################################################# |
420 | 423 | ||
424 | #ifdef __PROSPERO__ | ||
425 | |||
426 | void THREAD_SETNAME(std::string_view const& name_) | ||
427 | { | ||
428 | scePthreadRename(scePthreadSelf(), name_.data()); | ||
429 | } | ||
430 | |||
431 | #else // __PROSPERO__ | ||
432 | |||
421 | void THREAD_SETNAME(std::string_view const& name_) | 433 | void THREAD_SETNAME(std::string_view const& name_) |
422 | { | 434 | { |
423 | // exact API to set the thread name is platform-dependant | 435 | // exact API to set the thread name is platform-dependant |
@@ -442,6 +454,8 @@ void THREAD_SETNAME(std::string_view const& name_) | |||
442 | #endif | 454 | #endif |
443 | } | 455 | } |
444 | 456 | ||
457 | #endif // __PROSPERO__ | ||
458 | |||
445 | #endif // THREADAPI == THREADAPI_PTHREAD | 459 | #endif // THREADAPI == THREADAPI_PTHREAD |
446 | // ################################################################################################# | 460 | // ################################################################################################# |
447 | // ################################################################################################# | 461 | // ################################################################################################# |
diff --git a/src/threading.h b/src/threading.h index f0d1592..044b5a4 100644 --- a/src/threading.h +++ b/src/threading.h | |||
@@ -70,4 +70,4 @@ void THREAD_SETNAME(std::string_view const& name_); | |||
70 | void THREAD_SET_PRIORITY(int prio_, bool sudo_); | 70 | void THREAD_SET_PRIORITY(int prio_, bool sudo_); |
71 | void THREAD_SET_AFFINITY(unsigned int aff_); | 71 | void THREAD_SET_AFFINITY(unsigned int aff_); |
72 | 72 | ||
73 | void JTHREAD_SET_PRIORITY(std::jthread& thread_, int prio_, bool sudo_); | 73 | void THREAD_SET_PRIORITY(std::thread& thread_, int prio_, bool sudo_); |
diff --git a/src/tools.cpp b/src/tools.cpp index 49872f7..3a331f5 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
@@ -61,7 +61,7 @@ static constexpr int kWriterReturnCode{ 666 }; | |||
61 | * +-----------------+-------------------+------------+----------+ | 61 | * +-----------------+-------------------+------------+----------+ |
62 | * | lua_tocfunction | nullptr | | nullptr | | 62 | * | lua_tocfunction | nullptr | | nullptr | |
63 | * +-----------------+-------------------+------------+----------+ | 63 | * +-----------------+-------------------+------------+----------+ |
64 | * | lua_dump | kWriterReturnCode | 1 | 1 | | 64 | * | luaG_dump | kWriterReturnCode | 1 | 1 | |
65 | * +-----------------+-------------------+------------+----------+ | 65 | * +-----------------+-------------------+------------+----------+ |
66 | */ | 66 | */ |
67 | 67 | ||
@@ -77,7 +77,7 @@ static constexpr int kWriterReturnCode{ 666 }; | |||
77 | _mustpush = 1; | 77 | _mustpush = 1; |
78 | } | 78 | } |
79 | // the provided writer fails with code kWriterReturnCode | 79 | // the provided writer fails with code kWriterReturnCode |
80 | // therefore, anytime we get kWriterReturnCode, this means that lua_dump() attempted a dump | 80 | // therefore, anytime we get kWriterReturnCode, this means that luaG_dump() attempted a dump |
81 | // all other cases mean this is either a C or LuaJIT-fast function | 81 | // all other cases mean this is either a C or LuaJIT-fast function |
82 | int const _dumpres{ luaG_dump(L_, dummy_writer, nullptr, 0) }; | 82 | int const _dumpres{ luaG_dump(L_, dummy_writer, nullptr, 0) }; |
83 | lua_pop(L_, _mustpush); | 83 | lua_pop(L_, _mustpush); |