Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Put the thread implementations in separate files.

include (against my better judgement) config.h from pal-threads.h.  make
sure we include config.h from everywhere that includes pal-threads.h.
commit 1dff62a56ab2b6cecfe77f438716109d32769a46 1 parent dcbec70
@toshok toshok authored
View
2  build/osx/launcher/Makefile
@@ -1,2 +1,2 @@
all:
- g++ main.c -o launcher -arch i386 -DPAL_THREADS_PTHREADS=1 -I/Users/toshok/src/mono/mono -I/Users/toshok/src/mono/mono/eglib -I/Users/toshok/src/mono/mono/eglib/src -I/Users/toshok/src/mono/moon/src -I/Users/toshok/src/mono/moon/src/pal -I/Users/toshok/src/mono/moon/cairo/src -I/opt/moonlight-osx/include/freetype2/ -I/opt/moonlight-osx/include/ -L/opt/moonlight-osx/lib/ -lmoon /Users/toshok/src/mono/mono/mono/mini/.libs/libmono-moon.a -framework CoreFoundation
+ g++ main.c -o launcher -arch i386 -I/Users/toshok/src/mono/moon -I/Users/toshok/src/mono/moon/src -I/Users/toshok/src/mono/moon/src/pal -I/Users/toshok/src/mono/mono -I/Users/toshok/src/mono/mono/eglib -I/Users/toshok/src/mono/mono/eglib/src -I/Users/toshok/src/mono/moon/cairo/src -I/opt/moonlight-osx/include/freetype2/ -I/opt/moonlight-osx/include/ -L/opt/moonlight-osx/lib/ -lmoon /Users/toshok/src/mono/mono/mono/mini/.libs/libmono-moon.a -framework CoreFoundation
View
5 build/osx/launcher/main.c
@@ -12,11 +12,14 @@ G_END_DECLS
#define INCLUDED_MONO_HEADERS 1
+#include "config.h"
+
+#include "pal.h"
+
#include "runtime.h"
#include "deployment.h"
#include "downloader.h"
#include "uri.h"
-#include "pal.h"
#include "window.h"
#include "debug.h"
View
6 m4/pal.m4
@@ -43,7 +43,7 @@ if test "x$with_pal" = "xgtk"; then
PKG_CHECK_MODULES(FONTCONFIG, fontconfig)
PKG_CHECK_MODULES(GLIB, glib-2.0)
- PAL_CFLAGS="-DPAL_THREADS_PTHREADS=1"
+ AC_DEFINE([PAL_THREADS_PTHREADS],1,[Hack in pthreads for all gtk systems.])
PAL=gtk
@@ -79,7 +79,7 @@ elif test "x$with_pal" = "xcocoa"; then
[Include support for freetype2 in the font manager])
])
- PAL_CFLAGS="-DPAL_THREADS_PTHREADS=1"
+ AC_DEFINE([PAL_THREADS_PTHREADS],1,[Use pthreads for cocoa.])
elif test "x$with_pal" = "xandroid"; then
@@ -108,7 +108,7 @@ elif test "x$with_pal" = "xandroid"; then
[Include support for freetype2 in the font manager])
])
- PAL_CFLAGS="-DPAL_THREADS_PTHREADS=1"
+ AC_DEFINE([PAL_THREADS_PTHREADS],1,[Use pthreads for android.])
else
AC_MSG_ERROR([unknown PAL specified])
View
3  src/Makefile.am
@@ -253,7 +253,8 @@ dist_libmoon_la_SOURCES = \
namescope.cpp \
openfile.cpp \
pal/pal.cpp \
- pal/pal-threads.cpp \
+ pal/pal-threads-pthreads.cpp \
+ pal/pal-threads-windows.cpp \
pal/window.cpp \
panel.cpp \
pipeline-asf.cpp \
View
2  src/moon-path.cpp
@@ -11,6 +11,8 @@
*
*/
+#include "config.h"
+
#include "moon-path.h"
namespace Moonlight {
View
1  src/pal/cocoa/MLEvent.m
@@ -1,3 +1,4 @@
+#include "config.h"
#include "runtime.h"
#import "MLEvent.h"
View
1  src/pal/cocoa/MLTimerContext.m
@@ -1,3 +1,4 @@
+#include "config.h"
#import "MLTimerContext.h"
@implementation MLTimerContext
View
1  src/pal/cocoa/MLView.m
@@ -1,3 +1,4 @@
+#include "config.h"
#include "runtime.h"
#import "MLView.h"
View
1  src/pal/cocoa/MLWindow.m
@@ -1,3 +1,4 @@
+#include "config.h"
#include "runtime.h"
#import "MLWindow.h"
View
282 src/pal/pal-threads-pthreads.cpp
@@ -0,0 +1,282 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * pal-threads-pthreads.cpp
+ *
+ * Copyright 2011 Novell, Inc. (http://www.novell.com)
+ *
+ * See the LICENSE file included with the distribution for details.
+ *
+ */
+
+#include "config.h"
+
+#if PAL_THREADS_PTHREADS
+
+#include "pal-threads.h"
+
+namespace Moonlight {
+
+MoonTlsKey::MoonTlsKey ()
+{
+ pthread_key_create (&tls_key, NULL);
+}
+
+MoonTlsKey::~MoonTlsKey ()
+{
+}
+
+
+MoonThread::MoonThread (ThreadFunc func, gpointer func_arg)
+ : func (func), func_arg (func_arg)
+{
+}
+
+MoonThread::MoonThread ()
+{
+ pt = pthread_self ();
+}
+
+MoonThread::~MoonThread ()
+{
+}
+
+bool
+MoonThread::Join ()
+{
+ return pthread_join (pt, NULL);
+}
+
+bool
+MoonThread::IsThread (MoonThread* other)
+{
+ return pthread_equal (pthread_self(), other->pt);
+}
+
+gpointer
+MoonThread::GetSpecific (MoonTlsKey& key)
+{
+ return (gpointer)pthread_getspecific (key.tls_key);
+}
+
+void
+MoonThread::SetSpecific (MoonTlsKey& key, gpointer data)
+{
+ pthread_setspecific (key.tls_key, data);
+}
+
+void*
+MoonThread::Main (void* data)
+{
+ MoonThread *moon_thread = (MoonThread*)data;
+
+ pthread_setspecific (self_tls, moon_thread);
+
+ void* rv = moon_thread->func (moon_thread->func_arg);
+
+ pthread_setspecific (self_tls, NULL); // this will invoke the key dtor MoonThread::Cleanup
+
+ return rv;
+}
+
+pthread_key_t MoonThread::self_tls = 0;
+
+int
+MoonThread::Start (MoonThread **mt, MoonThread::ThreadFunc func, gpointer arg)
+{
+ if (self_tls == 0)
+ pthread_key_create (&self_tls, NULL);
+
+ MoonThread *moon_thread = new MoonThread (func, arg);
+ int result = pthread_create (&moon_thread->pt, NULL, MoonThread::Main, moon_thread);
+
+ if (result == 0) {
+ *mt = moon_thread;
+ }
+ else {
+ delete moon_thread;
+ *mt = NULL;
+ }
+
+ return result;
+}
+
+int
+MoonThread::StartJoinable (MoonThread **mt, MoonThread::ThreadFunc func, gpointer arg)
+{
+ if (self_tls == 0)
+ pthread_key_create (&self_tls, NULL);
+
+ MoonThread *moon_thread = new MoonThread (func, arg);
+
+ pthread_attr_t attribs;
+
+ pthread_attr_init (&attribs);
+ pthread_attr_setdetachstate (&attribs, PTHREAD_CREATE_JOINABLE);
+ int result = pthread_create (&moon_thread->pt, &attribs, MoonThread::Main, moon_thread);
+ pthread_attr_destroy (&attribs);
+
+ if (result == 0) {
+ *mt = moon_thread;
+ }
+ else {
+ delete moon_thread;
+ *mt = NULL;
+ }
+
+ return result;
+}
+
+void
+MoonThread::Cleanup (void *data)
+{
+ delete (MoonThread*)data;
+}
+
+MoonThread*
+MoonThread::Self ()
+{
+ // FIXME we race here
+ if (self_tls == 0)
+ pthread_key_create (&self_tls, MoonThread::Cleanup);
+
+ MoonThread *mt = (MoonThread*)pthread_getspecific (self_tls);
+ if (mt == NULL) {
+ // this happens in an unattached thread (the main thread, as well
+ // as mono threads that call into moonlight)
+ mt = new MoonThread ();
+ pthread_setspecific (self_tls, mt);
+ }
+
+ return mt;
+}
+
+
+MoonMutex::MoonMutex (bool recursive)
+{
+ if (!recursive) {
+ pthread_mutex_init (&mutex, NULL);
+ }
+ else {
+ pthread_mutexattr_t mta;
+ pthread_mutexattr_init (&mta);
+ pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE);
+ pthread_mutex_init (&mutex, &mta);
+ pthread_mutexattr_destroy (&mta);
+ }
+}
+
+MoonMutex::~MoonMutex ()
+{
+ pthread_mutex_destroy (&mutex);
+}
+
+void
+MoonMutex::Lock ()
+{
+ pthread_mutex_lock (&mutex);
+}
+
+void
+MoonMutex::Unlock ()
+{
+ pthread_mutex_unlock (&mutex);
+}
+
+
+MoonRWLock::MoonRWLock ()
+{
+#if HAVE_PTHREAD_RWLOCK_RDLOCK
+ pthread_rwlock_init (&lock, NULL);
+#else
+ pthread_mutex_init (&lock, NULL);
+#endif
+}
+
+MoonRWLock::~MoonRWLock ()
+{
+#if HAVE_PTHREAD_RWLOCK_RDLOCK
+ pthread_rwlock_destroy (&lock);
+#else
+ pthread_mutex_destroy (&lock);
+#endif
+}
+
+void
+MoonRWLock::ReadUnlock ()
+{
+#if HAVE_PTHREAD_RWLOCK_RDLOCK
+ pthread_rwlock_unlock (&lock);
+#else
+ pthread_mutex_unlock (&lock);
+#endif
+}
+
+void
+MoonRWLock::WriteUnlock ()
+{
+#if HAVE_PTHREAD_RWLOCK_RDLOCK
+ pthread_rwlock_unlock (&lock);
+#else
+ pthread_mutex_unlock (&lock);
+#endif
+}
+
+void
+MoonRWLock::ReadLock ()
+{
+#if HAVE_PTHREAD_RWLOCK_RDLOCK
+ pthread_rwlock_rdlock (&lock);
+#else
+ pthread_mutex_lock (&lock);
+#endif
+}
+
+void
+MoonRWLock::WriteLock ()
+{
+#if HAVE_PTHREAD_RWLOCK_RDLOCK
+ pthread_rwlock_wrlock (&lock);
+#else
+ pthread_mutex_lock (&lock);
+#endif
+}
+
+MoonCond::MoonCond ()
+{
+ pthread_cond_init (&cond, NULL);
+}
+
+MoonCond::~MoonCond ()
+{
+ pthread_cond_destroy (&cond);
+}
+
+void
+MoonCond::TimedWait (MoonMutex &mutex, timespec *ts)
+{
+ pthread_cond_timedwait (&cond, &mutex.mutex, ts);
+}
+
+void
+MoonCond::Wait (MoonMutex &mutex)
+{
+ pthread_cond_wait (&cond, &mutex.mutex);
+}
+
+void
+MoonCond::Signal ()
+{
+ pthread_cond_signal (&cond);
+}
+
+void
+MoonCond::Broadcast ()
+{
+ pthread_cond_broadcast (&cond);
+}
+
+
+};
+
+#endif
View
158 src/pal/pal-threads-windows.cpp
@@ -0,0 +1,158 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * pal-threads-windows.cpp
+ *
+ * Copyright 2011 Novell, Inc. (http://www.novell.com)
+ *
+ * See the LICENSE file included with the distribution for details.
+ *
+ */
+
+#include "config.h"
+
+#if PAL_THREADS_WINDOWS
+
+#include "pal-threads.h"
+
+namespace Moonlight {
+
+
+MoonTlsKey::MoonTlsKey ()
+{
+ tls_index = TlsAlloc ();
+}
+
+MoonTlsKey::~MoonTlsKey ()
+{
+ TlsFree (tls_index);
+}
+
+bool
+MoonThread::Join ()
+{
+ /* FIXME */
+ return false;
+}
+
+bool
+MoonThread::IsThread (MoonThread* other)
+{
+ /* FIXME */
+}
+
+gpointer
+MoonThread::GetSpecific (MoonTlsKey& key)
+{
+ return TlsGetValue (key.tls_index);
+}
+
+void
+MoonThread::SetSpecific (MoonTlsKey& key, gpointer data)
+{
+ TlsSetValue (key.tls_index, data);
+}
+
+MoonThread::MoonThread (ThreadFunc func, gpointer func_arg)
+ : func (func), func_arg (func_arg)
+{
+}
+
+MoonThread::MoonThread ()
+{
+ /* FIXME */
+}
+
+MoonThread::~MoonThread ()
+{
+}
+
+MoonMutex::MoonMutex (bool recursive)
+{
+ InitializeCriticalSection (&mutex);
+}
+
+MoonMutex::~MoonMutex ()
+{
+ DeleteCriticalSection (&mutex);
+}
+
+void
+MoonMutex::Lock ()
+{
+ EnterCriticalSection (&mutex);
+}
+
+void
+MoonMutex::Unlock ()
+{
+ LeaveCriticalSection (&mutex);
+}
+
+MoonRWLock::MoonRWLock ()
+{
+ InitializeSRWLock (&lock);
+}
+
+MoonRWLock::~MoonRWLock ()
+{
+ DestroySRWLock (&lock);
+}
+
+void
+MoonRWLock::ReadUnlock ()
+{
+ ReleaseSWRLockShared (&lock);
+}
+void
+MoonRWLock::ReadLock ()
+{
+ AcquireSWRLockShared (&lock);
+}
+
+void
+MoonRWLock::WriteUnlock ()
+{
+ ReleaseSWRLockExclusive (&lock);
+}
+void
+MoonRWLock::WriteLock ()
+{
+ AcquireSWRLockExclusive (&lock);
+}
+
+MoonCond::MoonCond ()
+{
+ InitializeConditionVariable (&cond);
+}
+MoonCond::~MoonCond ()
+{
+ DestroyConditionVariable (&cond);
+}
+
+void
+MoonCond::TimedWait (MoonMutex &mutex, timespec *ts)
+{
+ SleepConditionVariableCS (&cond, &mutex.mutex, ts.tv_sec * 1000 + ts.tv_nsec / 100000);
+}
+void
+MoonCond::Wait (MoonMutex &mutex)
+{
+ SleepConditionVariableCS (&cond, &mutex.mutex, INFINITE);
+}
+
+void
+MoonCond::Signal ()
+{
+ WakeConditionVariable (&cond);
+}
+
+void
+MoonCond::Broadcast ()
+{
+ WakeAllConditionVariable (&cond);
+}
+
+};
+
+#endif
View
169 src/pal/pal-threads.cpp
@@ -1,169 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-
-/*
- * pal-threads.cpp
- *
- * Copyright 2011 Novell, Inc. (http://www.novell.com)
- *
- * See the LICENSE file included with the distribution for details.
- *
- */
-
-#include "config.h"
-
-#include "pal-threads.h"
-
-namespace Moonlight {
-
-#if PAL_THREADS_PTHREADS
-
-void*
-MoonThread::Main (void* data)
-{
- MoonThread *moon_thread = (MoonThread*)data;
-
- pthread_setspecific (self_tls, moon_thread);
-
- void* rv = moon_thread->func (moon_thread->func_arg);
-
- pthread_setspecific (self_tls, NULL); // this will invoke the key dtor MoonThread::Cleanup
-
- return rv;
-}
-
-pthread_key_t MoonThread::self_tls = 0;
-
-int
-MoonThread::Start (MoonThread **mt, MoonThread::ThreadFunc func, gpointer arg)
-{
- if (self_tls == 0)
- pthread_key_create (&self_tls, NULL);
-
- MoonThread *moon_thread = new MoonThread (func, arg);
- int result = pthread_create (&moon_thread->pt, NULL, MoonThread::Main, moon_thread);
-
- if (result == 0) {
- *mt = moon_thread;
- }
- else {
- delete moon_thread;
- *mt = NULL;
- }
-
- return result;
-}
-
-int
-MoonThread::StartJoinable (MoonThread **mt, MoonThread::ThreadFunc func, gpointer arg)
-{
- if (self_tls == 0)
- pthread_key_create (&self_tls, NULL);
-
- MoonThread *moon_thread = new MoonThread (func, arg);
-
- pthread_attr_t attribs;
-
- pthread_attr_init (&attribs);
- pthread_attr_setdetachstate (&attribs, PTHREAD_CREATE_JOINABLE);
- int result = pthread_create (&moon_thread->pt, &attribs, MoonThread::Main, moon_thread);
- pthread_attr_destroy (&attribs);
-
- if (result == 0) {
- *mt = moon_thread;
- }
- else {
- delete moon_thread;
- *mt = NULL;
- }
-
- return result;
-}
-
-void
-MoonThread::Cleanup (void *data)
-{
- delete (MoonThread*)data;
-}
-
-MoonThread*
-MoonThread::Self ()
-{
- // FIXME we race here
- if (self_tls == 0)
- pthread_key_create (&self_tls, MoonThread::Cleanup);
-
- MoonThread *mt = (MoonThread*)pthread_getspecific (self_tls);
- if (mt == NULL) {
- // this happens in an unattached thread (the main thread, as well
- // as mono threads that call into moonlight)
- mt = new MoonThread ();
- pthread_setspecific (self_tls, mt);
- }
-
- return mt;
-}
-
-#elif PLATFORM_WINDOWS
-
-unsigned
-MoonThread::Main (void* data)
-{
- MoonThread *moon_thread = (MoonThread*)data;
-
- TlsSetValue (self_tls, moon_thread);
-
- /* XXX nothing done with return value */ moon_thread->func (moon_thread->func_arg);
-
- TlsSetValue (self_tls, NULL);
-
- delete moon_thread;
-
- return 0;
-}
-
-int
-MoonThread::Start (MoonThread **mt, ThreadFunc func, gpointer arg)
-{
- MoonThread *moon_thread = new MoonThread (func, arg);
-
- int result = _beginthreadex (NULL,
- 0,
- MoonThread::Main,
- moon_thread,
- 0,
- &moon_thread->thread_id);
-
- if (result != 0) {
- *mt = moon_thread;
- }
- else {
- delete moon_thread;
- *mt = NULL;
- }
-
- return result;
-}
-
-int
-MoonThread::StartJoinable (MoonThread **thread, ThreadFunc func, gpointer arg)
-{
- return MoonThread::Start (thread, func, arg);
-}
-
-MoonThread*
-MoonThread::Self ()
-{
- MoonThread *mt = (MoonThread*)TlsGetValue (self_tls);
- if (mt == NULL) {
- // this happens in an unattached thread (the main thread, as well
- // as mono threads that call into moonlight)
- mt = new MoonThread (); // FIXME are we going to leak this? there's no tls dtors in win32...
- TlsSetValue (self_tls, mt);
- }
-
- return mt;
-}
-
-#endif
-
-};
View
213 src/pal/pal-threads.h
@@ -7,6 +7,10 @@
#if PAL_THREADS_PTHREADS
#include <pthread.h>
+#elif PLATFORM_WINDOWS
+#error "windows support not finished"
+#else
+#error "config.h not included before #including pal-threads.h"
#endif
namespace Moonlight {
@@ -16,228 +20,113 @@ class MoonCond;
class MoonThread;
class MoonTlsKey;
-#if PAL_THREADS_PTHREADS
-
class MoonTlsKey {
public:
- MoonTlsKey () { pthread_key_create (&tls_key, NULL); }
+ MoonTlsKey ();
+ ~MoonTlsKey ();
private:
friend class MoonThread;
+#if PAL_THREADS_PTHREADS
pthread_key_t tls_key;
+#elif PLATFORM_WINDOWS
+ DWORD tls_index;
+#endif
};
class MoonThread {
public:
typedef gpointer (*ThreadFunc) (gpointer);
- bool Join () { return pthread_join (pt, NULL); }
+ bool Join ();
static int Start (MoonThread **thread, ThreadFunc func, gpointer arg = NULL);
static int StartJoinable (MoonThread **thread, ThreadFunc func, gpointer arg = NULL);
- static bool IsThread (MoonThread* other) { return pthread_equal (pthread_self(), other->pt); }
+ static bool IsThread (MoonThread* other);
static MoonThread* Self ();
- static gpointer GetSpecific (MoonTlsKey& key) { return (gpointer)pthread_getspecific (key.tls_key); }
- static void SetSpecific (MoonTlsKey& key, gpointer data) { pthread_setspecific (key.tls_key, data); }
+ static gpointer GetSpecific (MoonTlsKey& key);
+ static void SetSpecific (MoonTlsKey& key, gpointer data);
private:
- pthread_t pt;
- static pthread_key_t self_tls;
ThreadFunc func;
gpointer func_arg;
- MoonThread (ThreadFunc func, gpointer func_arg) : func (func), func_arg (func_arg) {}
- MoonThread () { pt = pthread_self (); }
+ MoonThread (ThreadFunc func, gpointer func_arg);
+ MoonThread ();
- ~MoonThread () { }
+ ~MoonThread ();
- static void Cleanup (void *data);
+#if PAL_THREADS_PTHREADS
+ pthread_t pt;
+ static pthread_key_t self_tls;
static void* Main (void* data);
+ static void Cleanup (void *data);
+#elif PLATFORM_WINDOWS
+ static unsigned int Main (void* data);
+#endif
};
class MoonMutex {
public:
- MoonMutex (bool recursive = false) {
- if (!recursive) {
- pthread_mutex_init (&mutex, NULL);
- }
- else {
- pthread_mutexattr_t mta;
- pthread_mutexattr_init (&mta);
- pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE);
- pthread_mutex_init (&mutex, &mta);
- pthread_mutexattr_destroy (&mta);
- }
- }
- ~MoonMutex () { pthread_mutex_destroy (&mutex); }
-
- void Lock () { pthread_mutex_lock (&mutex); }
- void Unlock () { pthread_mutex_unlock (&mutex); }
+ MoonMutex (bool recursive = false);
+ ~MoonMutex ();
+
+ void Lock ();
+ void Unlock ();
private:
friend class MoonCond;
+#if PAL_THREADS_PTHREADS
pthread_mutex_t mutex;
+#elif PLATFORM_WINDOWS
+ CRITICAL_SECTION mutex;
+#endif
};
class MoonRWLock {
public:
- MoonRWLock () {
-#if HAVE_PTHREAD_RWLOCK_RDLOCK
- pthread_rwlock_init (&lock, NULL);
-#else
- pthread_mutex_init (&lock, NULL);
-#endif
- }
-
- ~MoonRWLock () {
-#if HAVE_PTHREAD_RWLOCK_RDLOCK
- pthread_rwlock_destroy (&lock);
-#else
- pthread_mutex_destroy (&lock);
-#endif
- }
-
- void ReadUnlock () {
-#if HAVE_PTHREAD_RWLOCK_RDLOCK
- pthread_rwlock_unlock (&lock);
-#else
- pthread_mutex_unlock (&lock);
-#endif
- }
+ MoonRWLock ();
+ ~MoonRWLock ();
- void WriteUnlock () {
-#if HAVE_PTHREAD_RWLOCK_RDLOCK
- pthread_rwlock_unlock (&lock);
-#else
- pthread_mutex_unlock (&lock);
-#endif
- }
+ void ReadLock ();
+ void ReadUnlock ();
- void ReadLock () {
-#if HAVE_PTHREAD_RWLOCK_RDLOCK
- pthread_rwlock_rdlock (&lock);
-#else
- pthread_mutex_lock (&lock);
-#endif
- }
-
- void WriteLock () {
-#if HAVE_PTHREAD_RWLOCK_RDLOCK
- pthread_rwlock_wrlock (&lock);
-#else
- pthread_mutex_lock (&lock);
-#endif
- }
+ void WriteUnlock ();
+ void WriteLock ();
private:
+#if PAL_THREADS_PTHREADS
#if HAVE_PTHREAD_RWLOCK_RDLOCK
pthread_rwlock_t lock;
#else
pthread_mutex_t lock;
#endif
-
-};
-
-class MoonCond {
-public:
-
- MoonCond () { pthread_cond_init (&cond, NULL); }
- ~MoonCond () { pthread_cond_destroy (&cond); }
-
- void TimedWait (MoonMutex &mutex, timespec *ts) { pthread_cond_timedwait (&cond, &mutex.mutex, ts); }
- void Wait (MoonMutex &mutex) { pthread_cond_wait (&cond, &mutex.mutex); }
- void Signal () { pthread_cond_signal (&cond); }
- void Broadcast () { pthread_cond_broadcast (&cond); }
-
-private:
- pthread_cond_t cond;
-};
-
#elif PLATFORM_WINDOWS
-
-class MoonTlsKey {
-public:
- MoonTlsKey () { tls_index = TlsAlloc (); }
-
- ~MoonTlsKey () { TlsFree (tls_index); }
-private:
- friend class MoonThread;
- DWORD tls_index;
-};
-
-class MoonThread {
-public:
- typedef gpointer (*ThreadFunc) (gpointer);
-
- bool Join () { /* FIXME */ }
-
- static int Start (MoonThread **thread, ThreadFunc func, gpointer arg = NULL);
- static int StartJoinable (MoonThread **thread, ThreadFunc func, gpointer arg = NULL);
-
- static bool IsThread (MoonThread* other) { /* FIXME */ }
-
- static MoonThread* Self ();
-
- static gpointer GetSpecific (MoonTlsKey& key) { return TlsGetValue (key.tls_index); }
- static void SetSpecific (MoonTlsKey& key, gpointer data) { TlsSetValue (key.tls_index, data); }
-
-private:
- MoonThread (ThreadFunc func, gpointer func_arg) : func (func), func_arg (func_arg) {}
- MoonThread () { /* FIXME */ }
-
- ~MoonThread () { }
-
- static void Cleanup (void *data);
- static unsigned int Main (void* data);
-};
-
-class MoonMutex {
-public:
- MoonMutex (bool recursive = false) { InitializeCriticalSection (&mutex); }
- ~MoonMutex () { DeleteCriticalSection (&mutex); }
-
- void Lock () { EnterCriticalSection (&mutex); }
- void Unlock () { LeaveCriticalSection (&mutex); }
-
-private:
- friend class MoonCond;
- CRITICAL_SECTION mutex;
-};
-
-class MoonRWLock {
-public:
- MoonRWLock () { InitializeSRWLock (&lock); }
-
- ~MoonRWLock () { DestroySRWLock (&lock); }
-
- void ReadUnlock () { ReleaseSWRLockShared (&lock); }
- void ReadLock () { AcquireSWRLockShared (&lock); }
-
- void WriteUnlock () { ReleaseSWRLockExclusive (&lock); }
- void WriteLock () { AcquireSWRLockExclusive (&lock); }
-
-private:
SRWLOCK lock;
+#endif
};
class MoonCond {
public:
- MoonCond () { InitializeConditionVariable (&cond); }
- ~MoonCond () { DestroyConditionVariable (&cond); }
- void TimedWait (MoonMutex &mutex, timespec *ts) { SleepConditionVariableCS (&cond, &mutex.mutex, ts.tv_sec * 1000 + ts.tv_nsec / 100000); }
- void Wait (MoonMutex &mutex) { SleepConditionVariableCS (&cond, &mutex.mutex, INFINITE); }
+ MoonCond ();
+ ~MoonCond ();
- void Signal () { WakeConditionVariable (&cond); }
- void Broadcast () { WakeAllConditionVariable (&cond); }
+ void TimedWait (MoonMutex &mutex, timespec *ts);
+ void Wait (MoonMutex &mutex);
+ void Signal ();
+ void Broadcast ();
private:
+#if PAL_THREADS_PTHREADS
+ pthread_cond_t cond;
+#elif PLATFORM_WINDOWS
CONDITION_VARIABLE cond;
+#endif
};
-#endif
};
View
2  test/harness/shocker/texthelpers.cpp
@@ -11,8 +11,8 @@
*
*/
+#include <config.h>
#include <gtk/gtk.h>
-#include <pthread.h>
#include <string.h>
#include "debug.h"
Please sign in to comment.
Something went wrong with that request. Please try again.