aboutsummaryrefslogtreecommitdiffstats
path: root/extras/mini-os/include/posix
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2008-05-23 09:35:43 +0100
committerKeir Fraser <keir.fraser@citrix.com>2008-05-23 09:35:43 +0100
commit700f9d1bcf634b5a767ac17f509ffee044b57a8b (patch)
tree93b0d3c1d4603b86e3755ae59fcfb688ee30b6d9 /extras/mini-os/include/posix
parent8543c562dd5553e92bb65cf27409551bc795ed52 (diff)
downloadxen-700f9d1bcf634b5a767ac17f509ffee044b57a8b.tar.gz
xen-700f9d1bcf634b5a767ac17f509ffee044b57a8b.tar.bz2
xen-700f9d1bcf634b5a767ac17f509ffee044b57a8b.zip
stubdom: fix and clean pthread minimal support
Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
Diffstat (limited to 'extras/mini-os/include/posix')
-rw-r--r--extras/mini-os/include/posix/pthread.h52
1 files changed, 45 insertions, 7 deletions
diff --git a/extras/mini-os/include/posix/pthread.h b/extras/mini-os/include/posix/pthread.h
index 7e62001e3a..a3a726f0b7 100644
--- a/extras/mini-os/include/posix/pthread.h
+++ b/extras/mini-os/include/posix/pthread.h
@@ -1,18 +1,56 @@
#ifndef _POSIX_PTHREAD_H
#define _POSIX_PTHREAD_H
+#include <stdlib.h>
+
/* Let's be single-threaded for now. */
-typedef void *pthread_key_t;
-typedef struct {} pthread_mutex_t, pthread_once_t;
+typedef struct {
+ void *ptr;
+} *pthread_key_t;
+static inline int pthread_key_create(pthread_key_t *key, void (*destr_function)(void*))
+{
+ *key = malloc(sizeof(**key));
+ (*key)->ptr = NULL;
+ return 0;
+}
+static inline int pthread_setspecific(pthread_key_t key, const void *pointer)
+{
+ key->ptr = (void*) pointer;
+ return 0;
+}
+static inline void *pthread_getspecific(pthread_key_t key)
+{
+ return key->ptr;
+}
+static inline int pthread_key_delete(pthread_key_t key)
+{
+ free(key);
+ return 0;
+}
+
+
+
+typedef struct {} pthread_mutex_t;
#define PTHREAD_MUTEX_INITIALIZER {}
-#define PTHREAD_ONCE_INIT {}
static inline int pthread_mutex_lock(pthread_mutex_t *mutex) { return 0; }
static inline int pthread_mutex_unlock(pthread_mutex_t *mutex) { return 0; }
-static inline int pthread_key_create(pthread_key_t *key, void (*destr_function)(void*)) { *key = NULL; return 0; }
-static inline int pthread_setspecific(pthread_key_t *key, const void *pointer) { *key = (void*) pointer; return 0; }
-static inline void *pthread_getspecific(pthread_key_t *key) { return *key; }
-static inline int pthread_once(pthread_once_t *once_control, void (*init_routine)(void)) { init_routine(); return 0; }
+
+
+
+typedef struct {
+ int done;
+} pthread_once_t;
+#define PTHREAD_ONCE_INIT { 0 }
+
+static inline int pthread_once(pthread_once_t *once_control, void (*init_routine)(void))
+{
+ if (!once_control->done) {
+ once_control->done = 1;
+ init_routine();
+ }
+ return 0;
+}
#define __thread