1/*
2 * Copyright (c) 2010 Apple Inc. All rights reserved.
3 * Copyright (c) 2008 Likewise Software, Inc. All rights reserved.
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1.  Redistributions of source code must retain the above copyright
12 *     notice, this list of conditions and the following disclaimer.
13 * 2.  Redistributions in binary form must reproduce the above copyright
14 *     notice, this list of conditions and the following disclaimer in the
15 *     documentation and/or other materials provided with the distribution.
16 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of its
17 *     contributors may be used to endorse or promote products derived from
18 *     this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * Portions of this software have been released under the following terms:
32 *
33 * (c) Copyright 1989-1993 OPEN SOFTWARE FOUNDATION, INC.
34 * (c) Copyright 1989-1993 HEWLETT-PACKARD COMPANY
35 * (c) Copyright 1989-1993 DIGITAL EQUIPMENT CORPORATION
36 *
37 * To anyone who acknowledges that this file is provided "AS IS"
38 * without any express or implied warranty:
39 * permission to use, copy, modify, and distribute this file for any
40 * purpose is hereby granted without fee, provided that the above
41 * copyright notices and this notice appears in all source code copies,
42 * and that none of the names of Open Software Foundation, Inc., Hewlett-
43 * Packard Company or Digital Equipment Corporation be used
44 * in advertising or publicity pertaining to distribution of the software
45 * without specific, written prior permission.  Neither Open Software
46 * Foundation, Inc., Hewlett-Packard Company nor Digital
47 * Equipment Corporation makes any representations about the suitability
48 * of this software for any purpose.
49 *
50 * Copyright (c) 2007, Novell, Inc. All rights reserved.
51 * Redistribution and use in source and binary forms, with or without
52 * modification, are permitted provided that the following conditions
53 * are met:
54 *
55 * 1.  Redistributions of source code must retain the above copyright
56 *     notice, this list of conditions and the following disclaimer.
57 * 2.  Redistributions in binary form must reproduce the above copyright
58 *     notice, this list of conditions and the following disclaimer in the
59 *     documentation and/or other materials provided with the distribution.
60 * 3.  Neither the name of Novell Inc. nor the names of its contributors
61 *     may be used to endorse or promote products derived from this
62 *     this software without specific prior written permission.
63 *
64 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
65 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
66 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
67 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY
68 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
69 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
70 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
71 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
72 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
73 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
74 *
75 * @APPLE_LICENSE_HEADER_END@
76 */
77
78#ifndef __DCETHREAD_H__
79#define __DCETHREAD_H__
80
81/* Unfortunately, pthreads uses a lot of macros
82   and static initializers which can't easily be
83   abstracted away */
84#include <pthread.h>
85#include <signal.h>
86#include <time.h>
87#include <stdio.h>
88#include <setjmp.h>
89#include <unistd.h>
90#include <sys/types.h>
91#include <sys/time.h>
92#include <sys/socket.h>
93/* FIXME: this is kind of dirty */
94#ifdef __FreeBSD__
95#include <sys/select.h>
96#endif
97
98#ifdef __cplusplus
99extern "C" {
100#endif
101
102#if defined(__GNUC__) && (__GNUC__ >= 3)
103#    define __DCETHREAD_UNUSED__ __attribute__((unused))
104#    define __DCETHREAD_NORETURN__ __attribute__((noreturn))
105#else
106#    define __DCETHREAD_UNUSED__
107#    define __DCETHREAD_NORETURN__
108#endif
109
110/* Opaque thread type */
111typedef volatile struct _dcethread dcethread;
112
113/* We need to be able to track the
114   owner of a mutex */
115typedef volatile struct
116{
117    pthread_mutex_t mutex;
118    pthread_t owner;
119} dcethread_mutex;
120
121/* Alias pthread types */
122typedef pthread_cond_t dcethread_cond;
123typedef pthread_attr_t dcethread_attr;
124typedef pthread_mutexattr_t dcethread_mutexattr;
125typedef pthread_condattr_t dcethread_condattr;
126typedef pthread_once_t dcethread_oncectl;
127typedef pthread_key_t dcethread_key;
128typedef void* dcethread_addr;
129typedef void (*dcethread_initroutine)(void);
130typedef void* (*dcethread_startroutine)(void*);
131
132/* Solaris and AIX have a broken PTHREAD_ONCE_INIT macro, so wrap it
133   appropriately depending on platform */
134
135#if defined(sun) || defined(_AIX)
136#  define DCETHREAD_ONCE_INIT {PTHREAD_ONCE_INIT}
137#else
138#  define DCETHREAD_ONCE_INIT PTHREAD_ONCE_INIT
139#endif
140#define DCETHREAD_MUTEX_INITIALIZER {PTHREAD_MUTEX_INITIALIZER, (pthread_t) -1}
141#if defined(sun)
142#  define DCETHREAD_COND_INITIALIZER {{{0}, 0, 0}, 0}
143#else
144#  define DCETHREAD_COND_INITIALIZER PTHREAD_COND_INITIALIZER
145#endif
146
147/* Entry points */
148int dcethread_get_expiration(struct timespec* delta, struct timespec* abstime);
149
150int dcethread_delay(struct timespec* interval);
151
152void dcethread_lock_global(void);
153
154void dcethread_unlock_global(void);
155
156int dcethread_ismultithreaded(void);
157
158int dcethread_mutexattr_getkind(dcethread_mutexattr *attr);
159
160int dcethread_mutexattr_setkind(dcethread_mutexattr *attr, int kind);
161
162void dcethread_signal_to_interrupt(sigset_t *sigset, dcethread* thread);
163
164int dcethread_attr_create(dcethread_attr *attr);
165int dcethread_attr_create_throw(dcethread_attr *attr);
166
167int dcethread_attr_delete(dcethread_attr *attr);
168int dcethread_attr_delete_throw(dcethread_attr *attr);
169
170int dcethread_attr_setprio(dcethread_attr *attr, int priority);
171int  dcethread_attr_setprio_throw(dcethread_attr *attr, int priority);
172
173int dcethread_attr_getprio(dcethread_attr *attr);
174int dcethread_attr_getprio_throw(dcethread_attr *attr);
175
176int dcethread_attr_setsched(dcethread_attr *attr, int sched);
177int dcethread_attr_setsched_throw(dcethread_attr *attr, int sched);
178
179int dcethread_attr_getsched(dcethread_attr *attr);
180int dcethread_attr_getsched_throw(dcethread_attr* attr);
181
182int dcethread_attr_setinheritsched(dcethread_attr *attr, int inherit);
183int dcethread_attr_setinheritsched_throw(dcethread_attr *attr, int inherit);
184
185int dcethread_attr_getinheritsched(dcethread_attr *attr);
186int dcethread_attr_getinheritsched_throw(dcethread_attr *attr);
187
188int dcethread_attr_setstacksize(dcethread_attr *attr, size_t stacksize);
189int dcethread_attr_setstacksize_throw(dcethread_attr *attr, size_t stacksize);
190
191ssize_t dcethread_attr_getstacksize(dcethread_attr *attr);
192ssize_t dcethread_attr_getstacksize_throw(dcethread_attr* attr);
193
194int dcethread_create(dcethread** _thread, dcethread_attr* attr, void *(*start_routine)(void *), void *arg);
195int dcethread_create_throw(dcethread** _thread, dcethread_attr* attr, void *(*start_routine)(void *), void *arg);
196
197int dcethread_detach(dcethread *thread);
198int dcethread_detach_throw(dcethread *thread);
199
200int dcethread_join(dcethread* thread, void **status);
201int dcethread_join_throw(dcethread* thread, void **status);
202
203int dcethread_setprio(dcethread* thread, int priority);
204int dcethread_setprio_throw(dcethread* thread, int priority);
205
206int dcethread_getprio(dcethread* thread);
207int dcethread_getprio_throw(dcethread* thread);
208
209int dcethread_mutexattr_create(dcethread_mutexattr *attr);
210int dcethread_mutexattr_create_throw(dcethread_mutexattr *attr);
211
212int dcethread_mutexattr_delete(dcethread_mutexattr *attr);
213int dcethread_mutexattr_delete_throw(dcethread_mutexattr *attr);
214
215int dcethread_mutex_init(dcethread_mutex *mutex, dcethread_mutexattr* attr);
216int dcethread_mutex_init_throw(dcethread_mutex *mutex, dcethread_mutexattr* attr);
217
218int dcethread_mutex_destroy(dcethread_mutex *mutex);
219int dcethread_mutex_destroy_throw(dcethread_mutex *mutex);
220
221int dcethread_mutex_lock(dcethread_mutex *mutex);
222int dcethread_mutex_lock_throw(dcethread_mutex *mutex);
223
224int dcethread_mutex_unlock(dcethread_mutex *mutex);
225int dcethread_mutex_unlock_throw(dcethread_mutex *mutex);
226
227int dcethread_mutex_trylock(dcethread_mutex *mutex);
228int dcethread_mutex_trylock_throw(dcethread_mutex *mutex);
229
230int dcethread_condattr_create(dcethread_condattr *attr);
231int dcethread_condattr_create_throw(dcethread_condattr *attr);
232
233int dcethread_condattr_delete(dcethread_condattr *attr);
234int dcethread_condattr_delete_throw(dcethread_condattr *attr);
235
236int dcethread_cond_init(dcethread_cond *cond, dcethread_condattr* attr);
237int dcethread_cond_init_throw(dcethread_cond *cond, dcethread_condattr* attr);
238
239int dcethread_cond_destroy(dcethread_cond *cond);
240int dcethread_cond_destroy_throw(dcethread_cond *cond);
241
242int dcethread_cond_broadcast(dcethread_cond *cond);
243int dcethread_cond_broadcast_throw(dcethread_cond *cond);
244
245int dcethread_cond_signal(dcethread_cond *cond);
246int dcethread_cond_signal_throw(dcethread_cond *cond);
247
248int dcethread_cond_wait(dcethread_cond *cond, dcethread_mutex *mutex);
249int dcethread_cond_wait_throw(dcethread_cond *cond, dcethread_mutex *mutex);
250
251int dcethread_cond_timedwait(dcethread_cond *cond, dcethread_mutex *mutex, struct timespec *abstime);
252int dcethread_cond_timedwait_throw(dcethread_cond *cond, dcethread_mutex *mutex, struct timespec *abstime);
253
254int dcethread_once(dcethread_oncectl *once_block, void (*init_routine)(void));
255int dcethread_once_throw(dcethread_oncectl *once_block, void (*init_routine)(void));
256
257int dcethread_keycreate(dcethread_key *key, void (*destructor)(void *value));
258int dcethread_keycreate_throw(dcethread_key *key, void (*destructor)(void *value));
259
260int dcethread_setspecific(dcethread_key key, void *value);
261int dcethread_setspecific_throw(dcethread_key key, void *value);
262
263int dcethread_getspecific(dcethread_key key, void **value);
264int dcethread_getspecific_throw(dcethread_key key, void **value);
265
266int dcethread_interrupt(dcethread* thread);
267int dcethread_interrupt_throw(dcethread* thread);
268
269int dcethread_enableasync(int on);
270int dcethread_enableasync_throw(int on);
271
272int dcethread_enableinterrupt(int on);
273int dcethread_enableinterrupt_throw(int on);
274
275int dcethread_kill(dcethread* thread, int sig);
276int dcethread_kill_throw(dcethread* thread, int sig);
277
278void dcethread_yield(void);
279
280void dcethread_checkinterrupt(void);
281
282int dcethread_equal(dcethread* t1, dcethread* t2);
283
284dcethread* dcethread_self(void);
285
286__DCETHREAD_NORETURN__ void dcethread_exit(void* status);
287
288int dcethread_atfork(void *user_state, void (*pre_fork)(void *), void (*parent_fork)(void *), void (*child_fork)(void *));
289int dcethread_atfork_throw(void *user_state, void (*pre_fork)(void *), void (*parent_fork)(void *), void (*child_fork)(void *));
290
291/* Exceptions */
292
293typedef struct _dcethread_exc
294{
295    enum
296    {
297	DCETHREAD_EXC_KIND_ADDRESS = 0x02130455,
298	DCETHREAD_EXC_KIND_STATUS = 0x02130456
299    } kind;
300    union
301    {
302        int value;
303        struct _dcethread_exc *address;
304    } match;
305    const char* name;
306} dcethread_exc;
307
308void dcethread_exc_init(dcethread_exc* exc, const char* name);
309void dcethread_exc_setstatus(dcethread_exc* exc, int value);
310int dcethread_exc_getstatus(dcethread_exc* exc);
311int dcethread_exc_matches(dcethread_exc* exc, dcethread_exc* pattern);
312__DCETHREAD_NORETURN__ void dcethread_exc_raise(dcethread_exc* exc, const char* file, unsigned int line);
313
314typedef volatile struct _dcethread_frame
315{
316    dcethread_exc exc;
317    const char* file;
318    unsigned int line;
319    sigjmp_buf jmpbuf;
320    volatile struct _dcethread_frame *parent;
321} dcethread_frame;
322
323void dcethread_frame_push(dcethread_frame* frame);
324void dcethread_frame_pop(dcethread_frame* frame);
325
326#define DCETHREAD_TRY							\
327    do									\
328    {									\
329        /* handler frame */						\
330        __DCETHREAD_UNUSED__ dcethread_frame __dcethread_frame;         \
331	/* has a catch clause been run this frame? */			\
332	__DCETHREAD_UNUSED__ volatile char __dcethread_handled = 0;     \
333	/* has a finally clause been run this frame? */			\
334	__DCETHREAD_UNUSED__ volatile char __dcethread_finally = 0;     \
335	/* is a live (unhandled) exception in play? */			\
336	__DCETHREAD_UNUSED__ volatile int __dcethread_live;             \
337									\
338	dcethread_frame_push(&__dcethread_frame);			\
339	__dcethread_live = sigsetjmp(((struct _dcethread_frame*) &__dcethread_frame)->jmpbuf, 1); \
340									\
341									\
342	if (!__dcethread_live)						\
343	{								\
344	    /* Try block code goes here */
345
346#define DCETHREAD_CATCH(_exc)						 \
347        }								 \
348	else if (!__dcethread_handled &&				 \
349	         !__dcethread_finally &&				\
350		 dcethread_exc_matches((dcethread_exc*) &__dcethread_frame.exc, &(_exc))) \
351	{								\
352	    __dcethread_handled = 1;					\
353	    __dcethread_live = 0;					\
354	    /* exception code here */
355
356#define DCETHREAD_CATCH_EXPR(expr)			\
357        }						\
358	else if (!__dcethread_handled &&		\
359		 !__dcethread_finally && (expr))	\
360	{						\
361	    __dcethread_handled = 1;			\
362	    __dcethread_live = 0;			\
363	    /* exception code here */
364
365#define DCETHREAD_CATCH_ALL(_exc)			       \
366        }						       \
367	else if (!__dcethread_handled &&		       \
368		 !__dcethread_finally)			       \
369	{						       \
370            __DCETHREAD_UNUSED__ dcethread_exc* _exc = (dcethread_exc*) &__dcethread_frame.exc; \
371	    __dcethread_handled = 1;			       \
372	    __dcethread_live = 0;			       \
373        /* exception code here */
374
375#define DCETHREAD_FINALLY			\
376        }					\
377	if (!__dcethread_finally)		\
378        {					\
379	     __dcethread_finally = 1;		\
380	     /* user finally code here */
381
382#define DCETHREAD_ENDTRY						\
383        }								\
384        dcethread_frame_pop(&__dcethread_frame);			\
385	if (__dcethread_live)						\
386	{								\
387	    DCETHREAD_RERAISE;                                          \
388	}								\
389    } while (0);							\
390
391#define DCETHREAD_RAISE(e) (dcethread_exc_raise(&(e), __FILE__, __LINE__))
392
393#define DCETHREAD_RERAISE (dcethread_exc_raise((dcethread_exc*) &__dcethread_frame.exc, \
394                                               (const char*) __dcethread_frame.file, \
395                                               (unsigned int) __dcethread_frame.line))
396
397#define DCETHREAD_EXC_CURRENT ((dcethread_exc*) &__dcethread_frame.exc)
398
399#define DCETHREAD_EXC_INIT(e) (dcethread_exc_init(&(e), #e))
400
401/* Standard exceptions */
402
403extern dcethread_exc dcethread_uninitexc_e;       /* Uninitialized exception */
404
405/*
406 * The following exceptions are common error conditions which may be raised
407 * by the thread library or any other facility following this exception
408 * specification.
409 */
410
411extern dcethread_exc dcethread_exquota_e;         /* Exceeded quota */
412extern dcethread_exc dcethread_insfmem_e;         /* Insufficient memory */
413extern dcethread_exc dcethread_nopriv_e;          /* No privilege */
414
415/*
416 * The following exceptions describe hardware or operating system error
417 * conditions that are appropriate for most hardware and operating system
418 * platforms. These are raised by the exception facility to report operating
419 * system and hardware error conditions.
420 */
421
422extern dcethread_exc dcethread_illaddr_e;         /* Illegal address */
423extern dcethread_exc dcethread_illinstr_e;        /* Illegal instruction */
424extern dcethread_exc dcethread_resaddr_e;         /* Reserved addressing mode */
425extern dcethread_exc dcethread_privinst_e;        /* Privileged instruction */
426extern dcethread_exc dcethread_resoper_e;         /* Reserved operand */
427extern dcethread_exc dcethread_aritherr_e;        /* Arithmetic error */
428extern dcethread_exc dcethread_intovf_e;          /* Integer overflow */
429extern dcethread_exc dcethread_intdiv_e;          /* Integer divide by zero */
430extern dcethread_exc dcethread_fltovf_e;          /* Floating overflow */
431extern dcethread_exc dcethread_fltdiv_e;          /* Floating divide by zero */
432extern dcethread_exc dcethread_fltund_e;          /* Floating underflow */
433extern dcethread_exc dcethread_decovf_e;          /* Decimal overflow */
434extern dcethread_exc dcethread_subrng_e;          /* Subrange */
435extern dcethread_exc dcethread_excpu_e;           /* Exceeded CPU quota */
436extern dcethread_exc dcethread_exfilsiz_e;        /* Exceeded file size */
437
438/*
439 * The following exceptions correspond directly to UNIX synchronous
440 * terminating signals.  This is distinct from the prior list in that those
441 * are generic and likely to have equivalents on most any operating system,
442 * whereas these are highly specific to UNIX platforms.
443 */
444
445extern dcethread_exc dcethread_SIGTRAP_e;         /* SIGTRAP received */
446extern dcethread_exc dcethread_SIGIOT_e;          /* SIGIOT received */
447extern dcethread_exc dcethread_SIGEMT_e;          /* SIGEMT received */
448extern dcethread_exc dcethread_SIGSYS_e;          /* SIGSYS received */
449extern dcethread_exc dcethread_SIGPIPE_e;         /* SIGPIPE received */
450extern dcethread_exc dcethread_unksyncsig_e;      /* Unknown synchronous signal */
451
452/*
453 * The following exception is raised in the target of an interruption
454 */
455
456extern dcethread_exc dcethread_interrupt_e;
457extern dcethread_exc dcethread_badparam_e;           /* Bad parameter */
458extern dcethread_exc dcethread_existence_e;          /* Object does not exist */
459extern dcethread_exc dcethread_in_use_e;             /* Object is in use */
460extern dcethread_exc dcethread_use_error_e;          /* Object inappropriate for operation */
461extern dcethread_exc dcethread_nostackmem_e;         /* No memory to allocate stack */
462extern dcethread_exc dcethread_exit_thread_e;        /* Used to terminate a thread */
463
464/*
465 * Interruptible system calls, etc
466 */
467
468int dcethread_pause(void);
469ssize_t dcethread_read(int fd, void *buf, size_t count);
470ssize_t dcethread_write(int fd, void *buf, size_t count);
471ssize_t dcethread_send(int s, const void *buf, size_t len, int flags);
472ssize_t dcethread_sendto(int s, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen);
473ssize_t dcethread_sendmsg(int s, const struct msghdr *msg, int flags);
474ssize_t dcethread_recv(int s, void *buf, size_t len, int flags);
475ssize_t dcethread_recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);
476ssize_t dcethread_recvmsg(int s, struct msghdr *msg, int flags);
477int dcethread_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
478
479pid_t dcethread_fork(void);
480
481#ifdef DCETHREAD_ENFORCE_API
482#ifdef DCETHREAD_USE_THROW
483#define dcethread_attr_create ($ ERROR $)
484#define dcethread_attr_delete ($ ERROR $)
485#define dcethread_attr_setprio ($ ERROR $)
486#define dcethread_attr_getprio ($ ERROR $)
487#define dcethread_attr_setsched ($ ERROR $)
488#define dcethread_attr_getsched ($ ERROR $)
489#define dcethread_attr_setinheritsched ($ ERROR $)
490#define dcethread_attr_getinheritsched ($ ERROR $)
491#define dcethread_attr_setstacksize ($ ERROR $)
492#define dcethread_attr_getstacksize ($ ERROR $)
493#define dcethread_create ($ ERROR $)
494#define dcethread_detach ($ ERROR $)
495#define dcethread_join ($ ERROR $)
496#define dcethread_setprio ($ ERROR $)
497#define dcethread_getprio ($ ERROR $)
498#define dcethread_mutexattr_create ($ ERROR $)
499#define dcethread_mutexattr_delete ($ ERROR $)
500#define dcethread_mutex_init ($ ERROR $)
501#define dcethread_mutex_destroy ($ ERROR $)
502#define dcethread_mutex_lock ($ ERROR $)
503#define dcethread_mutex_unlock ($ ERROR $)
504#define dcethread_mutex_trylock ($ ERROR $)
505#define dcethread_condattr_create ($ ERROR $)
506#define dcethread_condattr_delete ($ ERROR $)
507#define dcethread_cond_init ($ ERROR $)
508#define dcethread_cond_destroy ($ ERROR $)
509#define dcethread_cond_broadcast ($ ERROR $)
510#define dcethread_cond_signal ($ ERROR $)
511#define dcethread_cond_wait ($ ERROR $)
512#define dcethread_cond_timedwait ($ ERROR $)
513#define dcethread_once ($ ERROR $)
514#define dcethread_keycreate ($ ERROR $)
515#define dcethread_setspecific ($ ERROR $)
516#define dcethread_getspecific ($ ERROR $)
517#define dcethread_interrupt ($ ERROR $)
518#define dcethread_enableasync ($ ERROR $)
519#define dcethread_enableinterrupt ($ ERROR $)
520#else
521#define dcethread_attr_create_throw ($ ERROR $)
522#define dcethread_attr_delete_throw ($ ERROR $)
523#define dcethread_attr_setprio_throw ($ ERROR $)
524#define dcethread_attr_getprio_throw ($ ERROR $)
525#define dcethread_attr_setsched_throw ($ ERROR $)
526#define dcethread_attr_getsched_throw ($ ERROR $)
527#define dcethread_attr_setinheritsched_throw ($ ERROR $)
528#define dcethread_attr_getinheritsched_throw ($ ERROR $)
529#define dcethread_attr_setstacksize_throw ($ ERROR $)
530#define dcethread_attr_getstacksize_throw ($ ERROR $)
531#define dcethread_create_throw ($ ERROR $)
532#define dcethread_detach_throw ($ ERROR $)
533#define dcethread_join_throw ($ ERROR $)
534#define dcethread_setprio_throw ($ ERROR $)
535#define dcethread_getprio_throw ($ ERROR $)
536#define dcethread_mutexattr_create_throw ($ ERROR $)
537#define dcethread_mutexattr_delete_throw ($ ERROR $)
538#define dcethread_mutex_init_throw ($ ERROR $)
539#define dcethread_mutex_destroy_throw ($ ERROR $)
540#define dcethread_mutex_lock_throw ($ ERROR $)
541#define dcethread_mutex_unlock_throw ($ ERROR $)
542#define dcethread_mutex_trylock_throw ($ ERROR $)
543#define dcethread_condattr_create_throw ($ ERROR $)
544#define dcethread_condattr_delete_throw ($ ERROR $)
545#define dcethread_cond_init_throw ($ ERROR $)
546#define dcethread_cond_destroy_throw ($ ERROR $)
547#define dcethread_cond_broadcast_throw ($ ERROR $)
548#define dcethread_cond_signal_throw ($ ERROR $)
549#define dcethread_cond_wait_throw ($ ERROR $)
550#define dcethread_cond_timedwait_throw ($ ERROR $)
551#define dcethread_once_throw ($ ERROR $)
552#define dcethread_keycreate_throw ($ ERROR $)
553#define dcethread_setspecific_throw ($ ERROR $)
554#define dcethread_getspecific_throw ($ ERROR $)
555#define dcethread_interrupt_throw ($ ERROR $)
556#define dcethread_enableasync_throw ($ ERROR $)
557#define dcethread_enableinterrupt_throw ($ ERROR $)
558#endif
559#define pthread_attr_create ($ ERROR $)
560#define pthread_attr_delete ($ ERROR $)
561#define pthread_attr_setprio ($ ERROR $)
562#define pthread_attr_getprio ($ ERROR $)
563#define pthread_attr_setsched ($ ERROR $)
564#define pthread_attr_getsched ($ ERROR $)
565#define pthread_attr_setinheritsched ($ ERROR $)
566#define pthread_attr_getinheritsched ($ ERROR $)
567#define pthread_attr_setstacksize ($ ERROR $)
568#define pthread_attr_getstacksize ($ ERROR $)
569#define pthread_create ($ ERROR $)
570#define pthread_detach ($ ERROR $)
571#define pthread_join ($ ERROR $)
572#define pthread_setprio ($ ERROR $)
573#define pthread_getprio ($ ERROR $)
574#define pthread_mutexattr_create ($ ERROR $)
575#define pthread_mutexattr_delete ($ ERROR $)
576
577#ifdef pthread_mutex_init
578#undef     pthread_mutex_init
579#endif
580#define pthread_mutex_init ($ ERROR $)
581
582#ifdef pthread_mutex_destroy
583#undef     pthread_mutex_destroy
584#endif
585#define pthread_mutex_destroy ($ ERROR $)
586
587#ifdef pthread_mutex_lock
588#undef     pthread_mutex_lock
589#endif
590#define pthread_mutex_lock ($ ERROR $)
591
592#ifdef pthread_mutex_unlock
593#undef     pthread_mutex_unlock
594#endif
595
596#ifdef pthread_mutex_unlock
597#undef     pthread_mutex_unlock
598#endif
599#define pthread_mutex_unlock ($ ERROR $)
600
601#ifdef pthread_mutex_trylock
602#undef     pthread_mutex_trylock
603#endif
604#define pthread_mutex_trylock ($ ERROR $)
605#define pthread_condattr_create ($ ERROR $)
606#define pthread_condattr_delete ($ ERROR $)
607
608#ifdef pthread_cond_init
609#undef     pthread_cond_init
610#endif
611#define pthread_cond_init ($ ERROR $)
612
613#ifdef pthread_cond_destroy
614#undef    pthread_cond_destroy
615#endif
616#define pthread_cond_destroy ($ ERROR $)
617
618#ifdef pthread_cond_broadcast
619#undef    pthread_cond_broadcast
620#endif
621#define pthread_cond_broadcast ($ ERROR $)
622
623#ifdef pthread_cond_signal
624#undef     pthread_cond_signal
625#endif
626#define pthread_cond_signal ($ ERROR $)
627
628#ifdef pthread_cond_wait
629#undef     pthread_cond_wait
630#endif
631#define pthread_cond_wait ($ ERROR $)
632
633#ifdef pthread_cond_timedwait
634#undef    pthread_cond_timedwait
635#endif
636#define pthread_cond_timedwait ($ ERROR $)
637
638#ifdef pthread_once
639#undef     pthread_once
640#endif
641#define pthread_once ($ ERROR $)
642#define pthread_keycreate ($ ERROR $)
643
644#ifdef pthread_setspecific
645#undef     pthread_setspecific
646#endif
647#define pthread_setspecific ($ ERROR $)
648
649#ifdef pthread_getspecific
650#undef     pthread_getspecific
651#endif
652#define pthread_getspecific ($ ERROR $)
653#define pthread_cancel ($ ERROR $)
654#define pthread_setasynccancel ($ ERROR $)
655#define pthread_setcancel ($ ERROR $)
656#define pthread_kill ($ ERROR $)
657
658#ifdef pthread_exit
659#undef     pthread_exit
660#endif
661#define pthread_exit ($ ERROR $)
662#define DO_NOT_CLOBBER ($ ERROR $)
663#define EXCEPTION ($ ERROR $)
664#define EXCEPTION_INIT ($ ERROR $)
665#define TRY ($ ERROR $)
666#define ENDTRY ($ ERROR $)
667#define CATCH ($ ERROR $)
668#define CATCH_ALL ($ ERROR $)
669#define CATCH_EXPR ($ ERROR $)
670#define RAISE ($ ERROR $)
671#define RERAISE ($ ERROR $)
672#define FINALLY ($ ERROR $)
673#define pthread_mutex_t ($ ERROR $)
674#define pthread_cond_t ($ ERROR $)
675#define pthread_attr_t ($ ERROR $)
676#define pthread_mutexattr_t ($ ERROR $)
677#define pthread_condattr_t ($ ERROR $)
678#define pthread_once_t ($ ERROR $)
679#define pthread_key_t ($ ERROR $)
680#define pthread_addr_t ($ ERROR $)
681#define pthread_initroutine_t ($ ERROR $)
682#define pthread_startroutine_t ($ ERROR $)
683#define pause ($ ERROR $)
684
685#ifdef read
686#    undef read
687#endif
688#define read ($ ERROR $)
689#define write ($ ERROR $)
690#define send ($ ERROR $)
691#ifdef sendto
692#    undef sendto
693#endif
694#define sendto ($ ERROR $)
695#ifdef sendmsg
696#    undef sendmsg
697#endif
698#define sendmsg ($ ERROR $)
699#define recv ($ ERROR $)
700#ifdef recvfrom
701#    undef recvfrom
702#endif
703#define recvfrom ($ ERROR $)
704#ifdef recvmsg
705#    undef recvmsg
706#endif
707#define recvmsg ($ ERROR $)
708#define select ($ ERROR $)
709#endif
710
711#ifdef __cplusplus
712} /* extern "C" */
713#endif
714
715#endif
716