diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2012-11-25 14:36:20 +0000 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2012-11-25 14:36:20 +0000 |
commit | c3649a2def02c41d837ae1f79dda729ccb91e677 (patch) | |
tree | bea46dff212fdef977fe9094a70a939e8cc21885 /src/include/threads.h | |
download | trousers-c3649a2def02c41d837ae1f79dda729ccb91e677.tar.gz |
Imported Upstream version 0.3.9upstream/0.3.9upstream
Diffstat (limited to 'src/include/threads.h')
-rw-r--r-- | src/include/threads.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/include/threads.h b/src/include/threads.h new file mode 100644 index 0000000..3c57144 --- /dev/null +++ b/src/include/threads.h @@ -0,0 +1,52 @@ + +/* + * Licensed Materials - Property of IBM + * + * trousers - An open source TCG Software Stack + * + * (C) Copyright International Business Machines Corp. 2006 + * + */ + +#ifndef __THREADS_H__ +#define __THREADS_H__ + +#ifdef HAVE_PTHREAD_H + +#include <pthread.h> + +/* mutex abstractions */ +#define MUTEX_INIT(m) pthread_mutex_init(&m, NULL) +#define MUTEX_LOCK(m) pthread_mutex_lock(&m) +#define MUTEX_UNLOCK(m) pthread_mutex_unlock(&m) +#define MUTEX_DECLARE(m) pthread_mutex_t m +#define MUTEX_DECLARE_INIT(m) pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER +#define MUTEX_DECLARE_EXTERN(m) extern pthread_mutex_t m + +/* condition variable abstractions */ +#define COND_DECLARE(c) pthread_cond_t c +#define COND_INIT(c) pthread_cond_init(&c, NULL) +#define COND_VAR pthread_cond_t +#define COND_WAIT(c,m) pthread_cond_wait(c,m) +#define COND_SIGNAL(c) pthread_cond_signal(c) + +/* thread abstractions */ +#define THREAD_ID ((THREAD_TYPE)pthread_self()) +#define THREAD_TYPE pthread_t +#define THREAD_JOIN pthread_join +#define THREAD_DETACH pthread_detach +#define THREAD_ATTR_DECLARE(a) pthread_attr_t a +#define THREAD_ATTR_INIT(a) pthread_attr_init(&a) +#define THREAD_ATTR_SETJOINABLE(a) pthread_attr_setdetachstate(&a, PTHREAD_CREATE_JOINABLE) +#define THREAD_EXIT pthread_exit +#define THREAD_CREATE(a,b,c,d) pthread_create(a,b,c,d) +#define THREAD_SET_SIGNAL_MASK pthread_sigmask +#define THREAD_NULL (THREAD_TYPE *)0 + +#else + +#error No threading library defined! (Cannot find pthread.h) + +#endif + +#endif |