|
|
1 | /* |
|
|
2 | * libeio implementation |
|
|
3 | * |
|
|
4 | * Copyright (c) 2007,2008 Marc Alexander Lehmann <libeio@schmorp.de> |
|
|
5 | * All rights reserved. |
|
|
6 | * |
|
|
7 | * Redistribution and use in source and binary forms, with or without modifica- |
|
|
8 | * tion, are permitted provided that the following conditions are met: |
|
|
9 | * |
|
|
10 | * 1. Redistributions of source code must retain the above copyright notice, |
|
|
11 | * this list of conditions and the following disclaimer. |
|
|
12 | * |
|
|
13 | * 2. Redistributions in binary form must reproduce the above copyright |
|
|
14 | * notice, this list of conditions and the following disclaimer in the |
|
|
15 | * documentation and/or other materials provided with the distribution. |
|
|
16 | * |
|
|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
|
18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- |
|
|
19 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
|
20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- |
|
|
21 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
|
22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
|
23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
|
24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- |
|
|
25 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
|
|
26 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
|
|
27 | * |
|
|
28 | * Alternatively, the contents of this file may be used under the terms of |
|
|
29 | * the GNU General Public License ("GPL") version 2 or any later version, |
|
|
30 | * in which case the provisions of the GPL are applicable instead of |
|
|
31 | * the above. If you wish to allow the use of your version of this file |
|
|
32 | * only under the terms of the GPL and not to allow others to use your |
|
|
33 | * version of this file under the BSD license, indicate your decision |
|
|
34 | * by deleting the provisions above and replace them with the notice |
|
|
35 | * and other provisions required by the GPL. If you do not delete the |
|
|
36 | * provisions above, a recipient may use your version of this file under |
|
|
37 | * either the BSD or the GPL. |
|
|
38 | */ |
|
|
39 | |
1 | #include "eio.h" |
40 | #include "eio.h" |
2 | #include "xthread.h" |
41 | #include "xthread.h" |
3 | |
42 | |
4 | #include <errno.h> |
43 | #include <errno.h> |
5 | #include <stddef.h> |
44 | #include <stddef.h> |
… | |
… | |
70 | /* buffer size for various temporary buffers */ |
109 | /* buffer size for various temporary buffers */ |
71 | #define EIO_BUFSIZE 65536 |
110 | #define EIO_BUFSIZE 65536 |
72 | |
111 | |
73 | #define dBUF \ |
112 | #define dBUF \ |
74 | char *eio_buf; \ |
113 | char *eio_buf; \ |
75 | X_LOCK (etplock); \ |
114 | ETP_WORKER_LOCK (self); \ |
76 | self->dbuf = eio_buf = malloc (EIO_BUFSIZE); \ |
115 | self->dbuf = eio_buf = malloc (EIO_BUFSIZE); \ |
77 | X_UNLOCK (etplock); \ |
116 | ETP_WORKER_UNLOCK (self); \ |
78 | errno = ENOMEM; \ |
117 | errno = ENOMEM; \ |
79 | if (!eio_buf) \ |
118 | if (!eio_buf) \ |
80 | return -1; |
119 | return -1; |
81 | |
120 | |
82 | #define EIO_TICKS ((1000000 + 1023) >> 10) |
121 | #define EIO_TICKS ((1000000 + 1023) >> 10) |
83 | |
122 | |
84 | /*****************************************************************************/ |
123 | /*****************************************************************************/ |
85 | |
124 | |
|
|
125 | #define ETP_PRI_MIN EIO_PRI_MIN |
|
|
126 | #define ETP_PRI_MAX EIO_PRI_MAX |
|
|
127 | |
|
|
128 | #define ETP_REQ eio_req |
|
|
129 | #define ETP_DESTROY(req) eio_destroy (req) |
|
|
130 | static int eio_finish (eio_req *req); |
|
|
131 | #define ETP_FINISH(req) eio_finish (req) |
|
|
132 | |
|
|
133 | #define ETP_WORKER_CLEAR(req) \ |
|
|
134 | if (wrk->dbuf) \ |
|
|
135 | { \ |
|
|
136 | free (wrk->dbuf); \ |
|
|
137 | wrk->dbuf = 0; \ |
|
|
138 | } \ |
|
|
139 | \ |
|
|
140 | if (wrk->dirp) \ |
|
|
141 | { \ |
|
|
142 | closedir (wrk->dirp); \ |
|
|
143 | wrk->dirp = 0; \ |
|
|
144 | } |
|
|
145 | #define ETP_WORKER_COMMON \ |
|
|
146 | void *dbuf; \ |
|
|
147 | DIR *dirp; |
|
|
148 | |
|
|
149 | /*****************************************************************************/ |
|
|
150 | |
|
|
151 | #define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1) |
|
|
152 | |
86 | /* calculcate time difference in ~1/EIO_TICKS of a second */ |
153 | /* calculcate time difference in ~1/EIO_TICKS of a second */ |
87 | static int tvdiff (struct timeval *tv1, struct timeval *tv2) |
154 | static int tvdiff (struct timeval *tv1, struct timeval *tv2) |
88 | { |
155 | { |
89 | return (tv2->tv_sec - tv1->tv_sec ) * EIO_TICKS |
156 | return (tv2->tv_sec - tv1->tv_sec ) * EIO_TICKS |
90 | + ((tv2->tv_usec - tv1->tv_usec) >> 10); |
157 | + ((tv2->tv_usec - tv1->tv_usec) >> 10); |
91 | } |
158 | } |
92 | |
159 | |
93 | static unsigned int started, idle, wanted = 4; |
160 | static unsigned int started, idle, wanted = 4; |
94 | |
161 | |
95 | typedef struct etp_pool |
|
|
96 | { |
|
|
97 | void (*want_poll_cb) (void); |
162 | static void (*want_poll_cb) (void); |
98 | void (*done_poll_cb) (void); |
163 | static void (*done_poll_cb) (void); |
99 | |
164 | |
100 | unsigned int max_poll_time; |
165 | static unsigned int max_poll_time; /* reslock */ |
101 | unsigned int max_poll_reqs; |
166 | static unsigned int max_poll_reqs; /* reslock */ |
102 | } etp_pool; |
|
|
103 | |
167 | |
104 | static volatile unsigned int nreqs, nready, npending; |
168 | static volatile unsigned int nreqs; /* reqlock */ |
|
|
169 | static volatile unsigned int nready; /* reqlock */ |
|
|
170 | static volatile unsigned int npending; /* reqlock */ |
105 | static volatile unsigned int max_idle = 4; |
171 | static volatile unsigned int max_idle = 4; |
106 | |
172 | |
107 | static mutex_t etplock = X_MUTEX_INIT; |
173 | static mutex_t wrklock = X_MUTEX_INIT; |
108 | static mutex_t reslock = X_MUTEX_INIT; |
174 | static mutex_t reslock = X_MUTEX_INIT; |
109 | static mutex_t reqlock = X_MUTEX_INIT; |
175 | static mutex_t reqlock = X_MUTEX_INIT; |
110 | static cond_t reqwait = X_COND_INIT; |
176 | static cond_t reqwait = X_COND_INIT; |
111 | |
177 | |
112 | typedef struct worker |
178 | typedef struct etp_worker |
113 | { |
179 | { |
114 | /* locked by etplock */ |
180 | /* locked by wrklock */ |
115 | struct worker *prev, *next; |
181 | struct etp_worker *prev, *next; |
116 | |
182 | |
117 | thread_t tid; |
183 | thread_t tid; |
118 | |
184 | |
119 | /* locked by reslock, reqlock or etplock */ |
185 | /* locked by reslock, reqlock or wrklock */ |
120 | eio_req *req; /* currently processed request */ |
186 | ETP_REQ *req; /* currently processed request */ |
121 | void *dbuf; |
187 | |
122 | DIR *dirp; |
188 | ETP_WORKER_COMMON |
123 | } worker; |
189 | } etp_worker; |
124 | |
190 | |
125 | static worker wrk_first = { &wrk_first, &wrk_first, 0 }; /* NOT etp */ |
191 | static etp_worker wrk_first = { &wrk_first, &wrk_first, 0 }; /* NOT etp */ |
|
|
192 | |
|
|
193 | #define ETP_WORKER_LOCK(wrk) X_LOCK (wrklock) |
|
|
194 | #define ETP_WORKER_UNLOCK(wrk) X_UNLOCK (wrklock) |
126 | |
195 | |
127 | /* worker threads management */ |
196 | /* worker threads management */ |
128 | |
197 | |
129 | static void worker_clear (worker *wrk) |
198 | static void etp_worker_clear (etp_worker *wrk) |
130 | { |
199 | { |
131 | if (wrk->dirp) |
200 | ETP_WORKER_CLEAR (wrk); |
132 | { |
|
|
133 | closedir (wrk->dirp); |
|
|
134 | wrk->dirp = 0; |
|
|
135 | } |
|
|
136 | |
|
|
137 | if (wrk->dbuf) |
|
|
138 | { |
|
|
139 | free (wrk->dbuf); |
|
|
140 | wrk->dbuf = 0; |
|
|
141 | } |
|
|
142 | } |
201 | } |
143 | |
202 | |
144 | static void worker_free (worker *wrk) |
203 | static void etp_worker_free (etp_worker *wrk) |
145 | { |
204 | { |
146 | wrk->next->prev = wrk->prev; |
205 | wrk->next->prev = wrk->prev; |
147 | wrk->prev->next = wrk->next; |
206 | wrk->prev->next = wrk->next; |
148 | |
207 | |
149 | free (wrk); |
208 | free (wrk); |
150 | } |
209 | } |
151 | |
210 | |
152 | unsigned int eio_nreqs (void) |
211 | static unsigned int etp_nreqs (void) |
153 | { |
212 | { |
|
|
213 | int retval; |
|
|
214 | if (WORDACCESS_UNSAFE) X_LOCK (reqlock); |
|
|
215 | retval = nreqs; |
|
|
216 | if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); |
154 | return nreqs; |
217 | return retval; |
155 | } |
218 | } |
156 | |
219 | |
157 | unsigned int eio_nready (void) |
220 | static unsigned int etp_nready (void) |
158 | { |
221 | { |
159 | unsigned int retval; |
222 | unsigned int retval; |
160 | |
223 | |
161 | if (WORDACCESS_UNSAFE) X_LOCK (reqlock); |
224 | if (WORDACCESS_UNSAFE) X_LOCK (reqlock); |
162 | retval = nready; |
225 | retval = nready; |
163 | if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); |
226 | if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); |
164 | |
227 | |
165 | return retval; |
228 | return retval; |
166 | } |
229 | } |
167 | |
230 | |
168 | unsigned int eio_npending (void) |
231 | static unsigned int etp_npending (void) |
169 | { |
232 | { |
170 | unsigned int retval; |
233 | unsigned int retval; |
171 | |
234 | |
172 | if (WORDACCESS_UNSAFE) X_LOCK (reqlock); |
235 | if (WORDACCESS_UNSAFE) X_LOCK (reqlock); |
173 | retval = npending; |
236 | retval = npending; |
174 | if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); |
237 | if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); |
175 | |
238 | |
176 | return retval; |
239 | return retval; |
177 | } |
240 | } |
178 | |
241 | |
179 | unsigned int eio_nthreads (void) |
242 | static unsigned int etp_nthreads (void) |
180 | { |
243 | { |
181 | unsigned int retval; |
244 | unsigned int retval; |
182 | |
245 | |
183 | if (WORDACCESS_UNSAFE) X_LOCK (reqlock); |
246 | if (WORDACCESS_UNSAFE) X_LOCK (reqlock); |
184 | retval = started; |
247 | retval = started; |
… | |
… | |
191 | * a somewhat faster data structure might be nice, but |
254 | * a somewhat faster data structure might be nice, but |
192 | * with 8 priorities this actually needs <20 insns |
255 | * with 8 priorities this actually needs <20 insns |
193 | * per shift, the most expensive operation. |
256 | * per shift, the most expensive operation. |
194 | */ |
257 | */ |
195 | typedef struct { |
258 | typedef struct { |
196 | eio_req *qs[EIO_NUM_PRI], *qe[EIO_NUM_PRI]; /* qstart, qend */ |
259 | ETP_REQ *qs[ETP_NUM_PRI], *qe[ETP_NUM_PRI]; /* qstart, qend */ |
197 | int size; |
260 | int size; |
198 | } reqq; |
261 | } etp_reqq; |
199 | |
262 | |
200 | static reqq req_queue; |
263 | static etp_reqq req_queue; |
201 | static reqq res_queue; |
264 | static etp_reqq res_queue; |
202 | |
265 | |
203 | static int reqq_push (reqq *q, eio_req *req) |
266 | static int reqq_push (etp_reqq *q, ETP_REQ *req) |
204 | { |
267 | { |
205 | int pri = req->pri; |
268 | int pri = req->pri; |
206 | req->next = 0; |
269 | req->next = 0; |
207 | |
270 | |
208 | if (q->qe[pri]) |
271 | if (q->qe[pri]) |
… | |
… | |
214 | q->qe[pri] = q->qs[pri] = req; |
277 | q->qe[pri] = q->qs[pri] = req; |
215 | |
278 | |
216 | return q->size++; |
279 | return q->size++; |
217 | } |
280 | } |
218 | |
281 | |
219 | static eio_req *reqq_shift (reqq *q) |
282 | static ETP_REQ *reqq_shift (etp_reqq *q) |
220 | { |
283 | { |
221 | int pri; |
284 | int pri; |
222 | |
285 | |
223 | if (!q->size) |
286 | if (!q->size) |
224 | return 0; |
287 | return 0; |
225 | |
288 | |
226 | --q->size; |
289 | --q->size; |
227 | |
290 | |
228 | for (pri = EIO_NUM_PRI; pri--; ) |
291 | for (pri = ETP_NUM_PRI; pri--; ) |
229 | { |
292 | { |
230 | eio_req *req = q->qs[pri]; |
293 | eio_req *req = q->qs[pri]; |
231 | |
294 | |
232 | if (req) |
295 | if (req) |
233 | { |
296 | { |
… | |
… | |
241 | abort (); |
304 | abort (); |
242 | } |
305 | } |
243 | |
306 | |
244 | static void etp_atfork_prepare (void) |
307 | static void etp_atfork_prepare (void) |
245 | { |
308 | { |
246 | X_LOCK (etplock); |
309 | X_LOCK (wrklock); |
247 | X_LOCK (reqlock); |
310 | X_LOCK (reqlock); |
248 | X_LOCK (reslock); |
311 | X_LOCK (reslock); |
249 | #if !HAVE_PREADWRITE |
312 | #if !HAVE_PREADWRITE |
250 | X_LOCK (preadwritelock); |
313 | X_LOCK (preadwritelock); |
251 | #endif |
314 | #endif |
… | |
… | |
262 | #if !HAVE_PREADWRITE |
325 | #if !HAVE_PREADWRITE |
263 | X_UNLOCK (preadwritelock); |
326 | X_UNLOCK (preadwritelock); |
264 | #endif |
327 | #endif |
265 | X_UNLOCK (reslock); |
328 | X_UNLOCK (reslock); |
266 | X_UNLOCK (reqlock); |
329 | X_UNLOCK (reqlock); |
267 | X_UNLOCK (etplock); |
330 | X_UNLOCK (wrklock); |
268 | } |
331 | } |
269 | |
332 | |
270 | static void etp_atfork_child (void) |
333 | static void etp_atfork_child (void) |
271 | { |
334 | { |
272 | eio_req *prv; |
335 | ETP_REQ *prv; |
273 | |
336 | |
274 | while (prv = reqq_shift (&req_queue)) |
337 | while (prv = reqq_shift (&req_queue)) |
275 | eio_destroy (prv); |
338 | ETP_DESTROY (prv); |
276 | |
339 | |
277 | while (prv = reqq_shift (&res_queue)) |
340 | while (prv = reqq_shift (&res_queue)) |
278 | eio_destroy (prv); |
341 | ETP_DESTROY (prv); |
279 | |
342 | |
280 | while (wrk_first.next != &wrk_first) |
343 | while (wrk_first.next != &wrk_first) |
281 | { |
344 | { |
282 | worker *wrk = wrk_first.next; |
345 | etp_worker *wrk = wrk_first.next; |
283 | |
346 | |
284 | if (wrk->req) |
347 | if (wrk->req) |
285 | eio_destroy (wrk->req); |
348 | ETP_DESTROY (wrk->req); |
286 | |
349 | |
287 | worker_clear (wrk); |
350 | etp_worker_clear (wrk); |
288 | worker_free (wrk); |
351 | etp_worker_free (wrk); |
289 | } |
352 | } |
290 | |
353 | |
291 | started = 0; |
354 | started = 0; |
292 | idle = 0; |
355 | idle = 0; |
293 | nreqs = 0; |
356 | nreqs = 0; |
… | |
… | |
302 | { |
365 | { |
303 | X_THREAD_ATFORK (etp_atfork_prepare, etp_atfork_parent, etp_atfork_child); |
366 | X_THREAD_ATFORK (etp_atfork_prepare, etp_atfork_parent, etp_atfork_child); |
304 | } |
367 | } |
305 | |
368 | |
306 | static int |
369 | static int |
307 | etp_init (etp_pool *etp, void (*want_poll)(void), void (*done_poll)(void)) |
370 | etp_init (void (*want_poll)(void), void (*done_poll)(void)) |
308 | { |
371 | { |
309 | static pthread_once_t doinit = PTHREAD_ONCE_INIT; |
372 | static pthread_once_t doinit = PTHREAD_ONCE_INIT; |
310 | |
373 | |
311 | pthread_once (&doinit, etp_once_init); |
374 | pthread_once (&doinit, etp_once_init); |
312 | |
375 | |
313 | memset (etp, 0, sizeof *etp); |
|
|
314 | |
|
|
315 | etp->want_poll_cb = want_poll; |
376 | want_poll_cb = want_poll; |
316 | etp->done_poll_cb = done_poll; |
377 | done_poll_cb = done_poll; |
317 | } |
378 | } |
318 | |
379 | |
319 | static etp_pool etp; |
|
|
320 | |
|
|
321 | /*****************************************************************************/ |
|
|
322 | |
|
|
323 | static void grp_try_feed (eio_req *grp) |
|
|
324 | { |
|
|
325 | while (grp->size < grp->int2 && !EIO_CANCELLED (grp)) |
|
|
326 | { |
|
|
327 | int old_len = grp->size; |
|
|
328 | |
|
|
329 | EIO_FEED (grp); |
|
|
330 | |
|
|
331 | /* stop if no progress has been made */ |
|
|
332 | if (old_len == grp->size) |
|
|
333 | { |
|
|
334 | grp->feed = 0; |
|
|
335 | break; |
|
|
336 | } |
|
|
337 | } |
|
|
338 | } |
|
|
339 | |
|
|
340 | static int eio_finish (eio_req *req); |
|
|
341 | |
|
|
342 | static int grp_dec (eio_req *grp) |
|
|
343 | { |
|
|
344 | --grp->size; |
|
|
345 | |
|
|
346 | /* call feeder, if applicable */ |
|
|
347 | grp_try_feed (grp); |
|
|
348 | |
|
|
349 | /* finish, if done */ |
|
|
350 | if (!grp->size && grp->int1) |
|
|
351 | return eio_finish (grp); |
|
|
352 | else |
|
|
353 | return 0; |
|
|
354 | } |
|
|
355 | |
|
|
356 | void eio_destroy (eio_req *req) |
|
|
357 | { |
|
|
358 | if ((req)->flags & EIO_FLAG_PTR1_FREE) free (req->ptr1); |
|
|
359 | if ((req)->flags & EIO_FLAG_PTR2_FREE) free (req->ptr2); |
|
|
360 | |
|
|
361 | EIO_DESTROY (req); |
|
|
362 | } |
|
|
363 | |
|
|
364 | static int eio_finish (eio_req *req) |
|
|
365 | { |
|
|
366 | int res = EIO_FINISH (req); |
|
|
367 | |
|
|
368 | if (req->grp) |
|
|
369 | { |
|
|
370 | int res2; |
|
|
371 | eio_req *grp = req->grp; |
|
|
372 | |
|
|
373 | /* unlink request */ |
|
|
374 | if (req->grp_next) req->grp_next->grp_prev = req->grp_prev; |
|
|
375 | if (req->grp_prev) req->grp_prev->grp_next = req->grp_next; |
|
|
376 | |
|
|
377 | if (grp->grp_first == req) |
|
|
378 | grp->grp_first = req->grp_next; |
|
|
379 | |
|
|
380 | res2 = grp_dec (grp); |
|
|
381 | |
|
|
382 | if (!res && res2) |
|
|
383 | res = res2; |
|
|
384 | } |
|
|
385 | |
|
|
386 | eio_destroy (req); |
|
|
387 | |
|
|
388 | return res; |
|
|
389 | } |
|
|
390 | |
|
|
391 | void eio_grp_cancel (eio_req *grp) |
|
|
392 | { |
|
|
393 | for (grp = grp->grp_first; grp; grp = grp->grp_next) |
|
|
394 | eio_cancel (grp); |
|
|
395 | } |
|
|
396 | |
|
|
397 | void eio_cancel (eio_req *req) |
|
|
398 | { |
|
|
399 | X_LOCK (etplock); |
|
|
400 | req->flags |= EIO_FLAG_CANCELLED; |
|
|
401 | X_UNLOCK (etplock); |
|
|
402 | |
|
|
403 | eio_grp_cancel (req); |
|
|
404 | } |
|
|
405 | |
|
|
406 | X_THREAD_PROC (eio_proc); |
380 | X_THREAD_PROC (etp_proc); |
407 | |
381 | |
408 | static void start_thread (void) |
382 | static void etp_start_thread (void) |
409 | { |
383 | { |
410 | worker *wrk = calloc (1, sizeof (worker)); |
384 | etp_worker *wrk = calloc (1, sizeof (etp_worker)); |
411 | |
385 | |
412 | /*TODO*/ |
386 | /*TODO*/ |
413 | assert (("unable to allocate worker thread data", wrk)); |
387 | assert (("unable to allocate worker thread data", wrk)); |
414 | |
388 | |
415 | X_LOCK (etplock); |
389 | X_LOCK (wrklock); |
416 | |
390 | |
417 | if (thread_create (&wrk->tid, eio_proc, (void *)wrk)) |
391 | if (thread_create (&wrk->tid, etp_proc, (void *)wrk)) |
418 | { |
392 | { |
419 | wrk->prev = &wrk_first; |
393 | wrk->prev = &wrk_first; |
420 | wrk->next = wrk_first.next; |
394 | wrk->next = wrk_first.next; |
421 | wrk_first.next->prev = wrk; |
395 | wrk_first.next->prev = wrk; |
422 | wrk_first.next = wrk; |
396 | wrk_first.next = wrk; |
423 | ++started; |
397 | ++started; |
424 | } |
398 | } |
425 | else |
399 | else |
426 | free (wrk); |
400 | free (wrk); |
427 | |
401 | |
428 | X_UNLOCK (etplock); |
402 | X_UNLOCK (wrklock); |
429 | } |
403 | } |
430 | |
404 | |
431 | static void maybe_start_thread (void) |
405 | static void etp_maybe_start_thread (void) |
432 | { |
406 | { |
433 | if (eio_nthreads () >= wanted) |
407 | if (etp_nthreads () >= wanted) |
434 | return; |
408 | return; |
435 | |
409 | |
436 | /* todo: maybe use idle here, but might be less exact */ |
410 | /* todo: maybe use idle here, but might be less exact */ |
437 | if (0 <= (int)eio_nthreads () + (int)eio_npending () - (int)eio_nreqs ()) |
411 | if (0 <= (int)etp_nthreads () + (int)etp_npending () - (int)etp_nreqs ()) |
438 | return; |
412 | return; |
439 | |
413 | |
440 | start_thread (); |
414 | etp_start_thread (); |
441 | } |
415 | } |
442 | |
416 | |
443 | void eio_submit (eio_req *req) |
|
|
444 | { |
|
|
445 | req->pri += EIO_PRI_BIAS; |
|
|
446 | |
|
|
447 | if (req->pri < EIO_PRI_MIN + EIO_PRI_BIAS) req->pri = EIO_PRI_MIN + EIO_PRI_BIAS; |
|
|
448 | if (req->pri > EIO_PRI_MAX + EIO_PRI_BIAS) req->pri = EIO_PRI_MAX + EIO_PRI_BIAS; |
|
|
449 | |
|
|
450 | ++nreqs; |
|
|
451 | |
|
|
452 | X_LOCK (reqlock); |
|
|
453 | ++nready; |
|
|
454 | reqq_push (&req_queue, req); |
|
|
455 | X_COND_SIGNAL (reqwait); |
|
|
456 | X_UNLOCK (reqlock); |
|
|
457 | |
|
|
458 | maybe_start_thread (); |
|
|
459 | } |
|
|
460 | |
|
|
461 | static void end_thread (void) |
417 | static void etp_end_thread (void) |
462 | { |
418 | { |
463 | eio_req *req = calloc (1, sizeof (eio_req)); |
419 | eio_req *req = calloc (1, sizeof (eio_req)); |
464 | |
420 | |
465 | req->type = EIO_QUIT; |
421 | req->type = -1; |
466 | req->pri = EIO_PRI_MAX + EIO_PRI_BIAS; |
422 | req->pri = ETP_PRI_MAX - ETP_PRI_MIN; |
467 | |
423 | |
468 | X_LOCK (reqlock); |
424 | X_LOCK (reqlock); |
469 | reqq_push (&req_queue, req); |
425 | reqq_push (&req_queue, req); |
470 | X_COND_SIGNAL (reqwait); |
426 | X_COND_SIGNAL (reqwait); |
471 | X_UNLOCK (reqlock); |
427 | X_UNLOCK (reqlock); |
472 | |
428 | |
473 | X_LOCK (etplock); |
429 | X_LOCK (wrklock); |
474 | --started; |
430 | --started; |
475 | X_UNLOCK (etplock); |
431 | X_UNLOCK (wrklock); |
476 | } |
432 | } |
477 | |
433 | |
478 | void eio_set_max_poll_time (double nseconds) |
|
|
479 | { |
|
|
480 | if (WORDACCESS_UNSAFE) X_LOCK (reqlock); |
|
|
481 | etp.max_poll_time = nseconds; |
|
|
482 | if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); |
|
|
483 | } |
|
|
484 | |
|
|
485 | void eio_set_max_poll_reqs (unsigned int maxreqs) |
|
|
486 | { |
|
|
487 | if (WORDACCESS_UNSAFE) X_LOCK (reqlock); |
|
|
488 | etp.max_poll_reqs = maxreqs; |
|
|
489 | if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); |
|
|
490 | } |
|
|
491 | |
|
|
492 | void eio_set_max_idle (unsigned int nthreads) |
|
|
493 | { |
|
|
494 | if (WORDACCESS_UNSAFE) X_LOCK (reqlock); |
|
|
495 | max_idle = nthreads <= 0 ? 1 : nthreads; |
|
|
496 | if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); |
|
|
497 | } |
|
|
498 | |
|
|
499 | void eio_set_min_parallel (unsigned int nthreads) |
|
|
500 | { |
|
|
501 | if (wanted < nthreads) |
|
|
502 | wanted = nthreads; |
|
|
503 | } |
|
|
504 | |
|
|
505 | void eio_set_max_parallel (unsigned int nthreads) |
|
|
506 | { |
|
|
507 | if (wanted > nthreads) |
|
|
508 | wanted = nthreads; |
|
|
509 | |
|
|
510 | while (started > wanted) |
|
|
511 | end_thread (); |
|
|
512 | } |
|
|
513 | |
|
|
514 | int eio_poll (void) |
434 | static int etp_poll (void) |
515 | { |
435 | { |
516 | int maxreqs = etp.max_poll_reqs; |
436 | unsigned int maxreqs; |
|
|
437 | unsigned int maxtime; |
517 | struct timeval tv_start, tv_now; |
438 | struct timeval tv_start, tv_now; |
518 | eio_req *req; |
|
|
519 | |
439 | |
520 | if (etp.max_poll_time) |
440 | X_LOCK (reslock); |
|
|
441 | maxreqs = max_poll_reqs; |
|
|
442 | maxtime = max_poll_time; |
|
|
443 | X_UNLOCK (reslock); |
|
|
444 | |
|
|
445 | if (maxtime) |
521 | gettimeofday (&tv_start, 0); |
446 | gettimeofday (&tv_start, 0); |
522 | |
447 | |
523 | for (;;) |
448 | for (;;) |
524 | { |
449 | { |
|
|
450 | ETP_REQ *req; |
|
|
451 | |
525 | maybe_start_thread (); |
452 | etp_maybe_start_thread (); |
526 | |
453 | |
527 | X_LOCK (reslock); |
454 | X_LOCK (reslock); |
528 | req = reqq_shift (&res_queue); |
455 | req = reqq_shift (&res_queue); |
529 | |
456 | |
530 | if (req) |
457 | if (req) |
531 | { |
458 | { |
532 | --npending; |
459 | --npending; |
533 | |
460 | |
534 | if (!res_queue.size && etp.done_poll_cb) |
461 | if (!res_queue.size && done_poll_cb) |
535 | etp.done_poll_cb (); |
462 | done_poll_cb (); |
536 | } |
463 | } |
537 | |
464 | |
538 | X_UNLOCK (reslock); |
465 | X_UNLOCK (reslock); |
539 | |
466 | |
540 | if (!req) |
467 | if (!req) |
541 | return 0; |
468 | return 0; |
542 | |
469 | |
|
|
470 | X_LOCK (reqlock); |
543 | --nreqs; |
471 | --nreqs; |
|
|
472 | X_UNLOCK (reqlock); |
544 | |
473 | |
545 | if (req->type == EIO_GROUP && req->size) |
474 | if (req->type == EIO_GROUP && req->size) |
546 | { |
475 | { |
547 | req->int1 = 1; /* mark request as delayed */ |
476 | req->int1 = 1; /* mark request as delayed */ |
548 | continue; |
477 | continue; |
549 | } |
478 | } |
550 | else |
479 | else |
551 | { |
480 | { |
552 | int res = eio_finish (req); |
481 | int res = ETP_FINISH (req); |
553 | if (res) |
482 | if (res) |
554 | return res; |
483 | return res; |
555 | } |
484 | } |
556 | |
485 | |
557 | if (maxreqs && !--maxreqs) |
486 | if (maxreqs && !--maxreqs) |
558 | break; |
487 | break; |
559 | |
488 | |
560 | if (etp.max_poll_time) |
489 | if (maxtime) |
561 | { |
490 | { |
562 | gettimeofday (&tv_now, 0); |
491 | gettimeofday (&tv_now, 0); |
563 | |
492 | |
564 | if (tvdiff (&tv_start, &tv_now) >= etp.max_poll_time) |
493 | if (tvdiff (&tv_start, &tv_now) >= maxtime) |
565 | break; |
494 | break; |
566 | } |
495 | } |
567 | } |
496 | } |
568 | |
497 | |
569 | errno = EAGAIN; |
498 | errno = EAGAIN; |
570 | return -1; |
499 | return -1; |
|
|
500 | } |
|
|
501 | |
|
|
502 | static void etp_cancel (ETP_REQ *req) |
|
|
503 | { |
|
|
504 | X_LOCK (wrklock); |
|
|
505 | req->flags |= EIO_FLAG_CANCELLED; |
|
|
506 | X_UNLOCK (wrklock); |
|
|
507 | |
|
|
508 | eio_grp_cancel (req); |
|
|
509 | } |
|
|
510 | |
|
|
511 | static void etp_submit (ETP_REQ *req) |
|
|
512 | { |
|
|
513 | req->pri -= ETP_PRI_MIN; |
|
|
514 | |
|
|
515 | if (req->pri < ETP_PRI_MIN - ETP_PRI_MIN) req->pri = ETP_PRI_MIN - ETP_PRI_MIN; |
|
|
516 | if (req->pri > ETP_PRI_MAX - ETP_PRI_MIN) req->pri = ETP_PRI_MAX - ETP_PRI_MIN; |
|
|
517 | |
|
|
518 | X_LOCK (reqlock); |
|
|
519 | ++nreqs; |
|
|
520 | ++nready; |
|
|
521 | reqq_push (&req_queue, req); |
|
|
522 | X_COND_SIGNAL (reqwait); |
|
|
523 | X_UNLOCK (reqlock); |
|
|
524 | |
|
|
525 | etp_maybe_start_thread (); |
|
|
526 | } |
|
|
527 | |
|
|
528 | static void etp_set_max_poll_time (double nseconds) |
|
|
529 | { |
|
|
530 | if (WORDACCESS_UNSAFE) X_LOCK (reslock); |
|
|
531 | max_poll_time = nseconds; |
|
|
532 | if (WORDACCESS_UNSAFE) X_UNLOCK (reslock); |
|
|
533 | } |
|
|
534 | |
|
|
535 | static void etp_set_max_poll_reqs (unsigned int maxreqs) |
|
|
536 | { |
|
|
537 | if (WORDACCESS_UNSAFE) X_LOCK (reslock); |
|
|
538 | max_poll_reqs = maxreqs; |
|
|
539 | if (WORDACCESS_UNSAFE) X_UNLOCK (reslock); |
|
|
540 | } |
|
|
541 | |
|
|
542 | static void etp_set_max_idle (unsigned int nthreads) |
|
|
543 | { |
|
|
544 | if (WORDACCESS_UNSAFE) X_LOCK (reqlock); |
|
|
545 | max_idle = nthreads <= 0 ? 1 : nthreads; |
|
|
546 | if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); |
|
|
547 | } |
|
|
548 | |
|
|
549 | static void etp_set_min_parallel (unsigned int nthreads) |
|
|
550 | { |
|
|
551 | if (wanted < nthreads) |
|
|
552 | wanted = nthreads; |
|
|
553 | } |
|
|
554 | |
|
|
555 | static void etp_set_max_parallel (unsigned int nthreads) |
|
|
556 | { |
|
|
557 | if (wanted > nthreads) |
|
|
558 | wanted = nthreads; |
|
|
559 | |
|
|
560 | while (started > wanted) |
|
|
561 | etp_end_thread (); |
|
|
562 | } |
|
|
563 | |
|
|
564 | /*****************************************************************************/ |
|
|
565 | |
|
|
566 | static void grp_try_feed (eio_req *grp) |
|
|
567 | { |
|
|
568 | while (grp->size < grp->int2 && !EIO_CANCELLED (grp)) |
|
|
569 | { |
|
|
570 | int old_len = grp->size; |
|
|
571 | |
|
|
572 | EIO_FEED (grp); |
|
|
573 | |
|
|
574 | /* stop if no progress has been made */ |
|
|
575 | if (old_len == grp->size) |
|
|
576 | { |
|
|
577 | grp->feed = 0; |
|
|
578 | break; |
|
|
579 | } |
|
|
580 | } |
|
|
581 | } |
|
|
582 | |
|
|
583 | static int grp_dec (eio_req *grp) |
|
|
584 | { |
|
|
585 | --grp->size; |
|
|
586 | |
|
|
587 | /* call feeder, if applicable */ |
|
|
588 | grp_try_feed (grp); |
|
|
589 | |
|
|
590 | /* finish, if done */ |
|
|
591 | if (!grp->size && grp->int1) |
|
|
592 | return eio_finish (grp); |
|
|
593 | else |
|
|
594 | return 0; |
|
|
595 | } |
|
|
596 | |
|
|
597 | void eio_destroy (eio_req *req) |
|
|
598 | { |
|
|
599 | if ((req)->flags & EIO_FLAG_PTR1_FREE) free (req->ptr1); |
|
|
600 | if ((req)->flags & EIO_FLAG_PTR2_FREE) free (req->ptr2); |
|
|
601 | |
|
|
602 | EIO_DESTROY (req); |
|
|
603 | } |
|
|
604 | |
|
|
605 | static int eio_finish (eio_req *req) |
|
|
606 | { |
|
|
607 | int res = EIO_FINISH (req); |
|
|
608 | |
|
|
609 | if (req->grp) |
|
|
610 | { |
|
|
611 | int res2; |
|
|
612 | eio_req *grp = req->grp; |
|
|
613 | |
|
|
614 | /* unlink request */ |
|
|
615 | if (req->grp_next) req->grp_next->grp_prev = req->grp_prev; |
|
|
616 | if (req->grp_prev) req->grp_prev->grp_next = req->grp_next; |
|
|
617 | |
|
|
618 | if (grp->grp_first == req) |
|
|
619 | grp->grp_first = req->grp_next; |
|
|
620 | |
|
|
621 | res2 = grp_dec (grp); |
|
|
622 | |
|
|
623 | if (!res && res2) |
|
|
624 | res = res2; |
|
|
625 | } |
|
|
626 | |
|
|
627 | eio_destroy (req); |
|
|
628 | |
|
|
629 | return res; |
|
|
630 | } |
|
|
631 | |
|
|
632 | void eio_grp_cancel (eio_req *grp) |
|
|
633 | { |
|
|
634 | for (grp = grp->grp_first; grp; grp = grp->grp_next) |
|
|
635 | eio_cancel (grp); |
|
|
636 | } |
|
|
637 | |
|
|
638 | void eio_cancel (eio_req *req) |
|
|
639 | { |
|
|
640 | etp_cancel (req); |
|
|
641 | } |
|
|
642 | |
|
|
643 | void eio_submit (eio_req *req) |
|
|
644 | { |
|
|
645 | etp_submit (req); |
|
|
646 | } |
|
|
647 | |
|
|
648 | unsigned int eio_nreqs (void) |
|
|
649 | { |
|
|
650 | return etp_nreqs (); |
|
|
651 | } |
|
|
652 | |
|
|
653 | unsigned int eio_nready (void) |
|
|
654 | { |
|
|
655 | return etp_nready (); |
|
|
656 | } |
|
|
657 | |
|
|
658 | unsigned int eio_npending (void) |
|
|
659 | { |
|
|
660 | return etp_npending (); |
|
|
661 | } |
|
|
662 | |
|
|
663 | unsigned int eio_nthreads (void) |
|
|
664 | { |
|
|
665 | return etp_nthreads (); |
|
|
666 | } |
|
|
667 | |
|
|
668 | void eio_set_max_poll_time (double nseconds) |
|
|
669 | { |
|
|
670 | etp_set_max_poll_time (nseconds); |
|
|
671 | } |
|
|
672 | |
|
|
673 | void eio_set_max_poll_reqs (unsigned int maxreqs) |
|
|
674 | { |
|
|
675 | etp_set_max_poll_reqs (maxreqs); |
|
|
676 | } |
|
|
677 | |
|
|
678 | void eio_set_max_idle (unsigned int nthreads) |
|
|
679 | { |
|
|
680 | etp_set_max_idle (nthreads); |
|
|
681 | } |
|
|
682 | |
|
|
683 | void eio_set_min_parallel (unsigned int nthreads) |
|
|
684 | { |
|
|
685 | etp_set_min_parallel (nthreads); |
|
|
686 | } |
|
|
687 | |
|
|
688 | void eio_set_max_parallel (unsigned int nthreads) |
|
|
689 | { |
|
|
690 | etp_set_max_parallel (nthreads); |
|
|
691 | } |
|
|
692 | |
|
|
693 | int eio_poll (void) |
|
|
694 | { |
|
|
695 | return etp_poll (); |
571 | } |
696 | } |
572 | |
697 | |
573 | /*****************************************************************************/ |
698 | /*****************************************************************************/ |
574 | /* work around various missing functions */ |
699 | /* work around various missing functions */ |
575 | |
700 | |
… | |
… | |
705 | } |
830 | } |
706 | #endif |
831 | #endif |
707 | |
832 | |
708 | /* sendfile always needs emulation */ |
833 | /* sendfile always needs emulation */ |
709 | static ssize_t |
834 | static ssize_t |
710 | eio__sendfile (int ofd, int ifd, off_t offset, size_t count, worker *self) |
835 | eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) |
711 | { |
836 | { |
712 | ssize_t res; |
837 | ssize_t res; |
713 | |
838 | |
714 | if (!count) |
839 | if (!count) |
715 | return 0; |
840 | return 0; |
… | |
… | |
799 | return res; |
924 | return res; |
800 | } |
925 | } |
801 | |
926 | |
802 | /* read a full directory */ |
927 | /* read a full directory */ |
803 | static void |
928 | static void |
804 | eio__scandir (eio_req *req, worker *self) |
929 | eio__scandir (eio_req *req, etp_worker *self) |
805 | { |
930 | { |
806 | DIR *dirp; |
931 | DIR *dirp; |
807 | union |
932 | union |
808 | { |
933 | { |
809 | EIO_STRUCT_DIRENT d; |
934 | EIO_STRUCT_DIRENT d; |
… | |
… | |
813 | char *name, *names; |
938 | char *name, *names; |
814 | int memlen = 4096; |
939 | int memlen = 4096; |
815 | int memofs = 0; |
940 | int memofs = 0; |
816 | int res = 0; |
941 | int res = 0; |
817 | |
942 | |
818 | X_LOCK (etplock); |
943 | X_LOCK (wrklock); |
819 | self->dirp = dirp = opendir (req->ptr1); |
944 | self->dirp = dirp = opendir (req->ptr1); |
820 | self->dbuf = u = malloc (sizeof (*u)); |
945 | self->dbuf = u = malloc (sizeof (*u)); |
821 | req->flags |= EIO_FLAG_PTR2_FREE; |
946 | req->flags |= EIO_FLAG_PTR2_FREE; |
822 | req->ptr2 = names = malloc (memlen); |
947 | req->ptr2 = names = malloc (memlen); |
823 | X_UNLOCK (etplock); |
948 | X_UNLOCK (wrklock); |
824 | |
949 | |
825 | if (dirp && u && names) |
950 | if (dirp && u && names) |
826 | for (;;) |
951 | for (;;) |
827 | { |
952 | { |
828 | errno = 0; |
953 | errno = 0; |
… | |
… | |
840 | res++; |
965 | res++; |
841 | |
966 | |
842 | while (memofs + len > memlen) |
967 | while (memofs + len > memlen) |
843 | { |
968 | { |
844 | memlen *= 2; |
969 | memlen *= 2; |
845 | X_LOCK (etplock); |
970 | X_LOCK (wrklock); |
846 | req->ptr2 = names = realloc (names, memlen); |
971 | req->ptr2 = names = realloc (names, memlen); |
847 | X_UNLOCK (etplock); |
972 | X_UNLOCK (wrklock); |
848 | |
973 | |
849 | if (!names) |
974 | if (!names) |
850 | break; |
975 | break; |
851 | } |
976 | } |
852 | |
977 | |
… | |
… | |
864 | /*****************************************************************************/ |
989 | /*****************************************************************************/ |
865 | |
990 | |
866 | #define ALLOC(len) \ |
991 | #define ALLOC(len) \ |
867 | if (!req->ptr2) \ |
992 | if (!req->ptr2) \ |
868 | { \ |
993 | { \ |
869 | X_LOCK (etplock); \ |
994 | X_LOCK (wrklock); \ |
870 | req->flags |= EIO_FLAG_PTR2_FREE; \ |
995 | req->flags |= EIO_FLAG_PTR2_FREE; \ |
871 | X_UNLOCK (etplock); \ |
996 | X_UNLOCK (wrklock); \ |
872 | req->ptr2 = malloc (len); \ |
997 | req->ptr2 = malloc (len); \ |
873 | if (!req->ptr2) \ |
998 | if (!req->ptr2) \ |
874 | { \ |
999 | { \ |
875 | errno = ENOMEM; \ |
1000 | errno = ENOMEM; \ |
876 | req->result = -1; \ |
1001 | req->result = -1; \ |
877 | break; \ |
1002 | break; \ |
878 | } \ |
1003 | } \ |
879 | } |
1004 | } |
880 | |
1005 | |
881 | X_THREAD_PROC (eio_proc) |
1006 | X_THREAD_PROC (etp_proc) |
882 | { |
1007 | { |
883 | eio_req *req; |
1008 | ETP_REQ *req; |
884 | struct timespec ts; |
1009 | struct timespec ts; |
885 | worker *self = (worker *)thr_arg; |
1010 | etp_worker *self = (etp_worker *)thr_arg; |
886 | |
1011 | |
887 | /* try to distribute timeouts somewhat randomly */ |
1012 | /* try to distribute timeouts somewhat randomly */ |
888 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
1013 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
889 | |
1014 | |
890 | for (;;) |
1015 | for (;;) |
891 | { |
1016 | { |
892 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
|
|
893 | |
|
|
894 | X_LOCK (reqlock); |
1017 | X_LOCK (reqlock); |
895 | |
1018 | |
896 | for (;;) |
1019 | for (;;) |
897 | { |
1020 | { |
898 | self->req = req = reqq_shift (&req_queue); |
1021 | self->req = req = reqq_shift (&req_queue); |
… | |
… | |
900 | if (req) |
1023 | if (req) |
901 | break; |
1024 | break; |
902 | |
1025 | |
903 | ++idle; |
1026 | ++idle; |
904 | |
1027 | |
|
|
1028 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
905 | if (X_COND_TIMEDWAIT (reqwait, reqlock, ts) == ETIMEDOUT) |
1029 | if (X_COND_TIMEDWAIT (reqwait, reqlock, ts) == ETIMEDOUT) |
906 | { |
1030 | { |
907 | if (idle > max_idle) |
1031 | if (idle > max_idle) |
908 | { |
1032 | { |
909 | --idle; |
1033 | --idle; |
910 | X_UNLOCK (reqlock); |
1034 | X_UNLOCK (reqlock); |
911 | X_LOCK (etplock); |
1035 | X_LOCK (wrklock); |
912 | --started; |
1036 | --started; |
913 | X_UNLOCK (etplock); |
1037 | X_UNLOCK (wrklock); |
914 | goto quit; |
1038 | goto quit; |
915 | } |
1039 | } |
916 | |
1040 | |
917 | /* we are allowed to idle, so do so without any timeout */ |
1041 | /* we are allowed to idle, so do so without any timeout */ |
918 | X_COND_WAIT (reqwait, reqlock); |
1042 | X_COND_WAIT (reqwait, reqlock); |
919 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
|
|
920 | } |
1043 | } |
921 | |
1044 | |
922 | --idle; |
1045 | --idle; |
923 | } |
1046 | } |
924 | |
1047 | |
… | |
… | |
1018 | case EIO_GROUP: |
1141 | case EIO_GROUP: |
1019 | case EIO_NOP: |
1142 | case EIO_NOP: |
1020 | req->result = 0; |
1143 | req->result = 0; |
1021 | break; |
1144 | break; |
1022 | |
1145 | |
1023 | case EIO_QUIT: |
1146 | case -1: |
1024 | goto quit; |
1147 | goto quit; |
1025 | |
1148 | |
1026 | default: |
1149 | default: |
1027 | req->result = -1; |
1150 | req->result = -1; |
1028 | break; |
1151 | break; |
… | |
… | |
1032 | |
1155 | |
1033 | X_LOCK (reslock); |
1156 | X_LOCK (reslock); |
1034 | |
1157 | |
1035 | ++npending; |
1158 | ++npending; |
1036 | |
1159 | |
1037 | if (!reqq_push (&res_queue, req) && etp.want_poll_cb) |
1160 | if (!reqq_push (&res_queue, req) && want_poll_cb) |
1038 | etp.want_poll_cb (); |
1161 | want_poll_cb (); |
1039 | |
1162 | |
1040 | self->req = 0; |
1163 | self->req = 0; |
1041 | worker_clear (self); |
1164 | etp_worker_clear (self); |
1042 | |
1165 | |
1043 | X_UNLOCK (reslock); |
1166 | X_UNLOCK (reslock); |
1044 | } |
1167 | } |
1045 | |
1168 | |
1046 | quit: |
1169 | quit: |
1047 | X_LOCK (etplock); |
1170 | X_LOCK (wrklock); |
1048 | worker_free (self); |
1171 | etp_worker_free (self); |
1049 | X_UNLOCK (etplock); |
1172 | X_UNLOCK (wrklock); |
1050 | |
1173 | |
1051 | return 0; |
1174 | return 0; |
1052 | } |
1175 | } |
1053 | |
1176 | |
1054 | /*****************************************************************************/ |
1177 | /*****************************************************************************/ |
1055 | |
1178 | |
1056 | int eio_init (void (*want_poll)(void), void (*done_poll)(void)) |
1179 | int eio_init (void (*want_poll)(void), void (*done_poll)(void)) |
1057 | { |
1180 | { |
1058 | etp_init (&etp, want_poll, done_poll); |
1181 | etp_init (want_poll, done_poll); |
1059 | } |
1182 | } |
1060 | |
1183 | |
1061 | static void eio_api_destroy (eio_req *req) |
1184 | static void eio_api_destroy (eio_req *req) |
1062 | { |
1185 | { |
1063 | free (req); |
1186 | free (req); |
… | |
… | |
1321 | /*****************************************************************************/ |
1444 | /*****************************************************************************/ |
1322 | /* misc garbage */ |
1445 | /* misc garbage */ |
1323 | |
1446 | |
1324 | ssize_t eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count) |
1447 | ssize_t eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count) |
1325 | { |
1448 | { |
1326 | worker wrk; |
1449 | etp_worker wrk; |
1327 | |
1450 | |
1328 | wrk.dbuf = 0; |
1451 | wrk.dbuf = 0; |
1329 | |
1452 | |
1330 | eio__sendfile (ofd, ifd, offset, count, &wrk); |
1453 | eio__sendfile (ofd, ifd, offset, count, &wrk); |
1331 | |
1454 | |