ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/xthread.h
Revision: 1.1
Committed: Wed May 9 06:45:12 2007 UTC (17 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 /* solaris */
2     #define _POSIX_PTHREAD_SEMANTICS 1
3    
4     #if __linux && !defined(_GNU_SOURCE)
5     # define _GNU_SOURCE
6     #endif
7    
8     /* just in case */
9     #define _REENTRANT 1
10    
11     #include <signal.h>
12     #include <pthread.h>
13    
14     #ifndef PTHREAD_STACK_MIN
15     /* care for broken platforms, e.g. windows */
16     # define PTHREAD_STACK_MIN 16384
17     #endif
18    
19     #if __ia64
20     # define STACKSIZE 65536
21     #elif __i386 || __x86_64 /* 16k is unreasonably high :( */
22     # define STACKSIZE PTHREAD_STACK_MIN
23     #else
24     # define STACKSIZE 16384
25     #endif
26    
27     /* wether word reads are potentially non-atomic.
28     * this is conservatice, likely most arches this runs
29     * on have atomic word read/writes.
30     */
31     #ifndef WORDACCESS_UNSAFE
32     # if __i386 || __x86_64
33     # define WORDACCESS_UNSAFE 0
34     # else
35     # define WORDACCESS_UNSAFE 1
36     # endif
37     #endif
38    
39     typedef pthread_mutex_t mutex_t;
40     #if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP)
41     # define MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
42     #else
43     # define MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
44     #endif
45    
46     typedef pthread_cond_t cond_t;
47     #define COND_INIT PTHREAD_COND_INITIALIZER
48    
49     #define LOCK(mutex) pthread_mutex_lock (&(mutex))
50     #define UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
51    
52     #define COND_SIGNAL(cond) pthread_cond_signal (&(cond))
53     #define COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex))
54     #define COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to))
55    
56     typedef pthread_t thread_t;
57    
58     static int thread_create (thread_t *tid, void *(*proc)(void *), void *arg)
59     {
60     int retval;
61     sigset_t fullsigset, oldsigset;
62     pthread_attr_t attr;
63    
64     pthread_attr_init (&attr);
65     pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
66     #ifdef PTHREAD_SCOPE_PROCESS
67     pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS);
68     #endif
69    
70     sigfillset (&fullsigset);
71    
72     pthread_sigmask (SIG_SETMASK, &fullsigset, &oldsigset);
73     retval = pthread_create (tid, &attr, proc, arg) == 0;
74     pthread_sigmask (SIG_SETMASK, &oldsigset, 0);
75    
76     return retval;
77     }
78    
79     #define ATFORK(prepare,parent,child) pthread_atfork (prepare, parent, child)
80