mirror of
https://github.com/sockspls/badfish
synced 2025-06-28 00:19:50 +00:00
Refactor NativeThread start_routine
Removes the free function and fixes the formatting for the function call. closes https://github.com/official-stockfish/Stockfish/pull/4995 No functional change
This commit is contained in:
parent
c8bc2ce4fa
commit
856e60d12f
1 changed files with 9 additions and 8 deletions
|
@ -34,14 +34,6 @@
|
||||||
|
|
||||||
namespace Stockfish {
|
namespace Stockfish {
|
||||||
|
|
||||||
// free function to be passed to pthread_create()
|
|
||||||
inline void* start_routine(void* ptr) {
|
|
||||||
auto func = reinterpret_cast<std::function<void()>*>(ptr);
|
|
||||||
(*func)(); // Call the function
|
|
||||||
delete func;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
class NativeThread {
|
class NativeThread {
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
|
|
||||||
|
@ -56,6 +48,15 @@ class NativeThread {
|
||||||
pthread_attr_t attr_storage, *attr = &attr_storage;
|
pthread_attr_t attr_storage, *attr = &attr_storage;
|
||||||
pthread_attr_init(attr);
|
pthread_attr_init(attr);
|
||||||
pthread_attr_setstacksize(attr, TH_STACK_SIZE);
|
pthread_attr_setstacksize(attr, TH_STACK_SIZE);
|
||||||
|
|
||||||
|
auto start_routine = [](void* ptr) -> void* {
|
||||||
|
auto f = reinterpret_cast<std::function<void()>*>(ptr);
|
||||||
|
// Call the function
|
||||||
|
(*f)();
|
||||||
|
delete f;
|
||||||
|
return nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
pthread_create(&thread, attr, start_routine, func);
|
pthread_create(&thread, attr, start_routine, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue