ia64/xen-unstable

changeset 17708:f05795acfca9

stubdom: fix and clean pthread minimal support

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri May 23 09:35:43 2008 +0100 (2008-05-23)
parents 90c37c32182c
children fbf09143c2e5
files extras/mini-os/include/posix/pthread.h
line diff
     1.1 --- a/extras/mini-os/include/posix/pthread.h	Fri May 23 09:35:23 2008 +0100
     1.2 +++ b/extras/mini-os/include/posix/pthread.h	Fri May 23 09:35:43 2008 +0100
     1.3 @@ -1,18 +1,56 @@
     1.4  #ifndef _POSIX_PTHREAD_H
     1.5  #define _POSIX_PTHREAD_H
     1.6  
     1.7 +#include <stdlib.h>
     1.8 +
     1.9  /* Let's be single-threaded for now.  */
    1.10  
    1.11 -typedef void *pthread_key_t;
    1.12 -typedef struct {} pthread_mutex_t, pthread_once_t;
    1.13 +typedef struct {
    1.14 +    void *ptr;
    1.15 +} *pthread_key_t;
    1.16 +static inline int pthread_key_create(pthread_key_t *key, void (*destr_function)(void*))
    1.17 +{
    1.18 +    *key = malloc(sizeof(**key));
    1.19 +    (*key)->ptr = NULL;
    1.20 +    return 0;
    1.21 +}
    1.22 +static inline int pthread_setspecific(pthread_key_t key, const void *pointer)
    1.23 +{
    1.24 +    key->ptr = (void*) pointer;
    1.25 +    return 0;
    1.26 +}
    1.27 +static inline void *pthread_getspecific(pthread_key_t key)
    1.28 +{
    1.29 +    return key->ptr;
    1.30 +}
    1.31 +static inline int pthread_key_delete(pthread_key_t key)
    1.32 +{
    1.33 +    free(key);
    1.34 +    return 0;
    1.35 +}
    1.36 +
    1.37 +
    1.38 +
    1.39 +typedef struct {} pthread_mutex_t;
    1.40  #define PTHREAD_MUTEX_INITIALIZER {}
    1.41 -#define PTHREAD_ONCE_INIT {}
    1.42  static inline int pthread_mutex_lock(pthread_mutex_t *mutex) { return 0; }
    1.43  static inline int pthread_mutex_unlock(pthread_mutex_t *mutex) { return 0; }
    1.44 -static inline int pthread_key_create(pthread_key_t *key, void (*destr_function)(void*)) { *key = NULL; return 0; }
    1.45 -static inline int pthread_setspecific(pthread_key_t *key, const void *pointer) { *key = (void*) pointer; return 0; }
    1.46 -static inline void *pthread_getspecific(pthread_key_t *key) { return *key; }
    1.47 -static inline int pthread_once(pthread_once_t *once_control, void (*init_routine)(void)) { init_routine(); return 0; }
    1.48 +
    1.49 +
    1.50 +
    1.51 +typedef struct {
    1.52 +    int done;
    1.53 +} pthread_once_t;
    1.54 +#define PTHREAD_ONCE_INIT { 0 }
    1.55 +
    1.56 +static inline int pthread_once(pthread_once_t *once_control, void (*init_routine)(void))
    1.57 +{
    1.58 +    if (!once_control->done) {
    1.59 +        once_control->done = 1;
    1.60 +        init_routine();
    1.61 +    }
    1.62 +    return 0;
    1.63 +}
    1.64  
    1.65  #define __thread
    1.66