Use _beginthreadex

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3736 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Nolan Check 2009-07-10 20:22:25 +00:00
parent 112b742d31
commit 6800adf4dc
4 changed files with 51 additions and 21 deletions

View File

@ -94,7 +94,7 @@ bool DSound::WriteDataToBuffer(DWORD dwOffset, // Our own write
} }
// The audio thread. // The audio thread.
DWORD WINAPI soundThread(void* args) THREAD_RETURN soundThread(void* args)
{ {
(reinterpret_cast<DSound *>(args))->SoundLoop(); (reinterpret_cast<DSound *>(args))->SoundLoop();
return 0; return 0;

View File

@ -18,6 +18,11 @@
#include "Setup.h" #include "Setup.h"
#include "Thread.h" #include "Thread.h"
#include "Log.h" #include "Log.h"
#ifdef USE_BEGINTHREADEX
#include <process.h>
#endif
#ifdef SETUP_TIMER_WAITING #ifdef SETUP_TIMER_WAITING
#include <windows.h> #include <windows.h>
#include "ConsoleWindow.h" #include "ConsoleWindow.h"
@ -68,13 +73,11 @@ void CriticalSection::Leave()
Thread::Thread(ThreadFunc function, void* arg) Thread::Thread(ThreadFunc function, void* arg)
: m_hThread(NULL), m_threadId(0) : m_hThread(NULL), m_threadId(0)
{ {
m_hThread = CreateThread( #ifdef USE_BEGINTHREADEX
0, // Security attributes m_hThread = (HANDLE)_beginthreadex(NULL, 0, function, arg, 0, &m_threadId);
0, // Stack size #else
function, m_hThread = CreateThread(NULL, 0, function, arg, 0, &m_threadId);
arg, #endif
0,
&m_threadId);
} }
Thread::~Thread() Thread::~Thread()

View File

@ -19,9 +19,23 @@
#define _THREAD_H_ #define _THREAD_H_
#ifdef _WIN32 #ifdef _WIN32
#if defined(_MSC_VER) && defined(_MT)
// When linking with LIBCMT (the multithreaded C library), Microsoft recommends
// using _beginthreadex instead of CreateThread.
#define USE_BEGINTHREADEX
#endif
#include <windows.h> #include <windows.h>
#define THREAD_RETURN DWORD WINAPI
#ifdef USE_BEGINTHREADEX
#define THREAD_RETURN unsigned __stdcall
#else #else
#define THREAD_RETURN DWORD WINAPI
#endif
#else
#define THREAD_RETURN void* #define THREAD_RETURN void*
#include <unistd.h> #include <unistd.h>
#ifdef _POSIX_THREADS #ifdef _POSIX_THREADS
@ -31,6 +45,7 @@
#else #else
#error unsupported platform (no pthreads?) #error unsupported platform (no pthreads?)
#endif #endif
#endif #endif
// Don't include common.h here as it will break LogManager // Don't include common.h here as it will break LogManager
@ -75,9 +90,17 @@ public:
}; };
#ifdef _WIN32 #ifdef _WIN32
typedef DWORD (WINAPI * ThreadFunc)(void* arg);
#ifdef USE_BEGINTHREADEX
typedef unsigned (__stdcall *ThreadFunc)(void* arg);
#else #else
typedef DWORD (WINAPI *ThreadFunc)(void* arg);
#endif
#else
typedef void* (*ThreadFunc)(void* arg); typedef void* (*ThreadFunc)(void* arg);
#endif #endif
class Thread class Thread
@ -97,12 +120,20 @@ public:
private: private:
#ifdef _WIN32 #ifdef _WIN32
HANDLE m_hThread; HANDLE m_hThread;
DWORD m_threadId; #ifdef USE_BEGINTHREADEX
unsigned m_threadId;
#else #else
DWORD m_threadId;
#endif
#else
#ifdef _POSIX_THREADS #ifdef _POSIX_THREADS
pthread_t thread_id; pthread_t thread_id;
#endif #endif
#endif #endif
}; };
@ -137,6 +168,7 @@ public:
private: private:
#ifdef _WIN32 #ifdef _WIN32
HANDLE m_hEvent; HANDLE m_hEvent;
/* If we have waited more than five seconds we can be pretty sure that the thread is deadlocked. /* If we have waited more than five seconds we can be pretty sure that the thread is deadlocked.
So then we can just as well continue and hope for the best. I could try several times that So then we can just as well continue and hope for the best. I could try several times that
@ -144,12 +176,15 @@ private:
start another game without any noticable problems). But several times it failed to, and ended start another game without any noticable problems). But several times it failed to, and ended
with a crash. But it's better than an infinite deadlock. */ with a crash. But it's better than an infinite deadlock. */
static const int THREAD_WAIT_TIMEOUT = 5000; // INFINITE or 5000 for example static const int THREAD_WAIT_TIMEOUT = 5000; // INFINITE or 5000 for example
#else #else
bool is_set_; bool is_set_;
#ifdef _POSIX_THREADS #ifdef _POSIX_THREADS
pthread_cond_t event_; pthread_cond_t event_;
pthread_mutex_t mutex_; pthread_mutex_t mutex_;
#endif #endif
#endif #endif
}; };

View File

@ -44,11 +44,7 @@ namespace WiiMoteReal
class CWiiMote; class CWiiMote;
#ifdef _WIN32 THREAD_RETURN ReadWiimote_ThreadFunc(void* arg);
DWORD WINAPI ReadWiimote_ThreadFunc(void* arg);
#else
void* ReadWiimote_ThreadFunc(void* arg);
#endif
// Variable declarations // Variable declarations
@ -433,11 +429,7 @@ void Update()
occurs in Update(). If we are not currently using the real Wiimote we allow occurs in Update(). If we are not currently using the real Wiimote we allow
the separate ReadWiimote() function to run. Wo don't use them at the same the separate ReadWiimote() function to run. Wo don't use them at the same
time to avoid a potential collision. */ time to avoid a potential collision. */
#ifdef _WIN32 THREAD_RETURN ReadWiimote_ThreadFunc(void* arg)
DWORD WINAPI ReadWiimote_ThreadFunc(void* arg)
#else
void *ReadWiimote_ThreadFunc(void* arg)
#endif
{ {
while (!g_Shutdown) while (!g_Shutdown)
{ {