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.10 by root, Wed Jul 13 00:13:09 2005 UTC vs.
Revision 1.11 by root, Wed Jul 20 21:55:27 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
5#define _XOPEN_SOURCE 500
6 6
7#include <sys/types.h> 7#include <sys/types.h>
8#include <sys/stat.h> 8#include <sys/stat.h>
9 9
10#include <unistd.h> 10#include <unistd.h>
54} aio_cb; 54} aio_cb;
55 55
56typedef aio_cb *aio_req; 56typedef aio_cb *aio_req;
57 57
58static int started; 58static int started;
59static int nreqs; 59static volatile int nreqs;
60static int max_outstanding = 1<<30; 60static int max_outstanding = 1<<30;
61static int respipe [2]; 61static int respipe [2];
62 62
63static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER; 63static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER;
64static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER; 64static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER;
68static volatile aio_req ress, rese; /* queue start, queue end */ 68static volatile aio_req ress, rese; /* queue start, queue end */
69 69
70static void 70static void
71poll_wait () 71poll_wait ()
72{ 72{
73 if (!nreqs) 73 if (nreqs && !ress)
74 return; 74 {
75
76 fd_set rfd; 75 fd_set rfd;
77 FD_ZERO(&rfd); 76 FD_ZERO(&rfd);
78 FD_SET(respipe [0], &rfd); 77 FD_SET(respipe [0], &rfd);
79 78
80 select (respipe [0] + 1, &rfd, 0, 0, 0); 79 select (respipe [0] + 1, &rfd, 0, 0, 0);
80 }
81} 81}
82 82
83static int 83static int
84poll_cb () 84poll_cb ()
85{ 85{
86 dSP; 86 dSP;
87 int count = 0; 87 int count = 0;
88 aio_req req; 88 aio_req req, prv;
89 89
90 static int rl;//D
91 //printf ("%d ENTER\n", ++rl);//D
92
93 pthread_mutex_lock (&reslock);
94
90 { 95 {
91 /* read and signals sent by the worker threads */ 96 /* read any signals sent by the worker threads */
92 char buf [32]; 97 char buf [32];
93 while (read (respipe [0], buf, 32) > 0) 98 while (read (respipe [0], buf, 32) > 0)
94 ; 99 ;
95 } 100 }
96 101
97 for (;;) 102 req = ress;
103 ress = rese = 0;
104
105 pthread_mutex_unlock (&reslock);
106
107 while (req)
98 { 108 {
99 pthread_mutex_lock (&reslock);
100
101 req = ress;
102
103 if (ress)
104 {
105 ress = ress->next;
106 if (!ress) rese = 0;
107 }
108
109 pthread_mutex_unlock (&reslock);
110
111 if (!req)
112 break;
113
114 nreqs--; 109 nreqs--;
110 //printf ("%d count %d %p->%p\n", rl, count, req, req->next);//D
115 111
116 if (req->type == REQ_QUIT) 112 if (req->type == REQ_QUIT)
117 started--; 113 started--;
118 else 114 else
119 { 115 {
166 162
167 errno = errorno; 163 errno = errorno;
168 count++; 164 count++;
169 } 165 }
170 166
167 prv = req;
168 req = req->next;
171 Safefree (req); 169 Safefree (prv);
170
171 /* TODO: croak on errors? */
172 } 172 }
173 173
174 //printf ("%d LEAVE %p %p\n", rl--, ress, rese);//D
174 return count; 175 return count;
175} 176}
176 177
177static void *aio_proc(void *arg); 178static void *aio_proc(void *arg);
178 179

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines