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

Comparing libeio/xthread.h (file contents):
Revision 1.5 by root, Tue May 20 05:50:49 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_LOCK(mutex) pthread_mutex_lock (&(mutex)) 39#define X_LOCK(mutex) pthread_mutex_lock (&(mutex))
41#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) 40#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
42 41
43typedef pthread_cond_t cond_t; 42typedef pthread_cond_t xcond_t;
44#define X_COND_INIT PTHREAD_COND_INITIALIZER 43#define X_COND_INIT PTHREAD_COND_INITIALIZER
45#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) 44#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond))
46#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) 45#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex))
47#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))
48 47
49typedef pthread_t thread_t; 48typedef pthread_t xthread_t;
50#define X_THREAD_PROC(name) void *name (void *thr_arg) 49#define X_THREAD_PROC(name) void *name (void *thr_arg)
51#define X_THREAD_ATFORK(a,b,c) 50#define X_THREAD_ATFORK(a,b,c)
52 51
53static int 52static int
54thread_create (thread_t *tid, void *(*proc)(void *), void *arg) 53thread_create (xthread_t *tid, void *(*proc)(void *), void *arg)
55{ 54{
56 int retval; 55 int retval;
57 pthread_attr_t attr; 56 pthread_attr_t attr;
58 57
59 pthread_attr_init (&attr); 58 pthread_attr_init (&attr);
92#include <fcntl.h> 91#include <fcntl.h>
93#include <signal.h> 92#include <signal.h>
94#include <limits.h> 93#include <limits.h>
95#include <pthread.h> 94#include <pthread.h>
96 95
97typedef pthread_mutex_t mutex_t; 96typedef pthread_mutex_t xmutex_t;
98#if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) 97#if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP)
99# define X_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP 98# define X_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
100#else 99#else
101# define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER 100# define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
102#endif 101#endif
103#define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) 102#define X_LOCK(mutex) pthread_mutex_lock (&(mutex))
104#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) 103#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
105 104
106typedef pthread_cond_t cond_t; 105typedef pthread_cond_t xcond_t;
107#define X_COND_INIT PTHREAD_COND_INITIALIZER 106#define X_COND_INIT PTHREAD_COND_INITIALIZER
108#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) 107#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond))
109#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) 108#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex))
110#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))
111 110
112typedef pthread_t thread_t; 111typedef pthread_t xthread_t;
113#define X_THREAD_PROC(name) static void *name (void *thr_arg) 112#define X_THREAD_PROC(name) static void *name (void *thr_arg)
114#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)
115 114
116// the broken bsd's once more 115// the broken bsd's once more
117#ifndef PTHREAD_STACK_MIN 116#ifndef PTHREAD_STACK_MIN
118# define PTHREAD_STACK_MIN 0 117# define PTHREAD_STACK_MIN 0
119#endif 118#endif
120 119
120#ifndef X_STACKSIZE
121# define X_STACKSIZE sizeof (long) * 4096
122#endif
123
121static int 124static int
122thread_create (thread_t *tid, void *(*proc)(void *), void *arg) 125thread_create (xthread_t *tid, void *(*proc)(void *), void *arg)
123{ 126{
124 int retval; 127 int retval;
125 sigset_t fullsigset, oldsigset; 128 sigset_t fullsigset, oldsigset;
126 pthread_attr_t attr; 129 pthread_attr_t attr;
127 130
128 pthread_attr_init (&attr); 131 pthread_attr_init (&attr);
129 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); 132 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
130 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);
131 ? sizeof (long) * 4096 : PTHREAD_STACK_MIN);
132#ifdef PTHREAD_SCOPE_PROCESS 134#ifdef PTHREAD_SCOPE_PROCESS
133 pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); 135 pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS);
134#endif 136#endif
135 137
136 sigfillset (&fullsigset); 138 sigfillset (&fullsigset);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines