summaryrefslogtreecommitdiff
path: root/src/libmowgli/thread
diff options
context:
space:
mode:
Diffstat (limited to 'src/libmowgli/thread')
-rw-r--r--src/libmowgli/thread/mutex.c35
-rw-r--r--src/libmowgli/thread/mutex.h16
-rw-r--r--src/libmowgli/thread/null_mutexops.c18
-rw-r--r--src/libmowgli/thread/posix_mutexops.c81
-rw-r--r--src/libmowgli/thread/thread.h20
-rw-r--r--src/libmowgli/thread/win32_mutexops.c30
6 files changed, 95 insertions, 105 deletions
diff --git a/src/libmowgli/thread/mutex.c b/src/libmowgli/thread/mutex.c
index 1d5d480..c60902a 100644
--- a/src/libmowgli/thread/mutex.c
+++ b/src/libmowgli/thread/mutex.c
@@ -25,8 +25,6 @@
#if defined(_WIN32)
extern const mowgli_mutex_ops_t _mowgli_win32_mutex_ops;
-#elif defined(_sun) || defined(_sco)
-extern const mowgli_mutex_ops_t _mowgli_sun_mutex_ops;
#else
extern const mowgli_mutex_ops_t _mowgli_posix_mutex_ops;
#endif
@@ -35,7 +33,8 @@ extern const mowgli_mutex_ops_t _mowgli_null_mutex_ops;
static const mowgli_mutex_ops_t *_mowgli_mutex_ops = NULL;
-static inline const mowgli_mutex_ops_t *get_mutex_platform(void)
+static inline const mowgli_mutex_ops_t *
+get_mutex_platform(void)
{
/* allow for threading policy to set custom mutex ops */
if (_mowgli_mutex_ops != NULL)
@@ -45,10 +44,6 @@ static inline const mowgli_mutex_ops_t *get_mutex_platform(void)
return &_mowgli_win32_mutex_ops;
#endif
-#if defined(_sun) || defined(_sco)
- return &_mowgli_sun_mutex_ops;
-#endif
-
#if !defined(MOWGLI_FEATURE_HAVE_NATIVE_MUTEXES)
return &_mowgli_posix_mutex_ops;
#endif
@@ -56,14 +51,17 @@ static inline const mowgli_mutex_ops_t *get_mutex_platform(void)
return &_mowgli_null_mutex_ops;
}
-mowgli_mutex_t *mowgli_mutex_create(void)
+mowgli_mutex_t *
+mowgli_mutex_create(void)
{
mowgli_mutex_t *mutex = mowgli_alloc(sizeof(mowgli_mutex_t));
return_val_if_fail(mutex != NULL, NULL);
if (mowgli_mutex_init(mutex))
+ {
return mutex;
+ }
else
{
mowgli_free(mutex);
@@ -71,7 +69,8 @@ mowgli_mutex_t *mowgli_mutex_create(void)
}
}
-int mowgli_mutex_init(mowgli_mutex_t *mutex)
+int
+mowgli_mutex_init(mowgli_mutex_t *mutex)
{
return_val_if_fail(mutex != NULL, -1);
@@ -80,7 +79,8 @@ int mowgli_mutex_init(mowgli_mutex_t *mutex)
return mutex->ops->mutex_create(mutex);
}
-int mowgli_mutex_lock(mowgli_mutex_t *mutex)
+int
+mowgli_mutex_lock(mowgli_mutex_t *mutex)
{
return_val_if_fail(mutex != NULL, -1);
return_val_if_fail(mutex->ops != NULL, -1);
@@ -88,7 +88,8 @@ int mowgli_mutex_lock(mowgli_mutex_t *mutex)
return mutex->ops->mutex_lock(mutex);
}
-int mowgli_mutex_trylock(mowgli_mutex_t *mutex)
+int
+mowgli_mutex_trylock(mowgli_mutex_t *mutex)
{
return_val_if_fail(mutex != NULL, -1);
return_val_if_fail(mutex->ops != NULL, -1);
@@ -96,7 +97,8 @@ int mowgli_mutex_trylock(mowgli_mutex_t *mutex)
return mutex->ops->mutex_trylock(mutex);
}
-int mowgli_mutex_unlock(mowgli_mutex_t *mutex)
+int
+mowgli_mutex_unlock(mowgli_mutex_t *mutex)
{
return_val_if_fail(mutex != NULL, -1);
return_val_if_fail(mutex->ops != NULL, -1);
@@ -104,7 +106,8 @@ int mowgli_mutex_unlock(mowgli_mutex_t *mutex)
return mutex->ops->mutex_unlock(mutex);
}
-int mowgli_mutex_uninit(mowgli_mutex_t *mutex)
+int
+mowgli_mutex_uninit(mowgli_mutex_t *mutex)
{
return_val_if_fail(mutex != NULL, -1);
return_val_if_fail(mutex->ops != NULL, -1);
@@ -112,7 +115,8 @@ int mowgli_mutex_uninit(mowgli_mutex_t *mutex)
return mutex->ops->mutex_destroy(mutex);
}
-void mowgli_mutex_destroy(mowgli_mutex_t *mutex)
+void
+mowgli_mutex_destroy(mowgli_mutex_t *mutex)
{
return_if_fail(mutex != NULL);
@@ -120,7 +124,8 @@ void mowgli_mutex_destroy(mowgli_mutex_t *mutex)
mowgli_free(mutex);
}
-void mowgli_mutex_set_policy(mowgli_thread_policy_t policy)
+void
+mowgli_mutex_set_policy(mowgli_thread_policy_t policy)
{
switch (policy)
{
diff --git a/src/libmowgli/thread/mutex.h b/src/libmowgli/thread/mutex.h
index f08013d..94ead78 100644
--- a/src/libmowgli/thread/mutex.h
+++ b/src/libmowgli/thread/mutex.h
@@ -28,17 +28,18 @@
# include <thread.h>
# include <synch.h>
# define MOWGLI_FEATURE_HAVE_NATIVE_MUTEXES
-# define MOWGLI_NATIVE_MUTEX_DECL(name) mutex_t (name)
+# define MOWGLI_NATIVE_MUTEX_DECL(name) mutex_t(name)
#elif defined MOWGLI_OS_WIN
# define MOWGLI_FEATURE_HAVE_NATIVE_MUTEXES
-# define MOWGLI_NATIVE_MUTEX_DECL(name) HANDLE (name)
+# define MOWGLI_NATIVE_MUTEX_DECL(name) HANDLE(name)
#else
# include <pthread.h>
#endif
typedef struct mowgli_mutex_ mowgli_mutex_t;
-typedef struct {
+typedef struct
+{
int (*mutex_create)(mowgli_mutex_t *mutex);
int (*mutex_lock)(mowgli_mutex_t *mutex);
int (*mutex_trylock)(mowgli_mutex_t *mutex);
@@ -46,7 +47,8 @@ typedef struct {
int (*mutex_destroy)(mowgli_mutex_t *mutex);
} mowgli_mutex_ops_t;
-struct mowgli_mutex_ {
+struct mowgli_mutex_
+{
#ifdef MOWGLI_FEATURE_HAVE_NATIVE_MUTEXES
MOWGLI_NATIVE_MUTEX_DECL(mutex);
#else
@@ -60,7 +62,7 @@ struct mowgli_mutex_ {
#endif
mowgli_mutex_t *mowgli_mutex_create(void);
-int mowgli_mutex_init(mowgli_mutex_t* mutex);
+int mowgli_mutex_init(mowgli_mutex_t *mutex);
int mowgli_mutex_lock(mowgli_mutex_t *mutex);
int mowgli_mutex_trylock(mowgli_mutex_t *mutex);
int mowgli_mutex_unlock(mowgli_mutex_t *mutex);
@@ -70,10 +72,10 @@ void mowgli_mutex_destroy(mowgli_mutex_t *mutex);
void mowgli_mutex_set_policy(mowgli_thread_policy_t policy);
/* simple dispatch function to set the ops up for the various subsystems. */
-static inline void mowgli_thread_set_policy(mowgli_thread_policy_t policy)
+static inline void
+mowgli_thread_set_policy(mowgli_thread_policy_t policy)
{
mowgli_mutex_set_policy(policy);
}
#endif
-
diff --git a/src/libmowgli/thread/null_mutexops.c b/src/libmowgli/thread/null_mutexops.c
index 2750add..7a84c01 100644
--- a/src/libmowgli/thread/null_mutexops.c
+++ b/src/libmowgli/thread/null_mutexops.c
@@ -23,32 +23,38 @@
#include "mowgli.h"
-static int mowgli_null_mutex_create(mowgli_mutex_t *mutex)
+static int
+mowgli_null_mutex_create(mowgli_mutex_t *mutex)
{
return 0;
}
-static int mowgli_null_mutex_lock(mowgli_mutex_t *mutex)
+static int
+mowgli_null_mutex_lock(mowgli_mutex_t *mutex)
{
return 0;
}
-static int mowgli_null_mutex_trylock(mowgli_mutex_t *mutex)
+static int
+mowgli_null_mutex_trylock(mowgli_mutex_t *mutex)
{
return 0;
}
-static int mowgli_null_mutex_unlock(mowgli_mutex_t *mutex)
+static int
+mowgli_null_mutex_unlock(mowgli_mutex_t *mutex)
{
return 0;
}
-static int mowgli_null_mutex_destroy(mowgli_mutex_t *mutex)
+static int
+mowgli_null_mutex_destroy(mowgli_mutex_t *mutex)
{
return 0;
}
-const mowgli_mutex_ops_t _mowgli_null_mutex_ops = {
+const mowgli_mutex_ops_t _mowgli_null_mutex_ops =
+{
.mutex_create = mowgli_null_mutex_create,
.mutex_lock = mowgli_null_mutex_lock,
.mutex_trylock = mowgli_null_mutex_trylock,
diff --git a/src/libmowgli/thread/posix_mutexops.c b/src/libmowgli/thread/posix_mutexops.c
index 5fb64e9..dbb7be2 100644
--- a/src/libmowgli/thread/posix_mutexops.c
+++ b/src/libmowgli/thread/posix_mutexops.c
@@ -26,83 +26,48 @@
#ifndef _WIN32
/*************
- * This implements native Sun/UnixWare threads. Some other SVR4-based
- * environments attempted to make work-alikes, but those aren't guaranteed
- * to be supported. This should work on SunOS 5.2 and UnixWare 7, and
- * anything later.
- *************/
-#if defined(__sun) || defined(__sco)
-
-static int mowgli_sun_mutex_create(mowgli_mutex_t *mutex)
-{
- return mutex_init(&mutex->mutex, USYNC_THREAD, NULL);
-}
-
-static int mowgli_sun_mutex_lock(mowgli_mutex_t *mutex)
-{
- return mutex_lock(&mutex->mutex);
-}
-
-static int mowgli_sun_mutex_trylock(mowgli_mutex_t *mutex)
-{
- return mutex_trylock(&mutex->mutex);
-}
-
-static int mowgli_sun_mutex_unlock(mowgli_mutex_t *mutex)
-{
- return mutex_unlock(&mutex->mutex);
-}
-
-static int mowgli_sun_mutex_destroy(mowgli_mutex_t *mutex)
-{
- return mutex_destroy(&mutex->mutex);
-}
-
-const mowgli_mutex_ops_t _mowgli_sun_mutex_ops = {
- .mutex_create = mowgli_sun_mutex_create,
- .mutex_lock = mowgli_sun_mutex_lock,
- .mutex_trylock = mowgli_sun_mutex_trylock,
- .mutex_unlock = mowgli_sun_mutex_unlock,
- .mutex_destroy = mowgli_sun_mutex_destroy,
-};
-
-/*************
- * This "default" implementation uses pthreads. Care has been taken to
- * ensure it runs on POSIX 1003.4a (draft 4, aka DECthreads, aka what OSF/1,
- * Tru64, Ultrix, CMU Mach, and HP-UX use) as well as POSIX 1003.1c-1995.
- * As long as you don't try playing with the pthread_attr module or the
- * scheduler routines (which are non-standard and broken anyway, IMO) then
- * it should be relatively easy to maintian d4 compatibility without
- * sacrificing any functionality.
- *************/
-#elif !defined(MOWGLI_FEATURE_HAVE_NATIVE_MUTEXES)
-
-static int mowgli_posix_mutex_create(mowgli_mutex_t *mutex)
+* This "default" implementation uses pthreads. Care has been taken to
+* ensure it runs on POSIX 1003.4a (draft 4, aka DECthreads, aka what OSF/1,
+* Tru64, Ultrix, CMU Mach, and HP-UX use) as well as POSIX 1003.1c-1995.
+* As long as you don't try playing with the pthread_attr module or the
+* scheduler routines (which are non-standard and broken anyway, IMO) then
+* it should be relatively easy to maintian d4 compatibility without
+* sacrificing any functionality.
+*************/
+# if !defined(MOWGLI_FEATURE_HAVE_NATIVE_MUTEXES)
+
+static int
+mowgli_posix_mutex_create(mowgli_mutex_t *mutex)
{
return pthread_mutex_init(&mutex->mutex, NULL);
}
-static int mowgli_posix_mutex_lock(mowgli_mutex_t *mutex)
+static int
+mowgli_posix_mutex_lock(mowgli_mutex_t *mutex)
{
return pthread_mutex_lock(&mutex->mutex);
}
-static int mowgli_posix_mutex_trylock(mowgli_mutex_t *mutex)
+static int
+mowgli_posix_mutex_trylock(mowgli_mutex_t *mutex)
{
return pthread_mutex_trylock(&mutex->mutex);
}
-static int mowgli_posix_mutex_unlock(mowgli_mutex_t *mutex)
+static int
+mowgli_posix_mutex_unlock(mowgli_mutex_t *mutex)
{
return pthread_mutex_unlock(&mutex->mutex);
}
-static int mowgli_posix_mutex_destroy(mowgli_mutex_t *mutex)
+static int
+mowgli_posix_mutex_destroy(mowgli_mutex_t *mutex)
{
return pthread_mutex_destroy(&mutex->mutex);
}
-const mowgli_mutex_ops_t _mowgli_posix_mutex_ops = {
+const mowgli_mutex_ops_t _mowgli_posix_mutex_ops =
+{
.mutex_create = mowgli_posix_mutex_create,
.mutex_lock = mowgli_posix_mutex_lock,
.mutex_trylock = mowgli_posix_mutex_trylock,
@@ -110,6 +75,6 @@ const mowgli_mutex_ops_t _mowgli_posix_mutex_ops = {
.mutex_destroy = mowgli_posix_mutex_destroy,
};
-#endif
+# endif
#endif
diff --git a/src/libmowgli/thread/thread.h b/src/libmowgli/thread/thread.h
index f063217..88939eb 100644
--- a/src/libmowgli/thread/thread.h
+++ b/src/libmowgli/thread/thread.h
@@ -28,15 +28,20 @@
#ifdef MOWGLI_OS_UNIX_TYPE
# include <thread.h>
# define MOWGLI_FEATURE_HAVE_NATIVE_THREADS
-# define MOWGLI_NATIVE_THREAD_DECL(name) thread_t (name)
+# ifdef MOWGLI_OS_THREADS_SOLARIS
+# define MOWGLI_NATIVE_THREAD_DECL(name) pthread_t(name)
+# else
+# define MOWGLI_NATIVE_THREAD_DECL(name) thread_t(name)
+# endif
#elif defined MOWGLI_OS_WIN
# define MOWGLI_FEATURE_HAVE_NATIVE_THREADS
-# define MOWGLI_NATIVE_THREAD_DECL(name) HANDLE (name)
+# define MOWGLI_NATIVE_THREAD_DECL(name) HANDLE(name)
#else
# include <pthread.h>
#endif
-typedef struct {
+typedef struct
+{
#ifdef MOWGLI_FEATURE_HAVE_NATIVE_THREADS
MOWGLI_NATIVE_THREAD_DECL(thread);
#else
@@ -55,10 +60,11 @@ typedef void *(*mowgli_thread_start_fn_t)(mowgli_thread_t *thread, void *userdat
* portability. Creating, ending, killing and cleanup functions are presently implemented,
* and cover approximately 99.999% of uses of thread APIs. --nenolod
*/
-typedef struct {
+typedef struct
+{
int (*thread_create)(mowgli_thread_t *thread, mowgli_thread_start_fn_t start_fn, void *userdata);
void (*thread_exit)(mowgli_thread_t *thread);
- void *(*thread_join)(mowgli_thread_t *thread);
+ void *(*thread_join)(mowgli_thread_t * thread);
void (*thread_kill)(mowgli_thread_t *thread);
void (*thread_destroy)(mowgli_thread_t *thread);
} mowgli_thread_ops_t;
@@ -69,10 +75,10 @@ void *mowgli_thread_join(mowgli_thread_t *thread);
void mowgli_thread_kill(mowgli_thread_t *thread);
void mowgli_thread_destroy(mowgli_thread_t *thread);
-typedef enum {
+typedef enum
+{
MOWGLI_THREAD_POLICY_DEFAULT,
MOWGLI_THREAD_POLICY_DISABLED,
} mowgli_thread_policy_t;
#endif
-
diff --git a/src/libmowgli/thread/win32_mutexops.c b/src/libmowgli/thread/win32_mutexops.c
index 486992f..1e1bf5f 100644
--- a/src/libmowgli/thread/win32_mutexops.c
+++ b/src/libmowgli/thread/win32_mutexops.c
@@ -23,47 +23,53 @@
#include "mowgli.h"
-
/*************
- * This Windows implementation is guaranteed to work on Windows 95,
- * Windows NT 4, and anything later.
- *************/
+* This Windows implementation is guaranteed to work on Windows 95,
+* Windows NT 4, and anything later.
+*************/
#if defined(_WIN32)
-static int mowgli_win32_mutex_create(mowgli_mutex_t *mutex)
+static int
+mowgli_win32_mutex_create(mowgli_mutex_t *mutex)
{
mutex->mutex = CreateMutex(NULL, FALSE, NULL);
- if(mutex->mutex == NULL)
+
+ if (mutex->mutex == NULL)
return GetLastError();
return 0;
}
-static int mowgli_win32_mutex_lock(mowgli_mutex_t *mutex)
+static int
+mowgli_win32_mutex_lock(mowgli_mutex_t *mutex)
{
return WaitForSingleObject(mutex->mutex, INFINITE);
}
-static int mowgli_win32_mutex_trylock(mowgli_mutex_t *mutex)
+static int
+mowgli_win32_mutex_trylock(mowgli_mutex_t *mutex)
{
return WaitForSingleObject(mutex->mutex, 0);
}
-static int mowgli_win32_mutex_unlock(mowgli_mutex_t *mutex)
+static int
+mowgli_win32_mutex_unlock(mowgli_mutex_t *mutex)
{
- if(ReleaseMutex(mutex->mutex) != 0)
+ if (ReleaseMutex(mutex->mutex) != 0)
return 0;
return GetLastError();
}
-static int mowgli_win32_mutex_destroy(mowgli_mutex_t *mutex)
+static int
+mowgli_win32_mutex_destroy(mowgli_mutex_t *mutex)
{
CloseHandle(mutex->mutex);
return 0;
}
-const mowgli_mutex_ops_t _mowgli_win32_mutex_ops = {
+const mowgli_mutex_ops_t _mowgli_win32_mutex_ops =
+{
.mutex_create = mowgli_win32_mutex_create,
.mutex_lock = mowgli_win32_mutex_lock,
.mutex_trylock = mowgli_win32_mutex_trylock,