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

Comparing libeio/xthread.h (file contents):
Revision 1.13 by root, Tue Jul 19 04:57:10 2011 UTC vs.
Revision 1.19 by root, Tue Aug 14 09:29:50 2018 UTC

15 15
16///////////////////////////////////////////////////////////////////////////// 16/////////////////////////////////////////////////////////////////////////////
17 17
18#ifdef _WIN32 18#ifdef _WIN32
19 19
20#define NTDDI_VERSION NTDDI_WIN2K // needed to get win2000 api calls 20//#define NTDDI_VERSION NTDDI_WIN2K // needed to get win2000 api calls, fails with mingw
21#define _WIN32_WINNT 0x400 21#if _WIN32_WINNT < 0x400
22# define _WIN32_WINNT 0x400 // maybe working alternative for mingw
23#endif
22#include <stdio.h>//D 24#include <stdio.h>//D
23#include <fcntl.h> 25#include <fcntl.h>
24#include <io.h> 26#include <io.h>
25#include <time.h> 27#include <time.h>
26#include <winsock2.h> 28#include <winsock2.h>
27#include <process.h> 29#include <process.h>
28#include <windows.h> 30#include <windows.h>
31
32/* work around some bugs in ptw32 */
33#if defined(__MINGW32__) && defined(_TIMESPEC_DEFINED)
34#define HAVE_STRUCT_TIMESPEC 1
35#endif
36
29#include <pthread.h> 37#include <pthread.h>
38#ifndef pthread_sigmask
30#define sigset_t int 39# define sigset_t int
31#define sigfillset(a) 40# define sigfillset(a)
32#define pthread_sigmask(a,b,c) 41# define pthread_sigmask(a,b,c)
33#define sigaddset(a,b) 42# define sigaddset(a,b)
34#define sigemptyset(s) 43# define sigemptyset(s)
35#define sigfillset(s) 44#endif
36 45
37typedef pthread_mutex_t xmutex_t; 46typedef pthread_mutex_t xmutex_t;
38#define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER 47#define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
39#define X_MUTEX_CREATE(mutex) pthread_mutex_init (&(mutex), 0) 48#define X_MUTEX_CREATE(mutex) pthread_mutex_init (&(mutex), 0)
40#define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) 49#define X_LOCK(mutex) pthread_mutex_lock (&(mutex))
46#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) 55#define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond))
47#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) 56#define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex))
48#define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to)) 57#define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to))
49 58
50typedef pthread_t xthread_t; 59typedef pthread_t xthread_t;
51#define X_THREAD_PROC(name) void *name (void *thr_arg) 60#define X_THREAD_PROC(name) static void *name (void *thr_arg)
52#define X_THREAD_ATFORK(a,b,c) 61#define X_THREAD_ATFORK(a,b,c)
53 62
54static int 63static int
55thread_create (xthread_t *tid, void *(*proc)(void *), void *arg) 64xthread_create (xthread_t *tid, void *(*proc)(void *), void *arg)
56{ 65{
57 int retval; 66 int retval;
67#if 0
58 pthread_attr_t attr; 68 pthread_attr_t attr;
59 69
60 pthread_attr_init (&attr); 70 pthread_attr_init (&attr);
61 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); 71 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
62 72
63 retval = pthread_create (tid, &attr, proc, arg) == 0; 73 retval = pthread_create (tid, &attr, proc, arg) == 0;
64 74
65 pthread_attr_destroy (&attr); 75 pthread_attr_destroy (&attr);
76#else
77 retval = pthread_create (tid, 0, proc, arg) == 0;
78
79 if (retval)
80 pthread_detach (*tid);
81#endif
66 82
67 return retval; 83 return retval;
68} 84}
69 85
70#define respipe_read(a,b,c) PerlSock_recv ((a), (b), (c), 0) 86#define respipe_read(a,b,c) PerlSock_recv ((a), (b), (c), 0)
131#ifndef X_STACKSIZE 147#ifndef X_STACKSIZE
132# define X_STACKSIZE sizeof (void *) * 4096 148# define X_STACKSIZE sizeof (void *) * 4096
133#endif 149#endif
134 150
135static int 151static int
136thread_create (xthread_t *tid, void *(*proc)(void *), void *arg) 152xthread_create (xthread_t *tid, void *(*proc)(void *), void *arg)
137{ 153{
138 int retval; 154 int retval;
139 sigset_t fullsigset, oldsigset; 155 sigset_t fullsigset, oldsigset;
140 pthread_attr_t attr; 156 pthread_attr_t attr;
141 157
161#define respipe_write(a,b,c) write ((a), (b), (c)) 177#define respipe_write(a,b,c) write ((a), (b), (c))
162#define respipe_close(a) close ((a)) 178#define respipe_close(a) close ((a))
163 179
164#endif 180#endif
165 181
182#if __linux && __GNUC__ >= 4 && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 3 && 0 /* also check arch */
183/* __thread has little to no advantage over pthread_* in most configurations, so this is not used */
184# define X_TLS_DECLARE(varname) __thread void *varname
185# define X_TLS_INIT(varname)
186# define X_TLS_SET(varname,value) varname = (value)
187# define X_TLS_GET(varname) varname
188#else
189# define X_TLS_DECLARE(varname) pthread_key_t varname
190# define X_TLS_INIT(varname) do { if (pthread_key_create (&(varname), 0)) abort (); } while (0)
191# define X_TLS_SET(varname,value) pthread_setspecific (varname, (value))
192# define X_TLS_GET(varname) pthread_getspecific (varname)
166#endif 193#endif
167 194
195#endif
196

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines