ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.xs
(Generate patch)

Comparing IO-AIO/AIO.xs (file contents):
Revision 1.60 by root, Mon Oct 23 20:05:27 2006 UTC vs.
Revision 1.64 by root, Mon Oct 23 23:54:41 2006 UTC

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"
95 100
96typedef aio_cb *aio_req; 101typedef aio_cb *aio_req;
97typedef aio_cb *aio_req_ornot; 102typedef aio_cb *aio_req_ornot;
98 103
99enum { 104enum {
100 PRI_MIN = 4, 105 PRI_MIN = -4,
101 PRI_MAX = -4, 106 PRI_MAX = 4,
102 107
103 DEFAULT_PRI = 0, 108 DEFAULT_PRI = 0,
104 PRI_BIAS = PRI_MIN, 109 PRI_BIAS = -PRI_MIN,
105}; 110};
106 111
107static int next_pri = DEFAULT_PRI + PRI_BIAS; 112static int next_pri = DEFAULT_PRI + PRI_BIAS;
108 113
109static int started, wanted; 114static int started, wanted;
110static volatile int nreqs; 115static volatile int nreqs;
111static int max_outstanding = 1<<30; 116static int max_outstanding = 1<<30;
112static int respipe [2]; 117static 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
114static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER; 125static pthread_mutex_t reslock = AIO_MUTEX_INIT;
115static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER; 126static pthread_mutex_t reqlock = AIO_MUTEX_INIT;
116static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; 127static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER;
117 128
118static volatile aio_req reqs, reqe; /* queue start, queue end */ 129static volatile aio_req reqs, reqe; /* queue start, queue end */
119static volatile aio_req ress, rese; /* queue start, queue end */ 130static volatile aio_req ress, rese; /* queue start, queue end */
120 131
191 } 202 }
192} 203}
193 204
194static void poll_wait () 205static void poll_wait ()
195{ 206{
207 fd_set rfd;
208
196 while (nreqs) 209 while (nreqs)
197 { 210 {
198 aio_req req; 211 aio_req req;
212#if !(__x86 || __x86_64) /* safe without sempahore on this archs */
199 pthread_mutex_lock (&reslock); 213 pthread_mutex_lock (&reslock);
214#endif
200 req = ress; 215 req = ress;
216#if !(__x86 || __x86_64) /* safe without sempahore on this archs */
201 pthread_mutex_unlock (&reslock); 217 pthread_mutex_unlock (&reslock);
218#endif
202 219
203 if (req) 220 if (req)
204 return; 221 return;
205 222
206 fd_set rfd;
207 FD_ZERO(&rfd); 223 FD_ZERO(&rfd);
208 FD_SET(respipe [0], &rfd); 224 FD_SET(respipe [0], &rfd);
209 225
210 select (respipe [0] + 1, &rfd, 0, 0, 0); 226 select (respipe [0] + 1, &rfd, 0, 0, 0);
211 } 227 }
1260#if 0 1276#if 0
1261 1277
1262void 1278void
1263aio_pri (int pri = DEFAULT_PRI) 1279aio_pri (int pri = DEFAULT_PRI)
1264 CODE: 1280 CODE:
1265 if (pri > PRI_MIN) pri = PRI_MIN; 1281 if (pri < PRI_MIN) pri = PRI_MIN;
1266 if (pri < PRI_MAX) pri = PRI_MAX; 1282 if (pri > PRI_MAX) pri = PRI_MAX;
1267 next_pri = pri + PRI_BIAS; 1283 next_pri = pri + PRI_BIAS;
1268 1284
1269#endif 1285#endif
1270 1286
1271void 1287void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines