4 /* whether word reads are potentially non-atomic.
5 * this is conservatice, likely most arches this runs
6 * on have atomic word read/writes.
8 #ifndef WORDACCESS_UNSAFE
9 # if __i386 || __x86_64
10 # define WORDACCESS_UNSAFE 0
12 # define WORDACCESS_UNSAFE 1
16 /////////////////////////////////////////////////////////////////////////////
24 #define NTDDI_VERSION NTDDI_WIN2K // needed to get win2000 api calls
25 #define _WIN32_WINNT 0x400
35 #define pthread_sigmask(a,b,c)
36 #define sigaddset(a,b)
37 #define sigemptyset(s)
40 typedef pthread_mutex_t xmutex_t;
41 #define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
42 #define X_LOCK(mutex) pthread_mutex_lock (&(mutex))
43 #define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
45 typedef pthread_cond_t xcond_t;
46 #define X_COND_INIT PTHREAD_COND_INITIALIZER
47 #define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond))
48 #define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex))
49 #define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to))
51 typedef pthread_t xthread_t;
52 #define X_THREAD_PROC(name) void *name (void *thr_arg)
53 #define X_THREAD_ATFORK(a,b,c)
56 thread_create (xthread_t *tid, void *(*proc)(void *), void *arg)
61 pthread_attr_init (&attr);
62 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
64 retval = pthread_create (tid, &attr, proc, arg) == 0;
66 pthread_attr_destroy (&attr);
71 #define respipe_read(a,b,c) PerlSock_recv ((a), (b), (c), 0)
72 #define respipe_write(a,b,c) send ((a), (b), (c), 0)
73 #define respipe_close(a) PerlSock_closesocket ((a))
76 /////////////////////////////////////////////////////////////////////////////
78 #if __linux && !defined(_GNU_SOURCE)
86 # define _POSIX_PTHREAD_SEMANTICS 1
87 /* try to bribe solaris headers into providing a current pthread API
88 * despite environment being configured for an older version.
90 # define __EXTENSIONS__ 1
99 typedef pthread_mutex_t xmutex_t;
100 #if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP)
101 # define X_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
103 # define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
105 #define X_LOCK(mutex) pthread_mutex_lock (&(mutex))
106 #define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
108 typedef pthread_cond_t xcond_t;
109 #define X_COND_INIT PTHREAD_COND_INITIALIZER
110 #define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond))
111 #define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex))
112 #define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to))
114 typedef pthread_t xthread_t;
115 #define X_THREAD_PROC(name) static void *name (void *thr_arg)
116 #define X_THREAD_ATFORK(prepare,parent,child) pthread_atfork (prepare, parent, child)
118 // the broken bsd's once more
119 #ifndef PTHREAD_STACK_MIN
120 # define PTHREAD_STACK_MIN 0
124 # define X_STACKSIZE sizeof (long) * 4096
128 thread_create (xthread_t *tid, void *(*proc)(void *), void *arg)
131 sigset_t fullsigset, oldsigset;
134 pthread_attr_init (&attr);
135 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
136 pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN < X_STACKSIZE ? X_STACKSIZE : PTHREAD_STACK_MIN);
137 #ifdef PTHREAD_SCOPE_PROCESS
138 pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS);
141 sigfillset (&fullsigset);
143 pthread_sigmask (SIG_SETMASK, &fullsigset, &oldsigset);
144 retval = pthread_create (tid, &attr, proc, arg) == 0;
145 pthread_sigmask (SIG_SETMASK, &oldsigset, 0);
147 pthread_attr_destroy (&attr);
152 #define respipe_read(a,b,c) read ((a), (b), (c))
153 #define respipe_write(a,b,c) write ((a), (b), (c))
154 #define respipe_close(a) close ((a))