WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] stubdom: fix and clean pthread minimal support

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] stubdom: fix and clean pthread minimal support
From: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>
Date: Thu, 22 May 2008 16:10:30 +0100
Delivery-date: Thu, 22 May 2008 08:11:26 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Mail-followup-to: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.12-2006-07-14
stubdom: fix and clean pthread minimal support

Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>

diff -r f4a293cbec1b extras/mini-os/include/posix/pthread.h
--- a/extras/mini-os/include/posix/pthread.h    Thu May 22 14:28:40 2008 +0100
+++ b/extras/mini-os/include/posix/pthread.h    Thu May 22 16:08:29 2008 +0100
@@ -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
 

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] stubdom: fix and clean pthread minimal support, Samuel Thibault <=