mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 13:20:27 -06:00
Replaced Common::Thread with a partial implementation of std::thread. (rvalue references are used if available, <thread> 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
This commit is contained in:
@ -18,37 +18,7 @@
|
||||
#ifndef _THREAD_H_
|
||||
#define _THREAD_H_
|
||||
|
||||
#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
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef USE_BEGINTHREADEX
|
||||
#define THREAD_RETURN unsigned __stdcall
|
||||
#else
|
||||
#define THREAD_RETURN DWORD WINAPI
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#include <xmmintrin.h>
|
||||
#define THREAD_RETURN void*
|
||||
#include <unistd.h>
|
||||
#ifdef _POSIX_THREADS
|
||||
#include <pthread.h>
|
||||
#elif GEKKO
|
||||
#include <ogc/lwp_threads.h>
|
||||
#else
|
||||
#error unsupported platform (no pthreads?)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#include "StdThread.h"
|
||||
|
||||
// Don't include common.h here as it will break LogManager
|
||||
#include "CommonTypes.h"
|
||||
@ -61,6 +31,8 @@
|
||||
#define INFINITE 0xffffffff
|
||||
#endif
|
||||
|
||||
#include <xmmintrin.h>
|
||||
|
||||
//for gettimeofday and struct time(spec|val)
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
@ -69,6 +41,11 @@
|
||||
|
||||
namespace Common
|
||||
{
|
||||
|
||||
int CurrentThreadId();
|
||||
|
||||
void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask);
|
||||
void SetCurrentThreadAffinity(u32 mask);
|
||||
|
||||
class CriticalSection
|
||||
{
|
||||
@ -88,57 +65,6 @@ namespace Common
|
||||
void Leave();
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifdef USE_BEGINTHREADEX
|
||||
typedef unsigned (__stdcall *ThreadFunc)(void* arg);
|
||||
#else
|
||||
typedef DWORD (WINAPI *ThreadFunc)(void* arg);
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
typedef void* (*ThreadFunc)(void* arg);
|
||||
|
||||
#endif
|
||||
|
||||
class Thread
|
||||
{
|
||||
public:
|
||||
Thread(ThreadFunc entry, void* arg);
|
||||
~Thread();
|
||||
|
||||
void SetAffinity(int mask);
|
||||
static void SetCurrentThreadAffinity(int mask);
|
||||
static int CurrentId();
|
||||
bool IsCurrentThread();
|
||||
#ifdef _WIN32
|
||||
void SetPriority(int priority);
|
||||
DWORD WaitForDeath(const int iWait = INFINITE);
|
||||
#else
|
||||
void WaitForDeath();
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
HANDLE m_hThread;
|
||||
#ifdef USE_BEGINTHREADEX
|
||||
unsigned m_threadId;
|
||||
#else
|
||||
DWORD m_threadId;
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#ifdef _POSIX_THREADS
|
||||
pthread_t thread_id;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
// Event(WaitForSingleObject) is too expensive
|
||||
// as it always enters Ring0 regardless of the state of lock
|
||||
|
Reference in New Issue
Block a user