ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libeio/xthread.h
(Generate patch)

Comparing libeio/xthread.h (file contents):
Revision 1.1 by root, Sat May 10 17:16:39 2008 UTC vs.
Revision 1.9 by root, Sat Oct 30 14:36:53 2010 UTC

27#include <winsock2.h> 27#include <winsock2.h>
28#include <process.h> 28#include <process.h>
29#include <windows.h> 29#include <windows.h>
30#include <pthread.h> 30#include <pthread.h>
31#define sigset_t int 31#define sigset_t int
32#define sigfillset(a)
33#define pthread_sigmask(a,b,c) 32#define pthread_sigmask(a,b,c)
34#define sigaddset(a,b) 33#define sigaddset(a,b)
35#define sigemptyset(s) 34#define sigemptyset(s)
36#define sigfillset(s) 35#define sigfillset(s)
37 36
38typedef pthread_mutex_t mutex_t; 37typedef pthread_mutex_t xmutex_t;
39#define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER 38#define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
40#define X_MUTEX_CHECK(mutex)
41#define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) 39#define X_LOCK(mutex) pthread_mutex_lock (&(mutex))
42#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) 40#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
43 41
44typedef pthread_cond_t cond_t; 42typedef pthread_cond_t xcond_t;
45#define X_COND_INIT PTHREAD_COND_INITIALIZER 43#define X_COND_INIT PTHREAD_COND_INITIALIZER
46#define X_COND_CHECK(cond)
47#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) 44#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond))
48#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) 45#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)) 46#define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to))
50 47
51typedef pthread_t thread_t; 48typedef pthread_t xthread_t;
52#define X_THREAD_PROC(name) void *name (void *thr_arg) 49#define X_THREAD_PROC(name) void *name (void *thr_arg)
53#define X_THREAD_ATFORK(a,b,c) 50#define X_THREAD_ATFORK(a,b,c)
54 51
55static int 52static int
56thread_create (thread_t *tid, void *(*proc)(void *), void *arg) 53thread_create (xthread_t *tid, void *(*proc)(void *), void *arg)
57{ 54{
55 int retval;
58 pthread_attr_t attr; 56 pthread_attr_t attr;
59 57
60 pthread_attr_init (&attr); 58 pthread_attr_init (&attr);
61 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); 59 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
62 60
63 return pthread_create (tid, &attr, proc, arg) == 0; 61 retval = pthread_create (tid, &attr, proc, arg) == 0;
62
63 pthread_attr_destroy (&attr);
64
65 return retval;
64} 66}
65 67
66#define respipe_read(a,b,c) PerlSock_recv ((a), (b), (c), 0) 68#define respipe_read(a,b,c) PerlSock_recv ((a), (b), (c), 0)
67#define respipe_write(a,b,c) send ((a), (b), (c), 0) 69#define respipe_write(a,b,c) send ((a), (b), (c), 0)
68#define respipe_close(a) PerlSock_closesocket ((a)) 70#define respipe_close(a) PerlSock_closesocket ((a))
89#include <fcntl.h> 91#include <fcntl.h>
90#include <signal.h> 92#include <signal.h>
91#include <limits.h> 93#include <limits.h>
92#include <pthread.h> 94#include <pthread.h>
93 95
94typedef pthread_mutex_t mutex_t; 96typedef pthread_mutex_t xmutex_t;
95#if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) 97#if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP)
96# define X_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP 98# define X_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
97#else 99#else
98# define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER 100# define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
99#endif 101#endif
100#define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) 102#define X_LOCK(mutex) pthread_mutex_lock (&(mutex))
101#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) 103#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
102 104
103typedef pthread_cond_t cond_t; 105typedef pthread_cond_t xcond_t;
104#define X_COND_INIT PTHREAD_COND_INITIALIZER 106#define X_COND_INIT PTHREAD_COND_INITIALIZER
105#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) 107#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond))
106#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) 108#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex))
107#define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to)) 109#define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to))
108 110
109typedef pthread_t thread_t; 111typedef pthread_t xthread_t;
110#define X_THREAD_PROC(name) static void *name (void *thr_arg) 112#define X_THREAD_PROC(name) static void *name (void *thr_arg)
111#define X_THREAD_ATFORK(prepare,parent,child) pthread_atfork (prepare, parent, child) 113#define X_THREAD_ATFORK(prepare,parent,child) pthread_atfork (prepare, parent, child)
112 114
115// the broken bsd's once more
116#ifndef PTHREAD_STACK_MIN
117# define PTHREAD_STACK_MIN 0
118#endif
119
120#ifndef X_STACKSIZE
121# define X_STACKSIZE sizeof (long) * 4096
122#endif
123
113static int 124static int
114thread_create (thread_t *tid, void *(*proc)(void *), void *arg) 125thread_create (xthread_t *tid, void *(*proc)(void *), void *arg)
115{ 126{
116 int retval; 127 int retval;
117 sigset_t fullsigset, oldsigset; 128 sigset_t fullsigset, oldsigset;
118 pthread_attr_t attr; 129 pthread_attr_t attr;
119 130
120 pthread_attr_init (&attr); 131 pthread_attr_init (&attr);
121 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); 132 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
122 pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN < sizeof (long) * 4096 133 pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN < X_STACKSIZE ? X_STACKSIZE : PTHREAD_STACK_MIN);
123 ? sizeof (long) * 4096 : PTHREAD_STACK_MIN);
124#ifdef PTHREAD_SCOPE_PROCESS 134#ifdef PTHREAD_SCOPE_PROCESS
125 pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); 135 pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS);
126#endif 136#endif
127 137
128 sigfillset (&fullsigset); 138 sigfillset (&fullsigset);
129 139
130 pthread_sigmask (SIG_SETMASK, &fullsigset, &oldsigset); 140 pthread_sigmask (SIG_SETMASK, &fullsigset, &oldsigset);
131 retval = pthread_create (tid, &attr, proc, arg) == 0; 141 retval = pthread_create (tid, &attr, proc, arg) == 0;
132 pthread_sigmask (SIG_SETMASK, &oldsigset, 0); 142 pthread_sigmask (SIG_SETMASK, &oldsigset, 0);
143
144 pthread_attr_destroy (&attr);
133 145
134 return retval; 146 return retval;
135} 147}
136 148
137#define respipe_read(a,b,c) read ((a), (b), (c)) 149#define respipe_read(a,b,c) read ((a), (b), (c))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines