diff --git a/renderdoc/core/core.cpp b/renderdoc/core/core.cpp index cf2a6712d..1a5fdf6a8 100644 --- a/renderdoc/core/core.cpp +++ b/renderdoc/core/core.cpp @@ -285,7 +285,7 @@ void RenderDoc::Initialise() m_RemoteIdent = port; m_TargetControlThreadShutdown = false; - m_RemoteThread = Threading::CreateThread(TargetControlServerThread, (void *)sock); + m_RemoteThread = Threading::CreateThread([sock]() { TargetControlServerThread(sock); }); RDCLOG("Listening for target control on %u", port); } diff --git a/renderdoc/core/core.h b/renderdoc/core/core.h index 82966f08a..756f03caf 100644 --- a/renderdoc/core/core.h +++ b/renderdoc/core/core.h @@ -450,8 +450,8 @@ private: Threading::CriticalSection m_SingleClientLock; string m_SingleClientName; - static void TargetControlServerThread(void *s); - static void TargetControlClientThread(void *s); + static void TargetControlServerThread(Network::Socket *sock); + static void TargetControlClientThread(Network::Socket *client); ICrashHandler *m_ExHandler; }; diff --git a/renderdoc/core/remote_server.cpp b/renderdoc/core/remote_server.cpp index 3bd4445c2..00f92bb7b 100644 --- a/renderdoc/core/remote_server.cpp +++ b/renderdoc/core/remote_server.cpp @@ -118,10 +118,8 @@ struct ProgressLoopData bool killsignal; }; -static void ProgressTicker(void *d) +static void ProgressTicker(ProgressLoopData *data) { - ProgressLoopData *data = (ProgressLoopData *)d; - Serialiser ser("", Serialiser::WRITING, false); while(!data->killsignal) @@ -154,10 +152,8 @@ struct ClientThread Threading::ThreadHandle thread; }; -static void InactiveRemoteClientThread(void *data) +static void InactiveRemoteClientThread(ClientThread *threadData) { - ClientThread *threadData = (ClientThread *)data; - uint32_t ip = threadData->socket->GetRemoteIP(); // this thread just handles receiving the handshake and sending a busy signal without blocking the @@ -194,10 +190,8 @@ static void InactiveRemoteClientThread(void *data) Network::GetIPOctet(ip, 1), Network::GetIPOctet(ip, 2), Network::GetIPOctet(ip, 3)); } -static void ActiveRemoteClientThread(void *data) +static void ActiveRemoteClientThread(ClientThread *threadData) { - ClientThread *threadData = (ClientThread *)data; - Network::Socket *&client = threadData->socket; uint32_t ip = client->GetRemoteIP(); @@ -390,7 +384,8 @@ static void ActiveRemoteClientThread(void *data) RenderDoc::Inst().SetProgressPtr(&progressData.progress); - Threading::ThreadHandle ticker = Threading::CreateThread(ProgressTicker, &progressData); + Threading::ThreadHandle ticker = + Threading::CreateThread([&progressData]() { ProgressTicker(&progressData); }); status = RenderDoc::Inst().CreateRemoteDriver(driverType, cap_file.c_str(), &driver); @@ -665,7 +660,8 @@ void RenderDoc::BecomeRemoteServer(const char *listenhost, uint16_t port, volati activeClientData->socket = client; activeClientData->allowExecution = allowExecution; - activeClientData->thread = Threading::CreateThread(ActiveRemoteClientThread, activeClientData); + activeClientData->thread = Threading::CreateThread( + [activeClientData]() { ActiveRemoteClientThread(activeClientData); }); RDCLOG("Making active connection"); } @@ -675,7 +671,8 @@ void RenderDoc::BecomeRemoteServer(const char *listenhost, uint16_t port, volati inactive->socket = client; inactive->allowExecution = false; - inactive->thread = Threading::CreateThread(InactiveRemoteClientThread, inactive); + inactive->thread = + Threading::CreateThread([inactive]() { InactiveRemoteClientThread(inactive); }); inactives.push_back(inactive); diff --git a/renderdoc/core/target_control.cpp b/renderdoc/core/target_control.cpp index 30b264017..19caaf60f 100644 --- a/renderdoc/core/target_control.cpp +++ b/renderdoc/core/target_control.cpp @@ -46,12 +46,10 @@ enum PacketType ePacket_NewChild, }; -void RenderDoc::TargetControlClientThread(void *s) +void RenderDoc::TargetControlClientThread(Network::Socket *client) { Threading::KeepModuleAlive(); - Network::Socket *client = (Network::Socket *)s; - Serialiser ser("", Serialiser::WRITING, false); string api = ""; @@ -244,12 +242,10 @@ void RenderDoc::TargetControlClientThread(void *s) Threading::ReleaseModuleExitThread(); } -void RenderDoc::TargetControlServerThread(void *s) +void RenderDoc::TargetControlServerThread(Network::Socket *sock) { Threading::KeepModuleAlive(); - Network::Socket *sock = (Network::Socket *)s; - RenderDoc::Inst().m_SingleClientName = ""; Threading::ThreadHandle clientThread = 0; @@ -336,7 +332,7 @@ void RenderDoc::TargetControlServerThread(void *s) // if we've claimed client status, spawn a thread to communicate if(existingClient.empty() || kick) { - clientThread = Threading::CreateThread(TargetControlClientThread, client); + clientThread = Threading::CreateThread([client] { TargetControlClientThread(client); }); continue; } else diff --git a/renderdoc/os/os_specific.h b/renderdoc/os/os_specific.h index a76dec80e..11143e603 100644 --- a/renderdoc/os/os_specific.h +++ b/renderdoc/os/os_specific.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -115,9 +116,8 @@ void SetTLSValue(uint64_t slot, void *value); // must typedef CriticalSectionTemplate CriticalSection -typedef void (*ThreadEntry)(void *); typedef uint64_t ThreadHandle; -ThreadHandle CreateThread(ThreadEntry entryFunc, void *userData); +ThreadHandle CreateThread(std::function entryFunc); uint64_t GetCurrentID(); void JoinThread(ThreadHandle handle); void CloseThread(ThreadHandle handle); diff --git a/renderdoc/os/posix/posix_threading.cpp b/renderdoc/os/posix/posix_threading.cpp index dbfa9ea4e..3c3a09a3d 100644 --- a/renderdoc/os/posix/posix_threading.cpp +++ b/renderdoc/os/posix/posix_threading.cpp @@ -103,8 +103,7 @@ void CriticalSection::Unlock() struct ThreadInitData { - ThreadEntry entryFunc; - void *userData; + std::function entryFunc; }; static void *sThreadInit(void *init) @@ -115,7 +114,7 @@ static void *sThreadInit(void *init) ThreadInitData local = *data; delete data; - local.entryFunc(local.userData); + local.entryFunc(); return NULL; } @@ -202,13 +201,12 @@ void SetTLSValue(uint64_t slot, void *value) slots->data[(size_t)slot - 1] = value; } -ThreadHandle CreateThread(ThreadEntry entryFunc, void *userData) +ThreadHandle CreateThread(std::function entryFunc) { pthread_t thread; ThreadInitData *initData = new ThreadInitData(); initData->entryFunc = entryFunc; - initData->userData = userData; int res = pthread_create(&thread, NULL, sThreadInit, (void *)initData); if(res != 0) diff --git a/renderdoc/os/win32/win32_process.cpp b/renderdoc/os/win32/win32_process.cpp index be1f25dcb..a00c09e0d 100644 --- a/renderdoc/os/win32/win32_process.cpp +++ b/renderdoc/os/win32/win32_process.cpp @@ -1269,7 +1269,7 @@ static GlobalHookData *globalHook = NULL; // a thread we run in the background just to keep the pipes open and wait until we're ready to stop // the global hook. -static void GlobalHookThread(void *) +static void GlobalHookThread() { // keep looping doing an atomic compare-exchange to check that finished is still 0 while(Atomic::CmpExch32(&globalHook->finished, 0, 0) == 0) @@ -1535,7 +1535,7 @@ bool Process::StartGlobalHook(const char *pathmatch, const char *logfile, const globalHook = new GlobalHookData; *globalHook = hookdata; - globalHook->pipeThread = Threading::CreateThread(&GlobalHookThread, NULL); + globalHook->pipeThread = Threading::CreateThread(&GlobalHookThread); return true; } diff --git a/renderdoc/os/win32/win32_threading.cpp b/renderdoc/os/win32/win32_threading.cpp index 67aa5c365..33ea1e143 100644 --- a/renderdoc/os/win32/win32_threading.cpp +++ b/renderdoc/os/win32/win32_threading.cpp @@ -108,8 +108,7 @@ void CriticalSection::Unlock() struct ThreadInitData { - ThreadEntry entryFunc; - void *userData; + std::function entryFunc; }; static DWORD __stdcall sThreadInit(void *init) @@ -120,7 +119,7 @@ static DWORD __stdcall sThreadInit(void *init) ThreadInitData local = *data; delete data; - local.entryFunc(local.userData); + local.entryFunc(); return 0; } @@ -205,11 +204,10 @@ void SetTLSValue(uint64_t slot, void *value) slots->data[(size_t)slot - 1] = value; } -ThreadHandle CreateThread(ThreadEntry entryFunc, void *userData) +ThreadHandle CreateThread(std::function entryFunc) { ThreadInitData *initData = new ThreadInitData; initData->entryFunc = entryFunc; - initData->userData = userData; HANDLE h = ::CreateThread(NULL, 0, &sThreadInit, (void *)initData, 0, NULL); diff --git a/renderdoc/serialise/serialiser.cpp b/renderdoc/serialise/serialiser.cpp index 12aeca111..9a9a180f8 100644 --- a/renderdoc/serialise/serialiser.cpp +++ b/renderdoc/serialise/serialiser.cpp @@ -1297,7 +1297,7 @@ void Serialiser::InitCallstackResolver() m_KnownSections[eSectionType_ResolveDatabase] != NULL) { m_ResolverThreadKillSignal = false; - m_ResolverThread = Threading::CreateThread(&Serialiser::CreateResolver, (void *)this); + m_ResolverThread = Threading::CreateThread([this]() { CreateResolver(); }); } } @@ -1309,17 +1309,15 @@ void Serialiser::SetCallstack(uint64_t *levels, size_t numLevels) m_pCallstack->Set(levels, numLevels); } -void Serialiser::CreateResolver(void *ths) +void Serialiser::CreateResolver() { - Serialiser *ser = (Serialiser *)ths; + string dir = dirname(m_Filename); - string dir = dirname(ser->m_Filename); - - Section *s = ser->m_KnownSections[Serialiser::eSectionType_ResolveDatabase]; + Section *s = m_KnownSections[Serialiser::eSectionType_ResolveDatabase]; RDCASSERT(s); - ser->m_pResolver = Callstack::MakeResolver((char *)&s->data[0], s->data.size(), dir, - &ser->m_ResolverThreadKillSignal); + m_pResolver = + Callstack::MakeResolver((char *)&s->data[0], s->data.size(), dir, &m_ResolverThreadKillSignal); } void Serialiser::FlushToDisk() diff --git a/renderdoc/serialise/serialiser.h b/renderdoc/serialise/serialiser.h index 541a8dd3e..b1a135755 100644 --- a/renderdoc/serialise/serialiser.h +++ b/renderdoc/serialise/serialiser.h @@ -614,7 +614,7 @@ private: // no copies Serialiser(const Serialiser &other); - static void CreateResolver(void *ths); + void CreateResolver(); // clean out for before constructor and after destructor (and other times probably) void Reset();