Massive Poo storm, had to take shelter. Hacks, fixes, etc etc

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5421 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Sonicadvance1 2010-04-29 13:46:20 +00:00
parent 3103b920b6
commit 81f06220ce
2 changed files with 567 additions and 679 deletions

View File

@ -17,7 +17,6 @@
#include "Setup.h" #include "Setup.h"
#include "Thread.h" #include "Thread.h"
#include "Atomic.h"
#include "Common.h" #include "Common.h"
#ifdef USE_BEGINTHREADEX #ifdef USE_BEGINTHREADEX
@ -306,22 +305,16 @@ pthread_key_t threadname_key;
CriticalSection::CriticalSection(int spincount_unused) CriticalSection::CriticalSection(int spincount_unused)
{ {
#ifdef __APPLE__
lock = OS_SPINLOCK_INIT;
#else
pthread_mutex_init(&mutex, NULL); pthread_mutex_init(&mutex, NULL);
#endif
} }
CriticalSection::~CriticalSection() CriticalSection::~CriticalSection()
{ {
#ifndef __APPLE__
pthread_mutex_destroy(&mutex); pthread_mutex_destroy(&mutex);
#endif
} }
#ifndef __APPLE__
void CriticalSection::Enter() void CriticalSection::Enter()
{ {
int ret = pthread_mutex_lock(&mutex); int ret = pthread_mutex_lock(&mutex);
@ -342,26 +335,8 @@ void CriticalSection::Leave()
if (ret) ERROR_LOG(COMMON, "%s: pthread_mutex_unlock(%p) failed: %s\n", if (ret) ERROR_LOG(COMMON, "%s: pthread_mutex_unlock(%p) failed: %s\n",
__FUNCTION__, &mutex, strerror(ret)); __FUNCTION__, &mutex, strerror(ret));
} }
#else
void CriticalSection::Enter()
{
OSSpinLockLock(&lock);
}
bool CriticalSection::TryEnter()
{
return(!OSSpinLockTry(&lock));
}
void CriticalSection::Leave()
{
OSSpinLockUnlock(&lock);
}
#endif
Thread::Thread(ThreadFunc function, void* arg) Thread::Thread(ThreadFunc function, void* arg)
: thread_id(0) : thread_id(0)
{ {
@ -465,96 +440,24 @@ void SetCurrentThreadName(const TCHAR* szThreadName)
Event::Event() Event::Event()
{ {
#ifdef __APPLE__
lock = OS_SPINLOCK_INIT;
event_ = 0;
#endif
is_set_ = false; is_set_ = false;
} }
void Event::Init() void Event::Init()
{ {
#ifndef __APPLE__
pthread_cond_init(&event_, 0); pthread_cond_init(&event_, 0);
pthread_mutex_init(&mutex_, 0); pthread_mutex_init(&mutex_, 0);
#else
lock = OS_SPINLOCK_INIT;
event_ = 0;
#endif
} }
void Event::Shutdown() void Event::Shutdown()
{ {
#ifndef __APPLE__
pthread_mutex_destroy(&mutex_); pthread_mutex_destroy(&mutex_);
pthread_cond_destroy(&event_); pthread_cond_destroy(&event_);
#endif
}
#ifdef __APPLE__
void Event::Set()
{
OSSpinLockLock(&lock);
if (!is_set_)
{
is_set_ = true;
Common::AtomicStore(event_, 1);
}
OSSpinLockUnlock(&lock);
} }
bool Event::Wait(const u32 timeout)
{
bool timedout = false;
struct timespec wait;
if (timeout != INFINITE)
{
struct timeval now;
gettimeofday(&now, NULL);
memset(&wait, 0, sizeof(wait));
//TODO: timespec also has nanoseconds, but do we need them?
//as consequence, waiting is limited to seconds for now.
//the following just looks ridiculous, and probably fails for
//values 429 < ms <= 999 since it overflows the long.
//wait.tv_nsec = (now.tv_usec + (timeout % 1000) * 1000) * 1000);
wait.tv_sec = now.tv_sec + (timeout / 1000);
}
int Slept = 0;
while (!timedout)
{
if (timeout == INFINITE)
{
if(Common::AtomicLoad(event_) == 1)
break;
}
else
{
if(Slept >= wait.tv_sec * 1000000)
timedout = true;
else
if(Common::AtomicLoad(event_) == 1)
break;
}
usleep(250);
Slept += 250;
}
OSSpinLockLock(&lock);
is_set_ = false;
Common::AtomicStore(event_, 0);
OSSpinLockUnlock(&lock);
return timedout;
}
#else
void Event::Set() void Event::Set()
{ {
pthread_mutex_lock(&mutex_); pthread_mutex_lock(&mutex_);
@ -606,7 +509,6 @@ bool Event::Wait(const u32 timeout)
return timedout; return timedout;
} }
#endif
#endif #endif

View File

@ -47,10 +47,6 @@
#error unsupported platform (no pthreads?) #error unsupported platform (no pthreads?)
#endif #endif
#ifdef __APPLE__
#include <libkern/OSAtomic.h>
#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
@ -79,13 +75,9 @@ class CriticalSection
CRITICAL_SECTION section; CRITICAL_SECTION section;
#else #else
#ifdef _POSIX_THREADS #ifdef _POSIX_THREADS
#ifdef __APPLE__
OSSpinLock lock;
#else
pthread_mutex_t mutex; pthread_mutex_t mutex;
#endif #endif
#endif #endif
#endif
public: public:
CriticalSection(int spincount = 1000); CriticalSection(int spincount = 1000);
@ -176,7 +168,6 @@ class Event
{ {
public: public:
Event(); Event();
void Init(); void Init();
void Shutdown(); void Shutdown();
@ -205,14 +196,9 @@ private:
bool is_set_; bool is_set_;
#ifdef _POSIX_THREADS #ifdef _POSIX_THREADS
#ifdef __APPLE__
OSSpinLock lock;
u32 event_;
#else
pthread_cond_t event_; pthread_cond_t event_;
pthread_mutex_t mutex_; pthread_mutex_t mutex_;
#endif #endif
#endif
#endif #endif
}; };