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

Comparing BDB/xthread.h (file contents):
Revision 1.6 by root, Mon Apr 21 20:09:44 2008 UTC vs.
Revision 1.10 by root, Sat Oct 23 09:40:53 2010 UTC

1#ifndef XTHREAD_H_
2#define XTHREAD_H_
3
1/* wether word reads are potentially non-atomic. 4/* whether word reads are potentially non-atomic.
2 * this is conservatice, likely most arches this runs 5 * this is conservatice, likely most arches this runs
3 * on have atomic word read/writes. 6 * on have atomic word read/writes.
4 */ 7 */
5#ifndef WORDACCESS_UNSAFE 8#ifndef WORDACCESS_UNSAFE
6# if __i386 || __x86_64 9# if __i386 || __x86_64
24#include <winsock2.h> 27#include <winsock2.h>
25#include <process.h> 28#include <process.h>
26#include <windows.h> 29#include <windows.h>
27#include <pthread.h> 30#include <pthread.h>
28#define sigset_t int 31#define sigset_t int
29#define sigfillset(a)
30#define pthread_sigmask(a,b,c) 32#define pthread_sigmask(a,b,c)
31#define sigaddset(a,b) 33#define sigaddset(a,b)
32#define sigemptyset(s) 34#define sigemptyset(s)
33#define sigfillset(s) 35#define sigfillset(s)
34 36
35typedef pthread_mutex_t mutex_t; 37typedef pthread_mutex_t xmutex_t;
36#define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER 38#define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
37#define X_MUTEX_CHECK(mutex)
38#define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) 39#define X_LOCK(mutex) pthread_mutex_lock (&(mutex))
39#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) 40#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
40 41
41typedef pthread_cond_t cond_t; 42typedef pthread_cond_t xcond_t;
42#define X_COND_INIT PTHREAD_COND_INITIALIZER 43#define X_COND_INIT PTHREAD_COND_INITIALIZER
43#define X_COND_CHECK(cond)
44#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) 44#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond))
45#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) 45#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex))
46#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))
47 47
48typedef pthread_t thread_t; 48typedef pthread_t xthread_t;
49#define X_THREAD_PROC(name) void *name (void *thr_arg) 49#define X_THREAD_PROC(name) void *name (void *thr_arg)
50#define X_THREAD_ATFORK(a,b,c) 50#define X_THREAD_ATFORK(a,b,c)
51 51
52static int 52static int
53thread_create (thread_t *tid, void *(*proc)(void *), void *arg) 53thread_create (xthread_t *tid, void *(*proc)(void *), void *arg)
54{ 54{
55 int retval;
55 pthread_attr_t attr; 56 pthread_attr_t attr;
56 57
57 pthread_attr_init (&attr); 58 pthread_attr_init (&attr);
58 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); 59 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
59 60
60 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;
61} 66}
62 67
63#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)
64#define respipe_write(a,b,c) send ((a), (b), (c), 0) 69#define respipe_write(a,b,c) send ((a), (b), (c), 0)
65#define respipe_close(a) PerlSock_closesocket ((a)) 70#define respipe_close(a) PerlSock_closesocket ((a))
66 71
67#else 72#else
68///////////////////////////////////////////////////////////////////////////// 73/////////////////////////////////////////////////////////////////////////////
69 74
70/* solaris */
71#define _POSIX_PTHREAD_SEMANTICS 1
72
73#if __linux && !defined(_GNU_SOURCE) 75#if __linux && !defined(_GNU_SOURCE)
74# define _GNU_SOURCE 76# define _GNU_SOURCE
75#endif 77#endif
76 78
77/* just in case */ 79/* just in case */
78#define _REENTRANT 1 80#define _REENTRANT 1
79 81
80#if __solaris 82#if __solaris
83# define _POSIX_PTHREAD_SEMANTICS 1
81/* try to bribe solaris headers into providing a current pthread API 84/* try to bribe solaris headers into providing a current pthread API
82 * despite perl being configured for an older version. 85 * despite environment being configured for an older version.
83 */ 86 */
84# define __EXTENSIONS__ 1 87# define __EXTENSIONS__ 1
85#endif 88#endif
86 89
87#include <unistd.h> 90#include <unistd.h>
88#include <fcntl.h> 91#include <fcntl.h>
89#include <signal.h> 92#include <signal.h>
90#include <limits.h> 93#include <limits.h>
91#include <pthread.h> 94#include <pthread.h>
92 95
93typedef pthread_mutex_t mutex_t; 96typedef pthread_mutex_t xmutex_t;
94#if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) 97#if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP)
95# define X_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP 98# define X_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
96#else 99#else
97# define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER 100# define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
98#endif 101#endif
99#define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) 102#define X_LOCK(mutex) pthread_mutex_lock (&(mutex))
100#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) 103#define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
101 104
102typedef pthread_cond_t cond_t; 105typedef pthread_cond_t xcond_t;
103#define X_COND_INIT PTHREAD_COND_INITIALIZER 106#define X_COND_INIT PTHREAD_COND_INITIALIZER
104#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) 107#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond))
105#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) 108#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex))
106#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))
107 110
108typedef pthread_t thread_t; 111typedef pthread_t xthread_t;
109#define X_THREAD_PROC(name) static void *name (void *thr_arg) 112#define X_THREAD_PROC(name) static void *name (void *thr_arg)
110#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)
111 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
112static int 124static int
113thread_create (thread_t *tid, void *(*proc)(void *), void *arg) 125thread_create (xthread_t *tid, void *(*proc)(void *), void *arg)
114{ 126{
115 int retval; 127 int retval;
116 sigset_t fullsigset, oldsigset; 128 sigset_t fullsigset, oldsigset;
117 pthread_attr_t attr; 129 pthread_attr_t attr;
118 130
119 pthread_attr_init (&attr); 131 pthread_attr_init (&attr);
120 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); 132 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
121 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);
122 ? sizeof (long) * 4096 : PTHREAD_STACK_MIN);
123#ifdef PTHREAD_SCOPE_PROCESS 134#ifdef PTHREAD_SCOPE_PROCESS
124 pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); 135 pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS);
125#endif 136#endif
126 137
127 sigfillset (&fullsigset); 138 sigfillset (&fullsigset);
128 139
129 pthread_sigmask (SIG_SETMASK, &fullsigset, &oldsigset); 140 pthread_sigmask (SIG_SETMASK, &fullsigset, &oldsigset);
130 retval = pthread_create (tid, &attr, proc, arg) == 0; 141 retval = pthread_create (tid, &attr, proc, arg) == 0;
131 pthread_sigmask (SIG_SETMASK, &oldsigset, 0); 142 pthread_sigmask (SIG_SETMASK, &oldsigset, 0);
132 143
144 pthread_attr_destroy (&attr);
145
133 return retval; 146 return retval;
134} 147}
135 148
136#define respipe_read(a,b,c) read ((a), (b), (c)) 149#define respipe_read(a,b,c) read ((a), (b), (c))
137#define respipe_write(a,b,c) write ((a), (b), (c)) 150#define respipe_write(a,b,c) write ((a), (b), (c))
138#define respipe_close(a) close ((a)) 151#define respipe_close(a) close ((a))
139 152
140#endif 153#endif
141 154
155#endif
142 156
143

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines