From 2c05c49a04aa838047417825c289958efb59ee3c Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Thu, 27 Jan 2011 20:47:58 +0000 Subject: Replaced Common::Thread with a partial implementation of std::thread. (rvalue references are used if available, is used if possible) Eliminates the need to use dynamic memory allocation for threads, so it's impossible to forget to delete a thread or set a pointer to NULL. Enables use of type-safe thread functions, no need to cast to and from void*. I've made sure the code compiles in vs08 and tested the functionality of "StdThread.h" on Linux so I'm hoping everything will work :p. In the future "StdThread.h" can be removed (maybe when OS X ships with gcc 4.4 and vs2015 is released :p). git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6933 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/InputCommon/Src/UDPWiimote.cpp | 19 ++++++------------- Source/Core/InputCommon/Src/UDPWiimote.h | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-) (limited to 'Source/Core/InputCommon') diff --git a/Source/Core/InputCommon/Src/UDPWiimote.cpp b/Source/Core/InputCommon/Src/UDPWiimote.cpp index 6fde1732d9..558e4d902d 100644 --- a/Source/Core/InputCommon/Src/UDPWiimote.cpp +++ b/Source/Core/InputCommon/Src/UDPWiimote.cpp @@ -47,7 +47,7 @@ struct UDPWiimote::_d { - Common::Thread * thread; + std::thread thread; std::list sockfds; Common::CriticalSection termLock,mutex,nameMutex; volatile bool exit; @@ -56,15 +56,9 @@ struct UDPWiimote::_d int UDPWiimote::noinst=0; -void _UDPWiiThread(void* arg) +void UDPWiiThread(UDPWiimote* arg) { - ((UDPWiimote*)arg)->mainThread(); -} - -THREAD_RETURN UDPWiiThread(void* arg) -{ - _UDPWiiThread(arg); - return 0; + arg->mainThread(); } UDPWiimote::UDPWiimote(const char *_port, const char * name, int _index) : @@ -86,7 +80,6 @@ UDPWiimote::UDPWiimote(const char *_port, const char * name, int _index) : #endif struct addrinfo hints, *servinfo, *p; int rv; - d->thread=NULL; #ifdef _WIN32 if (noinst==0) @@ -142,7 +135,7 @@ UDPWiimote::UDPWiimote(const char *_port, const char * name, int _index) : initBroadcastIPv4(); initBroadcastIPv6(); d->termLock.Enter(); - d->thread = new Common::Thread(UDPWiiThread,this); + d->thread = std::thread(UDPWiiThread, this); d->termLock.Leave(); return; } @@ -226,8 +219,8 @@ void UDPWiimote::mainThread() UDPWiimote::~UDPWiimote() { - d->exit=true; - d->thread->WaitForDeath(); + d->exit = true; + d->thread.join(); d->termLock.Enter(); d->termLock.Leave(); for (std::list::iterator i=d->sockfds.begin(); i!=d->sockfds.end(); i++) diff --git a/Source/Core/InputCommon/Src/UDPWiimote.h b/Source/Core/InputCommon/Src/UDPWiimote.h index c1c39b2887..02fa4f66bc 100644 --- a/Source/Core/InputCommon/Src/UDPWiimote.h +++ b/Source/Core/InputCommon/Src/UDPWiimote.h @@ -21,6 +21,7 @@ class UDPWiimote { + friend void UDPWiiThread(UDPWiimote* arg); public: UDPWiimote(const char * port, const char * name, int index); virtual ~UDPWiimote(); @@ -49,7 +50,6 @@ private: int index; int int_port; static int noinst; - friend void _UDPWiiThread(void* arg); void broadcastPresence(); void broadcastIPv4(const void * data, size_t size); void broadcastIPv6(const void * data, size_t size); -- cgit v1.2.3