|
|
1 | #if __linux |
|
|
2 | # define _GNU_SOURCE |
|
|
3 | #endif |
|
|
4 | |
1 | #define _REENTRANT 1 |
5 | #define _REENTRANT 1 |
|
|
6 | |
2 | #include <errno.h> |
7 | #include <errno.h> |
3 | |
8 | |
4 | #include "EXTERN.h" |
9 | #include "EXTERN.h" |
5 | #include "perl.h" |
10 | #include "perl.h" |
6 | #include "XSUB.h" |
11 | #include "XSUB.h" |
… | |
… | |
109 | static int started, wanted; |
114 | static int started, wanted; |
110 | static volatile int nreqs; |
115 | static volatile int nreqs; |
111 | static int max_outstanding = 1<<30; |
116 | static int max_outstanding = 1<<30; |
112 | static int respipe [2]; |
117 | static int respipe [2]; |
113 | |
118 | |
|
|
119 | #if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) |
|
|
120 | # define AIO_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP |
|
|
121 | #else |
|
|
122 | # define AIO_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER |
|
|
123 | #endif |
|
|
124 | |
114 | static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER; |
125 | static pthread_mutex_t reslock = AIO_MUTEX_INIT; |
115 | static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER; |
126 | static pthread_mutex_t reqlock = AIO_MUTEX_INIT; |
116 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
127 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
117 | |
128 | |
118 | static volatile aio_req reqs, reqe; /* queue start, queue end */ |
129 | static volatile aio_req reqs, reqe; /* queue start, queue end */ |
119 | static volatile aio_req ress, rese; /* queue start, queue end */ |
130 | static volatile aio_req ress, rese; /* queue start, queue end */ |
120 | |
131 | |
… | |
… | |
196 | fd_set rfd; |
207 | fd_set rfd; |
197 | |
208 | |
198 | while (nreqs) |
209 | while (nreqs) |
199 | { |
210 | { |
200 | aio_req req; |
211 | aio_req req; |
|
|
212 | #if !(__x86 || __x86_64) /* safe without sempahore on this archs */ |
201 | pthread_mutex_lock (&reslock); |
213 | pthread_mutex_lock (&reslock); |
|
|
214 | #endif |
202 | req = ress; |
215 | req = ress; |
|
|
216 | #if !(__x86 || __x86_64) /* safe without sempahore on this archs */ |
203 | pthread_mutex_unlock (&reslock); |
217 | pthread_mutex_unlock (&reslock); |
|
|
218 | #endif |
204 | |
219 | |
205 | if (req) |
220 | if (req) |
206 | return; |
221 | return; |
207 | |
222 | |
208 | FD_ZERO(&rfd); |
223 | FD_ZERO(&rfd); |