Skip to content

Commit

Permalink
Refactor NativeThread start_routine
Browse files Browse the repository at this point in the history
Removes the free function and fixes the formatting for the function
call.

closes #4995

No functional change
  • Loading branch information
Disservin committed Jan 21, 2024
1 parent c8bc2ce commit 856e60d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/thread_win32_osx.h
Expand Up @@ -34,14 +34,6 @@

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 {
pthread_t thread;

Expand All @@ -56,6 +48,15 @@ class NativeThread {
pthread_attr_t attr_storage, *attr = &attr_storage;
pthread_attr_init(attr);
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);
}

Expand Down

0 comments on commit 856e60d

Please sign in to comment.