Change thread creation type to std::function to allow lambdas

This commit is contained in:
baldurk
2017-09-04 11:14:51 +01:00
parent f529c9a393
commit d3d35ee216
10 changed files with 32 additions and 45 deletions
+1 -1
View File
@@ -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);
}
+2 -2
View File
@@ -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;
};
+9 -12
View File
@@ -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);
+3 -7
View File
@@ -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
+2 -2
View File
@@ -34,6 +34,7 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <functional>
#include <map>
#include <string>
#include <vector>
@@ -115,9 +116,8 @@ void SetTLSValue(uint64_t slot, void *value);
// must typedef CriticalSectionTemplate<X> CriticalSection
typedef void (*ThreadEntry)(void *);
typedef uint64_t ThreadHandle;
ThreadHandle CreateThread(ThreadEntry entryFunc, void *userData);
ThreadHandle CreateThread(std::function<void()> entryFunc);
uint64_t GetCurrentID();
void JoinThread(ThreadHandle handle);
void CloseThread(ThreadHandle handle);
+3 -5
View File
@@ -103,8 +103,7 @@ void CriticalSection::Unlock()
struct ThreadInitData
{
ThreadEntry entryFunc;
void *userData;
std::function<void()> 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<void()> 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)
+2 -2
View File
@@ -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;
}
+3 -5
View File
@@ -108,8 +108,7 @@ void CriticalSection::Unlock()
struct ThreadInitData
{
ThreadEntry entryFunc;
void *userData;
std::function<void()> 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<void()> entryFunc)
{
ThreadInitData *initData = new ThreadInitData;
initData->entryFunc = entryFunc;
initData->userData = userData;
HANDLE h = ::CreateThread(NULL, 0, &sThreadInit, (void *)initData, 0, NULL);
+6 -8
View File
@@ -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()
+1 -1
View File
@@ -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();