mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 16:47:37 +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:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user