From 856e60d12f11cd250cf00cdd336ed87c25bd0677 Mon Sep 17 00:00:00 2001 From: Disservin Date: Wed, 17 Jan 2024 22:58:46 +0100 Subject: [PATCH] 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 --- src/thread_win32_osx.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/thread_win32_osx.h b/src/thread_win32_osx.h index 8d424b72..1d9a834f 100644 --- a/src/thread_win32_osx.h +++ b/src/thread_win32_osx.h @@ -34,14 +34,6 @@ namespace Stockfish { -// free function to be passed to pthread_create() -inline void* start_routine(void* ptr) { - auto func = reinterpret_cast*>(ptr); - (*func)(); // Call the function - delete func; - return nullptr; -} - class NativeThread { pthread_t thread; @@ -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*>(ptr); + // Call the function + (*f)(); + delete f; + return nullptr; + }; + pthread_create(&thread, attr, start_routine, func); }