|
From: <ba...@us...> - 2006-06-06 03:52:59
|
Revision: 335 Author: bardtx Date: 2006-06-05 20:52:50 -0700 (Mon, 05 Jun 2006) ViewCVS: http://svn.sourceforge.net/cadcdev/?rev=335&view=rev Log Message: ----------- tiki: Switch DC port over to using pthreads instead of KOS threads Modified Paths: -------------- tiki/dc/include/Tiki/platthread.h tiki/dc/src/platthread.cpp tiki/include/Tiki/thread.h tiki/src/thread/thread.cpp Modified: tiki/dc/include/Tiki/platthread.h =================================================================== --- tiki/dc/include/Tiki/platthread.h 2006-06-06 03:51:53 UTC (rev 334) +++ tiki/dc/include/Tiki/platthread.h 2006-06-06 03:52:50 UTC (rev 335) @@ -9,18 +9,14 @@ #ifndef __TIKI_PLATTHREAD_H #define __TIKI_PLATTHREAD_H -#include <kos/thread.h> -#include <kos/sem.h> -#include <kos/mutex.h> -#include <kos/cond.h> -#include <kos/genwait.h> +#include <pthread.h> namespace Tiki { namespace Thread { -typedef ::kthread_t thread_t; -typedef ::mutex_t mutex_t; -typedef ::condvar_t cond_t; +typedef ::pthread_t thread_t; +typedef ::pthread_mutex_t mutex_t; +typedef ::pthread_cond_t cond_t; } } Modified: tiki/dc/src/platthread.cpp =================================================================== --- tiki/dc/src/platthread.cpp 2006-06-06 03:51:53 UTC (rev 334) +++ tiki/dc/src/platthread.cpp 2006-06-06 03:52:50 UTC (rev 335) @@ -1,7 +1,7 @@ /* Tiki - platthread.cpp + tikitime.cpp Copyright (C)2005 Cryptic Allusion, LLC */ @@ -12,81 +12,106 @@ #include <sys/time.h> #include <time.h> -using Tiki::Thread::mutex_t; +// +// For OSX, these pretty much thunk straight down to pthreads. +// + +//using Tiki::Thread::mutex_t; using Tiki::Thread::cond_t; -bool Thread::create(kthread_t * hndout, void (*func)(void *), void * param) { - hndout = thd_create(func, param); - return hndout != NULL; +bool Thread::create(pthread_t * out, void * (*func)(void *), void * param) { + return pthread_create(out, NULL, func, param) >= 0; } -bool Thread::join(kthread_t thd, void ** out) { - thd_wait(&thd); - return true; +bool Thread::join(pthread_t thd, void ** out) { + return pthread_join(thd, out) >= 0; } void Thread::exit(void * ptr) { - thd_exit(); + pthread_exit(ptr); } -bool Thread::equal(kthread_t t1, kthread_t t2) { - return t1.tid == t2.tid; +bool Thread::equal(pthread_t t1, pthread_t t2) { + return !!pthread_equal(t1, t2); } -kthread_t Thread::self() { - return *thd_get_current(); +pthread_t Thread::self() { + return pthread_self(); } bool Thread::mutex_create(mutex_t * out) { - out = ::mutex_create(); - return true; + pthread_mutexattr_t attrs; + if (pthread_mutexattr_init(&attrs) < 0) { + assert( false ); + return false; + } + /*if (pthread_mutexattr_settype(&attrs, PTHREAD_MUTEX_RECURSIVE) < 0) { + assert( false ); + return false; + }*/ + int rv = pthread_mutex_init(out, &attrs) >= 0; + pthread_mutexattr_destroy(&attrs); + return rv; } bool Thread::mutex_destroy(mutex_t * m) { - ::mutex_destroy(m); - return true; + return pthread_mutex_destroy(m) >= 0; } bool Thread::mutex_trylock(mutex_t * m) { - return ::mutex_trylock(m) >= 0; + return pthread_mutex_trylock(m) >= 0; } bool Thread::mutex_lock(mutex_t * m) { - return ::mutex_lock(m) >= 0; + return pthread_mutex_lock(m) >= 0; } bool Thread::mutex_unlock(mutex_t * m) { - ::mutex_unlock(m); - return true; + return pthread_mutex_unlock(m) >= 0; } bool Thread::cond_broadcast(cond_t *cond) { - ::cond_broadcast(cond); - return true; + return pthread_cond_broadcast(cond) >= 0; } bool Thread::cond_destroy(cond_t *cond) { - ::cond_destroy(cond); - return true; + return pthread_cond_destroy(cond) >= 0; } bool Thread::cond_create(cond_t *cond) { - cond = ::cond_create(); - return true; + return pthread_cond_init(cond, NULL) >= 0; } bool Thread::cond_signal(cond_t *cond) { - ::cond_signal(cond); - return true; + return pthread_cond_signal(cond) >= 0; } bool Thread::cond_wait(cond_t *cond, mutex_t *mutex, uint64 maxWaitMicros) { - ::cond_wait_timed(cond, mutex, maxWaitMicros / 1000); - return true; + struct timeval tn; + gettimeofday(&tn, NULL); + + tn.tv_sec += maxWaitMicros / 1000000; + tn.tv_usec += maxWaitMicros % 1000000; + + struct timespec ts; + ts.tv_sec = tn.tv_sec; + ts.tv_nsec = tn.tv_usec * 1000; + + return pthread_cond_timedwait(cond, mutex, &ts) >= 0; } bool Thread::cond_wait(cond_t * cond, mutex_t *mutex) { - return ::cond_wait(cond, mutex) >= 0; + return pthread_cond_wait(cond, mutex) >= 0; } + + + + + + + + + + Modified: tiki/include/Tiki/thread.h =================================================================== --- tiki/include/Tiki/thread.h 2006-06-06 03:51:53 UTC (rev 334) +++ tiki/include/Tiki/thread.h 2006-06-06 03:52:50 UTC (rev 335) @@ -23,11 +23,7 @@ // Plat should have also defined mutex_t and cond_t. -#if TIKI_PLAT == TIKI_DC -bool create(thread_t * hndout, void (*func)(void *), void * param); -#else bool create(thread_t * hndout, void * (*func)(void *), void * param); -#endif bool join(thread_t hnd, void ** out); bool equal(thread_t t1, thread_t t2); thread_t self(); @@ -50,21 +46,13 @@ class Thread : public RefCnt { public: Thread(); -#if TIKI_PLAT == TIKI_DC - Thread(void (*)(void *), void * param); -#else Thread(void* (*)(void *), void * param); -#endif virtual ~Thread(); bool operator==(const Thread & other) const; bool valid() const; -#if TIKI_PLAT == TIKI_DC - bool create(void (*func)(void *), void * param); -#else bool create(void* (*func)(void *), void * param); -#endif bool join(void ** out = NULL); protected: Modified: tiki/src/thread/thread.cpp =================================================================== --- tiki/src/thread/thread.cpp 2006-06-06 03:51:53 UTC (rev 334) +++ tiki/src/thread/thread.cpp 2006-06-06 03:52:50 UTC (rev 335) @@ -15,15 +15,9 @@ Tiki::Thread::Thread::Thread() { } -#if TIKI_PLAT == TIKI_DC -Tiki::Thread::Thread::Thread(void (* func)(void *), void * param) { - create(func, param); -} -#else Tiki::Thread::Thread::Thread(void* (* func)(void *), void * param) { create(func, param); } -#endif Tiki::Thread::Thread::~Thread() { if (valid()) @@ -35,22 +29,12 @@ } bool Tiki::Thread::Thread::valid() const { -#if TIKI_PLAT == TIKI_DC - return false; -#else return (m_hnd != NULL); -#endif } -#if TIKI_PLAT == TIKI_DC -bool Tiki::Thread::Thread::create(void (* func)(void *), void * param) { - return Tiki::Thread::create(&m_hnd, func, param); -} -#else bool Tiki::Thread::Thread::create(void* (* func)(void *), void * param) { return Tiki::Thread::create(&m_hnd, func, param); } -#endif bool Tiki::Thread::Thread::join(void ** out) { return Tiki::Thread::join(m_hnd, out); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |