#define LIBBARRELFISH_THREAD_SYNC_H
#include <stdint.h>
+#include <limits.h> // for INT_MAX
+
#include <barrelfish_kpi/spinlocks_arch.h>
/// A thread of execution
{ 0, (struct thread *)NULL, 0 }
#endif
+typedef int thread_once_t;
+#define THREAD_ONCE_INIT INT_MAX
+
#endif
#define LIBBARRELFISH_THREADS_H
#include <assert.h>
-#include <limits.h>
#include <sys/cdefs.h>
#include <barrelfish/caddr.h> // for struct capref.
uintptr_t thread_get_id(struct thread *t);
void thread_set_id(uintptr_t id);
-typedef int thread_once_t;
-#define THREAD_ONCE_INIT INT_MAX
-
extern __thread thread_once_t thread_once_local_epoch;
extern void thread_once_internal(thread_once_t *control, void (*func)(void));
#include <sched.h>
#include <time.h>
+#include <barrelfish/thread_sync.h> // for THREAD_ONCE_INIT
+
/*
* Run-time invariant values:
*/
#define PTHREAD_CANCELED ((void *) 1)
/*
- * Flags for once initialization.
- */
-#define PTHREAD_NEEDS_INIT 0
-#define PTHREAD_DONE_INIT 1
-
-/*
* Static once initialization values.
*/
-#define PTHREAD_ONCE_INIT { PTHREAD_NEEDS_INIT, NULL }
+#define PTHREAD_ONCE_INIT THREAD_ONCE_INIT
/*
* Static initialization values.
#ifndef _SYS__PTHREADTYPES_H_
#define _SYS__PTHREADTYPES_H_
+#include <barrelfish/thread_sync.h> // for thread_once_t
+
/*
* Forward structure definitions.
*
struct pthread_cond_attr;
struct pthread_mutex;
struct pthread_mutex_attr;
-struct pthread_once;
struct pthread_rwlock;
struct pthread_rwlockattr;
struct pthread_barrier;
typedef struct pthread_cond *pthread_cond_t;
typedef struct pthread_cond_attr *pthread_condattr_t;
typedef int pthread_key_t;
-typedef struct pthread_once pthread_once_t;
+typedef thread_once_t pthread_once_t;
typedef struct pthread_rwlock *pthread_rwlock_t;
typedef struct pthread_rwlockattr *pthread_rwlockattr_t;
typedef struct pthread_barrier *pthread_barrier_t;
typedef void *pthread_addr_t;
typedef void *(*pthread_startroutine_t)(void *);
-/*
- * Once definitions.
- */
-struct pthread_once {
- int state;
- pthread_mutex_t mutex;
-};
-
#endif /* ! _SYS__PTHREADTYPES_H_ */
// "Dynamic Initialization and Destruction with Concurrency"
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2660.htm
-#include <limits.h>
-
#include <barrelfish/threads.h>
/// Protects global_epoch and all thread_once_t writes.
if (ctrl == NULL || init == NULL) {
return EINVAL;
}
-
-
- pthread_mutex_lock(&ctrl->mutex);
-
-
- if (!ctrl->state)
- {
- //pthread_cleanup_push(ptw32_mcs_lock_release, &node);
- (*init)();
- //pthread_cleanup_pop(0);
- ctrl->state = 1;
- }
-
- pthread_mutex_unlock(&ctrl->mutex);
-
+ thread_once(ctrl, init);
return 0;
}