Merge pull request #73 from scribam/thread-rework
Rework cThread to use std::thread
This commit is contained in:
commit
ed1a9fabd0
|
@ -38,6 +38,7 @@ Cartridge *CurrentCartridge;
|
|||
bool bios_loaded = false;
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
typedef HANDLE fd_t;
|
||||
#define INVALID_FD INVALID_HANDLE_VALUE
|
||||
#else
|
||||
|
|
|
@ -158,38 +158,18 @@ bool make_directory(const std::string& path)
|
|||
#endif
|
||||
}
|
||||
|
||||
// Thread & related platform dependant code
|
||||
#if !defined(HOST_NO_THREADS)
|
||||
void cThread::Start()
|
||||
{
|
||||
verify(!thread.joinable());
|
||||
thread = std::thread(entry, param);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
void cThread::Start() {
|
||||
verify(hThread == NULL);
|
||||
hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)entry, param, 0, NULL);
|
||||
ResumeThread(hThread);
|
||||
}
|
||||
void cThread::WaitToEnd() {
|
||||
if (GetCurrentThreadId() != GetThreadId(hThread))
|
||||
WaitForSingleObject(hThread, INFINITE);
|
||||
CloseHandle(hThread);
|
||||
hThread = NULL;
|
||||
}
|
||||
#else
|
||||
void cThread::Start() {
|
||||
verify(hThread == NULL);
|
||||
hThread = new pthread_t;
|
||||
if (pthread_create( hThread, NULL, entry, param))
|
||||
die("Thread creation failed");
|
||||
}
|
||||
void cThread::WaitToEnd() {
|
||||
if (hThread) {
|
||||
pthread_join(*hThread,0);
|
||||
delete hThread;
|
||||
hThread = NULL;
|
||||
void cThread::WaitToEnd()
|
||||
{
|
||||
if (thread.joinable()) {
|
||||
thread.join();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
cResetEvent::cResetEvent() : state(false)
|
||||
{
|
||||
|
|
|
@ -5,12 +5,7 @@
|
|||
#include <mutex>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <pthread.h>
|
||||
#else
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <thread>
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <sys/mman.h>
|
||||
|
@ -21,29 +16,22 @@
|
|||
#define PAGE_MASK (PAGE_SIZE-1)
|
||||
#endif
|
||||
|
||||
//Threads
|
||||
|
||||
#if !defined(HOST_NO_THREADS)
|
||||
typedef void* ThreadEntryFP(void* param);
|
||||
|
||||
class cThread {
|
||||
class cThread
|
||||
{
|
||||
private:
|
||||
typedef void* ThreadEntryFP(void* param);
|
||||
ThreadEntryFP* entry;
|
||||
void* param;
|
||||
public :
|
||||
#ifdef _WIN32
|
||||
HANDLE hThread;
|
||||
#else
|
||||
pthread_t *hThread;
|
||||
#endif
|
||||
|
||||
public:
|
||||
std::thread thread;
|
||||
|
||||
cThread(ThreadEntryFP* function, void* param)
|
||||
:entry(function), param(param), hThread(NULL) {}
|
||||
:entry(function), param(param) {}
|
||||
~cThread() { WaitToEnd(); }
|
||||
void Start();
|
||||
void WaitToEnd();
|
||||
};
|
||||
#endif
|
||||
|
||||
class cResetEvent
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#pragma once
|
||||
#include "input/keyboard_device.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
// Used to differentiate between main enter key and num keypad one
|
||||
#define VK_NUMPAD_RETURN 0x0E
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include <xinput.h>
|
||||
#include "input/gamepad_device.h"
|
||||
#include "rend/gui.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <xinput.h>
|
||||
|
||||
class XInputMapping : public InputMapping
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -373,7 +373,7 @@ static cThread render_thread(render_thread_func, NULL);
|
|||
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_rendinitNative(JNIEnv * env, jobject obj, jobject surface, jint width, jint height)
|
||||
{
|
||||
if (render_thread.hThread != NULL)
|
||||
if (render_thread.thread.joinable())
|
||||
{
|
||||
if (surface == NULL)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue