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.8 by root, Mon Jul 11 02:53:59 2005 UTC vs.
Revision 1.12 by root, Wed Jul 20 21:57:04 2005 UTC

1#define _XOPEN_SOURCE 500
2
1#include "EXTERN.h" 3#include "EXTERN.h"
2#include "perl.h" 4#include "perl.h"
3#include "XSUB.h" 5#include "XSUB.h"
4 6
5#include <sys/types.h> 7#include <sys/types.h>
6#include <sys/stat.h> 8#include <sys/stat.h>
9
7#include <unistd.h> 10#include <unistd.h>
8#include <fcntl.h> 11#include <fcntl.h>
9#include <signal.h> 12#include <signal.h>
10#include <sched.h> 13#include <sched.h>
11#include <endian.h> 14#if __linux
15#include <sys/syscall.h>
16#endif
12 17
13#include <pthread.h> 18#include <pthread.h>
14#include <sys/syscall.h>
15 19
16typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ 20typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */
17typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */ 21typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */
18typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */ 22typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */
19 23
50} aio_cb; 54} aio_cb;
51 55
52typedef aio_cb *aio_req; 56typedef aio_cb *aio_req;
53 57
54static int started; 58static int started;
55static int nreqs; 59static volatile int nreqs;
56static int max_outstanding = 1<<30; 60static int max_outstanding = 1<<30;
57static int respipe [2]; 61static int respipe [2];
58 62
59static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER; 63static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER;
60static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER; 64static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER;
64static volatile aio_req ress, rese; /* queue start, queue end */ 68static volatile aio_req ress, rese; /* queue start, queue end */
65 69
66static void 70static void
67poll_wait () 71poll_wait ()
68{ 72{
69 if (!nreqs) 73 if (nreqs && !ress)
70 return; 74 {
71
72 fd_set rfd; 75 fd_set rfd;
73 FD_ZERO(&rfd); 76 FD_ZERO(&rfd);
74 FD_SET(respipe [0], &rfd); 77 FD_SET(respipe [0], &rfd);
75 78
76 select (respipe [0] + 1, &rfd, 0, 0, 0); 79 select (respipe [0] + 1, &rfd, 0, 0, 0);
80 }
77} 81}
78 82
79static int 83static int
80poll_cb () 84poll_cb ()
81{ 85{
82 dSP; 86 dSP;
83 int count = 0; 87 int count = 0;
84 aio_req req; 88 aio_req req, prv;
85 89
90 pthread_mutex_lock (&reslock);
91
86 { 92 {
87 /* read and signals sent by the worker threads */ 93 /* read any signals sent by the worker threads */
88 char buf [32]; 94 char buf [32];
89 while (read (respipe [0], buf, 32) > 0) 95 while (read (respipe [0], buf, 32) > 0)
90 ; 96 ;
91 } 97 }
92 98
93 for (;;) 99 req = ress;
100 ress = rese = 0;
101
102 pthread_mutex_unlock (&reslock);
103
104 while (req)
94 { 105 {
95 pthread_mutex_lock (&reslock);
96
97 req = ress;
98
99 if (ress)
100 {
101 ress = ress->next;
102 if (!ress) rese = 0;
103 }
104
105 pthread_mutex_unlock (&reslock);
106
107 if (!req)
108 break;
109
110 nreqs--; 106 nreqs--;
111 107
112 if (req->type == REQ_QUIT) 108 if (req->type == REQ_QUIT)
113 started--; 109 started--;
114 else 110 else
162 158
163 errno = errorno; 159 errno = errorno;
164 count++; 160 count++;
165 } 161 }
166 162
163 prv = req;
164 req = req->next;
167 Safefree (req); 165 Safefree (prv);
166
167 /* TODO: croak on errors? */
168 } 168 }
169 169
170 return count; 170 return count;
171} 171}
172 172
309 309
310 type = req->type; 310 type = req->type;
311 311
312 switch (type) 312 switch (type)
313 { 313 {
314 case REQ_READ: req->result = pread64 (req->fd, req->dataptr, req->length, req->offset); break; 314 case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break;
315 case REQ_WRITE: req->result = pwrite64 (req->fd, req->dataptr, req->length, req->offset); break; 315 case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break;
316#if SYS_readahead 316#if SYS_readahead
317 case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; 317 case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break;
318#else 318#else
319 case REQ_READAHEAD: req->result = -1; errno = ENOSYS; break; 319 case REQ_READAHEAD: req->result = -1; errno = ENOSYS; break;
320#endif 320#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines