diff --git a/core/hw/pvr/Renderer_if.cpp b/core/hw/pvr/Renderer_if.cpp index fc4db314d..0a9c5b16b 100644 --- a/core/hw/pvr/Renderer_if.cpp +++ b/core/hw/pvr/Renderer_if.cpp @@ -82,8 +82,7 @@ bool renderer_enabled = true; // Signals the renderer thread to exit bool renderer_changed = false; // Signals the renderer thread to switch renderer #if !defined(TARGET_NO_THREADS) -cResetEvent rs(false,true); -cResetEvent re(false,true); +cResetEvent rs, re; #endif int max_idx,max_mvo,max_op,max_pt,max_tr,max_vtx,max_modt, ovrn; diff --git a/core/hw/pvr/ta_ctx.cpp b/core/hw/pvr/ta_ctx.cpp index 781d82aa4..31e80b07e 100644 --- a/core/hw/pvr/ta_ctx.cpp +++ b/core/hw/pvr/ta_ctx.cpp @@ -124,7 +124,7 @@ void VDecEnd() cMutex mtx_rqueue; TA_context* rqueue; -cResetEvent frame_finished(false, true); +cResetEvent frame_finished; double last_frame = 0; u64 last_cyces = 0; diff --git a/core/linux/common.cpp b/core/linux/common.cpp index 7b6db0f7f..98ffca196 100644 --- a/core/linux/common.cpp +++ b/core/linux/common.cpp @@ -130,109 +130,6 @@ void install_fault_handler (void) #endif } -#if !defined(TARGET_NO_THREADS) - -//Thread class -cThread::cThread(ThreadEntryFP* function,void* prm) -{ - Entry=function; - param=prm; -} - -void cThread::Start() -{ - verify(hThread == NULL); - if (pthread_create( (pthread_t*)&hThread, NULL, Entry, param)) - { - die("Thread creation failed"); - } -} - -void cThread::WaitToEnd() -{ - if (hThread != NULL) - { - pthread_join((pthread_t)hThread,0); - hThread = NULL; - } -} - -//End thread class -#endif - -//cResetEvent Calss -cResetEvent::cResetEvent(bool State,bool Auto) -{ - //sem_init((sem_t*)hEvent, 0, State?1:0); - verify(State==false&&Auto==true); - pthread_mutex_init(&mutx, NULL); - pthread_cond_init(&cond, NULL); -} -cResetEvent::~cResetEvent() -{ - //Destroy the event object ? - -} -void cResetEvent::Set()//Signal -{ - pthread_mutex_lock( &mutx ); - state=true; - pthread_cond_signal( &cond); - pthread_mutex_unlock( &mutx ); -} -void cResetEvent::Reset()//reset -{ - pthread_mutex_lock( &mutx ); - state=false; - pthread_mutex_unlock( &mutx ); -} -bool cResetEvent::Wait(u32 msec)//Wait for signal , then reset -{ - pthread_mutex_lock( &mutx ); - if (!state) - { - struct timespec ts; -#if HOST_OS == OS_DARWIN - // OSX doesn't have clock_gettime. - clock_serv_t cclock; - mach_timespec_t mts; - - host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); - clock_get_time(cclock, &mts); - mach_port_deallocate(mach_task_self(), cclock); - ts.tv_sec = mts.tv_sec; - ts.tv_nsec = mts.tv_nsec; -#else - clock_gettime(CLOCK_REALTIME, &ts); -#endif - ts.tv_sec += msec / 1000; - ts.tv_nsec += (msec % 1000) * 1000000; - while (ts.tv_nsec > 1000000000) - { - ts.tv_nsec -= 1000000000; - ts.tv_sec++; - } - pthread_cond_timedwait( &cond, &mutx, &ts ); - } - bool rc = state; - state=false; - pthread_mutex_unlock( &mutx ); - - return rc; -} -void cResetEvent::Wait()//Wait for signal , then reset -{ - pthread_mutex_lock( &mutx ); - if (!state) - { - pthread_cond_wait( &cond, &mutx ); - } - state=false; - pthread_mutex_unlock( &mutx ); -} - -//End AutoResetEvent - #include void VArray2::LockRegion(u32 offset,u32 size) diff --git a/core/rend/gles/CustomTexture.h b/core/rend/gles/CustomTexture.h index 830855542..fd8a00db1 100644 --- a/core/rend/gles/CustomTexture.h +++ b/core/rend/gles/CustomTexture.h @@ -29,9 +29,9 @@ public: CustomTexture() : #ifndef TARGET_NO_THREADS - loader_thread(loader_thread_func, this), + loader_thread(loader_thread_func, this) #endif - wakeup_thread(false, true) {} + {} ~CustomTexture() { Terminate(); } u8* LoadCustomTexture(u32 hash, int& width, int& height); void LoadCustomTextureAsync(TextureCacheData *texture_data); diff --git a/core/stdclass.cpp b/core/stdclass.cpp index ca773ee24..05cc49013 100644 --- a/core/stdclass.cpp +++ b/core/stdclass.cpp @@ -4,6 +4,7 @@ #include #include "types.h" #include "cfg/cfg.h" +#include "stdclass.h" #if COMPILER_VC_OR_CLANG_WIN32 @@ -153,55 +154,145 @@ bool make_directory(const string& path) #endif } -#if 0 -//File Enumeration -void FindAllFiles(FileFoundCB* callback,wchar* dir,void* param) -{ - WIN32_FIND_DATA FindFileData; - HANDLE hFind = INVALID_HANDLE_VALUE; - wchar DirSpec[MAX_PATH + 1]; // directory specification - DWORD dwError; +// Thread & related platform dependant code +#if !defined(HOST_NO_THREADS) - strncpy (DirSpec, dir, strlen(dir)+1); - //strncat (DirSpec, "\\*", 3); - - hFind = FindFirstFile( DirSpec, &FindFileData); - - if (hFind == INVALID_HANDLE_VALUE) - { - return; - } - else - { - - if ((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)==0) - { - callback(FindFileData.cFileName,param); - } -u32 rv; - while ( (rv=FindNextFile(hFind, &FindFileData)) != 0) - { - if ((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)==0) - { - callback(FindFileData.cFileName,param); - } - } - dwError = GetLastError(); - FindClose(hFind); - if (dwError != ERROR_NO_MORE_FILES) - { - return ; - } +#if HOST_OS==OS_WINDOWS +void cThread::Start() { + verify(hThread == NULL); + hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)entry, param, 0, NULL); + ResumeThread(hThread); +} +void cThread::WaitToEnd() { + 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; } - return ; } #endif -/* -#include "dc\sh4\rec_v1\compiledblock.h" -#include "dc\sh4\rec_v1\blockmanager.h" +#endif + + +#if HOST_OS==OS_WINDOWS +cResetEvent::cResetEvent() { + hEvent = CreateEvent( + NULL, // default security attributes + FALSE, // auto-reset event? + FALSE, // initial state is State + NULL // unnamed object + ); +} +cResetEvent::~cResetEvent() +{ + //Destroy the event object ? + CloseHandle(hEvent); +} +void cResetEvent::Set()//Signal +{ + #if defined(DEBUG_THREADS) + Sleep(rand() % 10); + #endif + SetEvent(hEvent); +} +void cResetEvent::Reset()//reset +{ + #if defined(DEBUG_THREADS) + Sleep(rand() % 10); + #endif + ResetEvent(hEvent); +} +bool cResetEvent::Wait(u32 msec)//Wait for signal , then reset +{ + #if defined(DEBUG_THREADS) + Sleep(rand() % 10); + #endif + return WaitForSingleObject(hEvent,msec) == WAIT_OBJECT_0; +} +void cResetEvent::Wait()//Wait for signal , then reset +{ + #if defined(DEBUG_THREADS) + Sleep(rand() % 10); + #endif + WaitForSingleObject(hEvent,(u32)-1); +} +#else +cResetEvent::cResetEvent() { + pthread_mutex_init(&mutx, NULL); + pthread_cond_init(&cond, NULL); +} +cResetEvent::~cResetEvent() { +} +void cResetEvent::Set()//Signal +{ + pthread_mutex_lock( &mutx ); + state=true; + pthread_cond_signal( &cond); + pthread_mutex_unlock( &mutx ); +} +void cResetEvent::Reset()//reset +{ + pthread_mutex_lock( &mutx ); + state=false; + pthread_mutex_unlock( &mutx ); +} +bool cResetEvent::Wait(u32 msec)//Wait for signal , then reset +{ + pthread_mutex_lock( &mutx ); + if (!state) + { + struct timespec ts; +#if HOST_OS == OS_DARWIN + // OSX doesn't have clock_gettime. + clock_serv_t cclock; + mach_timespec_t mts; + + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + ts.tv_sec = mts.tv_sec; + ts.tv_nsec = mts.tv_nsec; +#else + clock_gettime(CLOCK_REALTIME, &ts); +#endif + ts.tv_sec += msec / 1000; + ts.tv_nsec += (msec % 1000) * 1000000; + while (ts.tv_nsec > 1000000000) + { + ts.tv_nsec -= 1000000000; + ts.tv_sec++; + } + pthread_cond_timedwait( &cond, &mutx, &ts ); + } + bool rc = state; + state=false; + pthread_mutex_unlock( &mutx ); + + return rc; +} +void cResetEvent::Wait()//Wait for signal , then reset +{ + pthread_mutex_lock( &mutx ); + if (!state) + { + pthread_cond_wait( &cond, &mutx ); + } + state=false; + pthread_mutex_unlock( &mutx ); +} +#endif -bool VramLockedWrite(u8* address); -bool RamLockedWrite(u8* address,u32* sp); -*/ diff --git a/core/stdclass.h b/core/stdclass.h index 0c30dd534..f5e87e6cb 100644 --- a/core/stdclass.h +++ b/core/stdclass.h @@ -166,38 +166,41 @@ public: #if !defined(HOST_NO_THREADS) typedef void* ThreadEntryFP(void* param); -typedef void* THREADHANDLE; - -class cThread -{ +class cThread { private: - ThreadEntryFP* Entry; + ThreadEntryFP* entry; void* param; public : - THREADHANDLE hThread; - cThread(ThreadEntryFP* function,void* param); - + #if HOST_OS==OS_WINDOWS + HANDLE hThread; + #else + pthread_t *hThread; + #endif + + cThread(ThreadEntryFP* function, void* param) + :entry(function), param(param), hThread(NULL) {} + ~cThread() { WaitToEnd(); } void Start(); void WaitToEnd(); }; #endif + + //Wait Events typedef void* EVENTHANDLE; class cResetEvent { - private: #if HOST_OS==OS_WINDOWS EVENTHANDLE hEvent; #else pthread_mutex_t mutx; pthread_cond_t cond; - + bool state; #endif public : - bool state; - cResetEvent(bool State,bool Auto); + cResetEvent(); ~cResetEvent(); void Set(); //Set state to signaled void Reset(); //Set state to non signaled diff --git a/core/windows/winmain.cpp b/core/windows/winmain.cpp index 7e269a90d..27d651dd4 100644 --- a/core/windows/winmain.cpp +++ b/core/windows/winmain.cpp @@ -750,78 +750,6 @@ void os_DoEvents() } - - -//Windoze Code implementation of commong classes from here and after .. - -//Thread class -cThread::cThread(ThreadEntryFP* function,void* prm) -{ - Entry=function; - param=prm; -} - - -void cThread::Start() -{ - verify(hThread == NULL); - hThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)Entry,param,0,NULL); - ResumeThread(hThread); -} - -void cThread::WaitToEnd() -{ - WaitForSingleObject(hThread,INFINITE); - CloseHandle(hThread); - hThread = NULL; -} -//End thread class - -//cResetEvent Calss -cResetEvent::cResetEvent(bool State,bool Auto) -{ - hEvent = CreateEvent( - NULL, // default security attributes - Auto?FALSE:TRUE, // auto-reset event? - State?TRUE:FALSE, // initial state is State - NULL // unnamed object - ); -} -cResetEvent::~cResetEvent() -{ - //Destroy the event object ? - CloseHandle(hEvent); -} -void cResetEvent::Set()//Signal -{ - #if defined(DEBUG_THREADS) - Sleep(rand() % 10); - #endif - SetEvent(hEvent); -} -void cResetEvent::Reset()//reset -{ - #if defined(DEBUG_THREADS) - Sleep(rand() % 10); - #endif - ResetEvent(hEvent); -} -bool cResetEvent::Wait(u32 msec)//Wait for signal , then reset -{ - #if defined(DEBUG_THREADS) - Sleep(rand() % 10); - #endif - return WaitForSingleObject(hEvent,msec) == WAIT_OBJECT_0; -} -void cResetEvent::Wait()//Wait for signal , then reset -{ - #if defined(DEBUG_THREADS) - Sleep(rand() % 10); - #endif - WaitForSingleObject(hEvent,(u32)-1); -} -//End AutoResetEvent - void VArray2::LockRegion(u32 offset,u32 size) { //verify(offset+sizesize);