summaryrefslogtreecommitdiff
path: root/src/include/threads.h
blob: 3c57144d5015c44aeb2330b97550c25c5cb12a99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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