StarPU Handbook

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
starpu_thread.h
Go to the documentation of this file.
1 /* StarPU --- Runtime system for heterogeneous multicore architectures.
2 *
3 * Copyright (C) 2010, 2012-2014 Université de Bordeaux 1
4 * Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
5 *
6 * StarPU is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or (at
9 * your option) any later version.
10 *
11 * StarPU is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 *
15 * See the GNU Lesser General Public License in COPYING.LGPL for more details.
16 */
17
18 #ifndef __STARPU_THREAD_H__
19 #define __STARPU_THREAD_H__
20
21 #include <starpu_config.h>
22 #ifdef STARPU_SIMGRID
23 #include <xbt/synchro_core.h>
24 #include <msg/msg.h>
25 #elif !defined(_MSC_VER)
26 #include <pthread.h>
27 #endif
28
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #endif
33
34 /*
35 * Encapsulation of the pthread_create function.
36 */
37
38 #ifdef STARPU_SIMGRID
39
40 typedef int starpu_pthread_t;
41 typedef int starpu_pthread_attr_t;
42
43 int starpu_pthread_create_on(char *name, starpu_pthread_t *thread, const starpu_pthread_attr_t *attr, void *(*start_routine) (void *), void *arg, int where);
44 int starpu_pthread_create(starpu_pthread_t *thread, const starpu_pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
45 int starpu_pthread_join(starpu_pthread_t thread, void **retval);
46 int starpu_pthread_attr_init(starpu_pthread_attr_t *attr);
47 int starpu_pthread_attr_destroy(starpu_pthread_attr_t *attr);
48 int starpu_pthread_attr_setdetachstate(starpu_pthread_attr_t *attr, int detachstate);
49
50 #elif !defined(_MSC_VER) /* STARPU_SIMGRID */
51
52 typedef pthread_t starpu_pthread_t;
53 typedef pthread_attr_t starpu_pthread_attr_t;
54
55 #define starpu_pthread_create pthread_create
56 #define starpu_pthread_create_on(name, thread, attr, routine, arg, where) starpu_pthread_create(thread, attr, routine, arg)
57 #define starpu_pthread_join pthread_join
58 #define starpu_pthread_attr_init pthread_attr_init
59 #define starpu_pthread_attr_destroy pthread_attr_destroy
60 #define starpu_pthread_attr_setdetachstate pthread_attr_setdetachstate
61
62 #endif /* STARPU_SIMGRID, _MSC_VER */
63
64 /*
65 * Encapsulation of the pthread_mutex_* functions.
66 */
67
68 #ifdef STARPU_SIMGRID
69 typedef xbt_mutex_t starpu_pthread_mutex_t;
70 typedef int starpu_pthread_mutexattr_t;
71
72 #define STARPU_PTHREAD_MUTEX_INITIALIZER NULL
73
74 int starpu_pthread_mutex_init(starpu_pthread_mutex_t *mutex, const starpu_pthread_mutexattr_t *mutexattr);
75 int starpu_pthread_mutex_destroy(starpu_pthread_mutex_t *mutex);
76 int starpu_pthread_mutex_lock(starpu_pthread_mutex_t *mutex);
77 int starpu_pthread_mutex_unlock(starpu_pthread_mutex_t *mutex);
78 int starpu_pthread_mutex_trylock(starpu_pthread_mutex_t *mutex);
79
80 #elif !defined(_MSC_VER) /* !STARPU_SIMGRID */
81
82 typedef pthread_mutex_t starpu_pthread_mutex_t;
83 typedef pthread_mutexattr_t starpu_pthread_mutexattr_t;
84
85 #define starpu_pthread_mutex_init pthread_mutex_init
86 #define starpu_pthread_mutex_destroy pthread_mutex_destroy
87 #define starpu_pthread_mutex_lock pthread_mutex_lock
88 #define starpu_pthread_mutex_unlock pthread_mutex_unlock
89 #define starpu_pthread_mutex_trylock pthread_mutex_trylock
90
91 #define STARPU_PTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
92
93 #endif /* STARPU_SIMGRID, _MSC_VER */
94
95 /*
96 * Encapsulation of the pthread_key_* functions.
97 */
98 #ifdef STARPU_SIMGRID
99
100 typedef int starpu_pthread_key_t;
101 int starpu_pthread_key_create(starpu_pthread_key_t *key, void (*destr_function) (void *));
102 int starpu_pthread_key_delete(starpu_pthread_key_t key);
103 int starpu_pthread_setspecific(starpu_pthread_key_t key, const void *pointer);
104 void *starpu_pthread_getspecific(starpu_pthread_key_t key);
105
106 #elif !defined(_MSC_VER) /* STARPU_SIMGRID */
107
108 typedef pthread_key_t starpu_pthread_key_t;
109
110 #define starpu_pthread_key_create pthread_key_create
111 #define starpu_pthread_key_delete pthread_key_delete
112 #define starpu_pthread_setspecific pthread_setspecific
113 #define starpu_pthread_getspecific pthread_getspecific
114
115 #endif /* STARPU_SIMGRID, _MSC_VER */
116
117 /*
118 * Encapsulation of the pthread_cond_* functions.
119 */
120
121 #ifdef STARPU_SIMGRID
122
123 typedef xbt_cond_t starpu_pthread_cond_t;
124 typedef int starpu_pthread_condattr_t;
125 #define STARPU_PTHREAD_COND_INITIALIZER NULL
126
127 int starpu_pthread_cond_init(starpu_pthread_cond_t *cond, starpu_pthread_condattr_t *cond_attr);
128 int starpu_pthread_cond_signal(starpu_pthread_cond_t *cond);
129 int starpu_pthread_cond_broadcast(starpu_pthread_cond_t *cond);
130 int starpu_pthread_cond_wait(starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex);
131 int starpu_pthread_cond_timedwait(starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex, const struct timespec *abstime);
132 int starpu_pthread_cond_destroy(starpu_pthread_cond_t *cond);
133
134 #elif !defined(_MSC_VER) /* STARPU_SIMGRID */
135
136 typedef pthread_cond_t starpu_pthread_cond_t;
137 typedef pthread_condattr_t starpu_pthread_condattr_t;
138 #define STARPU_PTHREAD_COND_INITIALIZER PTHREAD_COND_INITIALIZER
139
140 #define starpu_pthread_cond_init pthread_cond_init
141 #define starpu_pthread_cond_signal pthread_cond_signal
142 #define starpu_pthread_cond_broadcast pthread_cond_broadcast
143 #define starpu_pthread_cond_wait pthread_cond_wait
144 #define starpu_pthread_cond_timedwait pthread_cond_timedwait
145 #define starpu_pthread_cond_destroy pthread_cond_destroy
146
147 #endif /* STARPU_SIMGRID, _MSC_VER */
148
149 /*
150 * Encapsulation of the pthread_rwlock_* functions.
151 */
152
153 #ifdef STARPU_SIMGRID
154
155 typedef xbt_mutex_t starpu_pthread_rwlock_t;
156 typedef int starpu_pthread_rwlockattr_t;
157
158 int starpu_pthread_rwlock_init(starpu_pthread_rwlock_t *rwlock, const starpu_pthread_rwlockattr_t *attr);
159 int starpu_pthread_rwlock_destroy(starpu_pthread_rwlock_t *rwlock);
160 int starpu_pthread_rwlock_rdlock(starpu_pthread_rwlock_t *rwlock);
161 int starpu_pthread_rwlock_tryrdlock(starpu_pthread_rwlock_t *rwlock);
162 int starpu_pthread_rwlock_wrlock(starpu_pthread_rwlock_t *rwlock);
163 int starpu_pthread_rwlock_trywrlock(starpu_pthread_rwlock_t *rwlock);
164 int starpu_pthread_rwlock_unlock(starpu_pthread_rwlock_t *rwlock);
165
166 #elif !defined(_MSC_VER) /* STARPU_SIMGRID */
167
168 typedef pthread_rwlock_t starpu_pthread_rwlock_t;
169 typedef pthread_rwlockattr_t starpu_pthread_rwlockattr_t;
170
171 #define starpu_pthread_rwlock_init pthread_rwlock_init
172 #define starpu_pthread_rwlock_destroy pthread_rwlock_destroy
173 #define starpu_pthread_rwlock_rdlock pthread_rwlock_rdlock
174 #define starpu_pthread_rwlock_tryrdlock pthread_rwlock_tryrdlock
175 #define starpu_pthread_rwlock_wrlock pthread_rwlock_wrlock
176 #define starpu_pthread_rwlock_trywrlock pthread_rwlock_trywrlock
177 #define starpu_pthread_rwlock_unlock pthread_rwlock_unlock
178
179 #endif /* STARPU_SIMGRID, _MSC_VER */
180
181 /*
182 * Encapsulation of the pthread_barrier_* functions.
183 */
184
185 #if defined(STARPU_SIMGRID) || !defined(STARPU_HAVE_PTHREAD_BARRIER)
186
187 typedef struct {
188 starpu_pthread_mutex_t mutex;
189 starpu_pthread_cond_t cond;
190 unsigned count;
191 unsigned done;
192 } starpu_pthread_barrier_t;
193 typedef int starpu_pthread_barrierattr_t;
194 #define STARPU_PTHREAD_BARRIER_SERIAL_THREAD -1
195
196 int starpu_pthread_barrier_init(starpu_pthread_barrier_t *barrier, const starpu_pthread_barrierattr_t *attr, unsigned count);
197 int starpu_pthread_barrier_destroy(starpu_pthread_barrier_t *barrier);
198 int starpu_pthread_barrier_wait(starpu_pthread_barrier_t *barrier);
199
200 #elif !defined(_MSC_VER) /* STARPU_SIMGRID, !STARPU_HAVE_PTHREAD_BARRIER */
201
202 typedef pthread_barrier_t starpu_pthread_barrier_t;
203 typedef pthread_barrierattr_t starpu_pthread_barrierattr_t;
204
205 #define starpu_pthread_barrier_init pthread_barrier_init
206 #define starpu_pthread_barrier_destroy pthread_barrier_destroy
207 #define starpu_pthread_barrier_wait pthread_barrier_wait
208 #define STARPU_PTHREAD_BARRIER_SERIAL_THREAD PTHREAD_BARRIER_SERIAL_THREAD
209
210 #endif /* STARPU_SIMGRID, !STARPU_HAVE_PTHREAD_BARRIER, _MSC_VER */
211
212 #ifdef _MSC_VER
213 typedef void* starpu_pthread_rwlock_t;
214 typedef void* starpu_pthread_mutex_t;
215 typedef void* starpu_pthread_cond_t;
216 typedef void* starpu_pthread_barrier_t;
217 #endif /* _MSC_VER */
218
219 #ifdef __cplusplus
220 }
221 #endif
222
223 #endif /* __STARPU_THREAD_H__ */
224
225
starpu_pthread_mutex_unlock
int starpu_pthread_mutex_unlock(starpu_pthread_mutex_t *mutex)
starpu_pthread_getspecific
void * starpu_pthread_getspecific(starpu_pthread_key_t key)
starpu_pthread_rwlock_rdlock
int starpu_pthread_rwlock_rdlock(starpu_pthread_rwlock_t *rwlock)
starpu_pthread_attr_destroy
int starpu_pthread_attr_destroy(starpu_pthread_attr_t *attr)
starpu_pthread_cond_timedwait
int starpu_pthread_cond_timedwait(starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex, const struct timespec *abstime)
starpu_pthread_cond_wait
int starpu_pthread_cond_wait(starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex)
starpu_pthread_setspecific
int starpu_pthread_setspecific(starpu_pthread_key_t key, const void *pointer)
starpu_pthread_rwlock_wrlock
int starpu_pthread_rwlock_wrlock(starpu_pthread_rwlock_t *rwlock)
starpu_pthread_rwlock_unlock
int starpu_pthread_rwlock_unlock(starpu_pthread_rwlock_t *rwlock)
starpu_pthread_mutex_destroy
int starpu_pthread_mutex_destroy(starpu_pthread_mutex_t *mutex)
starpu_pthread_cond_broadcast
int starpu_pthread_cond_broadcast(starpu_pthread_cond_t *cond)
starpu_pthread_barrier_t
Definition: starpu_thread.h:187
starpu_pthread_join
int starpu_pthread_join(starpu_pthread_t thread, void **retval)
starpu_pthread_mutex_init
int starpu_pthread_mutex_init(starpu_pthread_mutex_t *mutex, const starpu_pthread_mutexattr_t *mutexattr)
starpu_pthread_key_delete
int starpu_pthread_key_delete(starpu_pthread_key_t key)
starpu_config.h
starpu_pthread_rwlock_init
int starpu_pthread_rwlock_init(starpu_pthread_rwlock_t *rwlock, const starpu_pthread_rwlockattr_t *attr)
starpu_pthread_cond_destroy
int starpu_pthread_cond_destroy(starpu_pthread_cond_t *cond)
starpu_pthread_cond_init
int starpu_pthread_cond_init(starpu_pthread_cond_t *cond, starpu_pthread_condattr_t *cond_attr)
starpu_pthread_create
int starpu_pthread_create(starpu_pthread_t *thread, const starpu_pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
starpu_pthread_attr_init
int starpu_pthread_attr_init(starpu_pthread_attr_t *attr)
starpu_pthread_attr_setdetachstate
int starpu_pthread_attr_setdetachstate(starpu_pthread_attr_t *attr, int detachstate)
starpu_pthread_mutex_lock
int starpu_pthread_mutex_lock(starpu_pthread_mutex_t *mutex)
starpu_pthread_mutex_trylock
int starpu_pthread_mutex_trylock(starpu_pthread_mutex_t *mutex)
starpu_pthread_key_create
int starpu_pthread_key_create(starpu_pthread_key_t *key, void(*destr_function)(void *))
starpu_pthread_cond_signal
int starpu_pthread_cond_signal(starpu_pthread_cond_t *cond)
starpu_pthread_rwlock_destroy
int starpu_pthread_rwlock_destroy(starpu_pthread_rwlock_t *rwlock)