ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libeio/eio.c
(Generate patch)

Comparing cvsroot/libeio/eio.c (file contents):
Revision 1.70 by root, Fri Jun 10 06:55:10 2011 UTC vs.
Revision 1.83 by root, Thu Jul 7 22:36:18 2011 UTC

40#ifndef _WIN32 40#ifndef _WIN32
41# include "config.h" 41# include "config.h"
42#endif 42#endif
43 43
44#include "eio.h" 44#include "eio.h"
45#include "ecb.h"
45 46
46#ifdef EIO_STACKSIZE 47#ifdef EIO_STACKSIZE
47# define XTHREAD_STACKSIZE EIO_STACKSIZE 48# define XTHREAD_STACKSIZE EIO_STACKSIZE
48#endif 49#endif
49#include "xthread.h" 50#include "xthread.h"
59#include <limits.h> 60#include <limits.h>
60#include <fcntl.h> 61#include <fcntl.h>
61#include <assert.h> 62#include <assert.h>
62 63
63/* intptr_t comes from unistd.h, says POSIX/UNIX/tradition */ 64/* intptr_t comes from unistd.h, says POSIX/UNIX/tradition */
64/* intptr_t only comes form stdint.h, says idiot openbsd coder */ 65/* intptr_t only comes from stdint.h, says idiot openbsd coder */
65#if HAVE_STDINT_H 66#if HAVE_STDINT_H
66# include <stdint.h> 67# include <stdint.h>
67#endif 68#endif
69
70#ifndef ECANCELED
71# define ECANCELED EDOM
72#endif
73
74static void eio_destroy (eio_req *req);
68 75
69#ifndef EIO_FINISH 76#ifndef EIO_FINISH
70# define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0 77# define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0
71#endif 78#endif
72 79
165 if (!eio_buf) \ 172 if (!eio_buf) \
166 return -1; 173 return -1;
167 174
168#define EIO_TICKS ((1000000 + 1023) >> 10) 175#define EIO_TICKS ((1000000 + 1023) >> 10)
169 176
170/*****************************************************************************/
171
172#if __GNUC__ >= 3
173# define expect(expr,value) __builtin_expect ((expr),(value))
174#else
175# define expect(expr,value) (expr)
176#endif
177
178#define expect_false(expr) expect ((expr) != 0, 0)
179#define expect_true(expr) expect ((expr) != 0, 1)
180
181/*****************************************************************************/
182
183#define ETP_PRI_MIN EIO_PRI_MIN 177#define ETP_PRI_MIN EIO_PRI_MIN
184#define ETP_PRI_MAX EIO_PRI_MAX 178#define ETP_PRI_MAX EIO_PRI_MAX
185 179
186struct etp_worker; 180struct etp_worker;
187 181
212/*****************************************************************************/ 206/*****************************************************************************/
213 207
214#define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1) 208#define ETP_NUM_PRI (ETP_PRI_MAX - ETP_PRI_MIN + 1)
215 209
216/* calculate time difference in ~1/EIO_TICKS of a second */ 210/* calculate time difference in ~1/EIO_TICKS of a second */
211ecb_inline int
217static int tvdiff (struct timeval *tv1, struct timeval *tv2) 212tvdiff (struct timeval *tv1, struct timeval *tv2)
218{ 213{
219 return (tv2->tv_sec - tv1->tv_sec ) * EIO_TICKS 214 return (tv2->tv_sec - tv1->tv_sec ) * EIO_TICKS
220 + ((tv2->tv_usec - tv1->tv_usec) >> 10); 215 + ((tv2->tv_usec - tv1->tv_usec) >> 10);
221} 216}
222 217
266#define ETP_WORKER_LOCK(wrk) X_LOCK (wrklock) 261#define ETP_WORKER_LOCK(wrk) X_LOCK (wrklock)
267#define ETP_WORKER_UNLOCK(wrk) X_UNLOCK (wrklock) 262#define ETP_WORKER_UNLOCK(wrk) X_UNLOCK (wrklock)
268 263
269/* worker threads management */ 264/* worker threads management */
270 265
266static void ecb_cold
271static void etp_worker_clear (etp_worker *wrk) 267etp_worker_clear (etp_worker *wrk)
272{ 268{
273 ETP_WORKER_CLEAR (wrk); 269 ETP_WORKER_CLEAR (wrk);
274} 270}
275 271
272static void ecb_cold
276static void etp_worker_free (etp_worker *wrk) 273etp_worker_free (etp_worker *wrk)
277{ 274{
278 wrk->next->prev = wrk->prev; 275 wrk->next->prev = wrk->prev;
279 wrk->prev->next = wrk->next; 276 wrk->prev->next = wrk->next;
280 277
281 free (wrk); 278 free (wrk);
282} 279}
283 280
284static unsigned int etp_nreqs (void) 281static unsigned int
282etp_nreqs (void)
285{ 283{
286 int retval; 284 int retval;
287 if (WORDACCESS_UNSAFE) X_LOCK (reqlock); 285 if (WORDACCESS_UNSAFE) X_LOCK (reqlock);
288 retval = nreqs; 286 retval = nreqs;
289 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); 287 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock);
290 return retval; 288 return retval;
291} 289}
292 290
293static unsigned int etp_nready (void) 291static unsigned int
292etp_nready (void)
294{ 293{
295 unsigned int retval; 294 unsigned int retval;
296 295
297 if (WORDACCESS_UNSAFE) X_LOCK (reqlock); 296 if (WORDACCESS_UNSAFE) X_LOCK (reqlock);
298 retval = nready; 297 retval = nready;
299 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); 298 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock);
300 299
301 return retval; 300 return retval;
302} 301}
303 302
304static unsigned int etp_npending (void) 303static unsigned int
304etp_npending (void)
305{ 305{
306 unsigned int retval; 306 unsigned int retval;
307 307
308 if (WORDACCESS_UNSAFE) X_LOCK (reqlock); 308 if (WORDACCESS_UNSAFE) X_LOCK (reqlock);
309 retval = npending; 309 retval = npending;
310 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); 310 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock);
311 311
312 return retval; 312 return retval;
313} 313}
314 314
315static unsigned int etp_nthreads (void) 315static unsigned int
316etp_nthreads (void)
316{ 317{
317 unsigned int retval; 318 unsigned int retval;
318 319
319 if (WORDACCESS_UNSAFE) X_LOCK (reqlock); 320 if (WORDACCESS_UNSAFE) X_LOCK (reqlock);
320 retval = started; 321 retval = started;
334} etp_reqq; 335} etp_reqq;
335 336
336static etp_reqq req_queue; 337static etp_reqq req_queue;
337static etp_reqq res_queue; 338static etp_reqq res_queue;
338 339
340static int ecb_noinline
339static int reqq_push (etp_reqq *q, ETP_REQ *req) 341reqq_push (etp_reqq *q, ETP_REQ *req)
340{ 342{
341 int pri = req->pri; 343 int pri = req->pri;
342 req->next = 0; 344 req->next = 0;
343 345
344 if (q->qe[pri]) 346 if (q->qe[pri])
350 q->qe[pri] = q->qs[pri] = req; 352 q->qe[pri] = q->qs[pri] = req;
351 353
352 return q->size++; 354 return q->size++;
353} 355}
354 356
357static ETP_REQ * ecb_noinline
355static ETP_REQ *reqq_shift (etp_reqq *q) 358reqq_shift (etp_reqq *q)
356{ 359{
357 int pri; 360 int pri;
358 361
359 if (!q->size) 362 if (!q->size)
360 return 0; 363 return 0;
375 } 378 }
376 379
377 abort (); 380 abort ();
378} 381}
379 382
383static void ecb_cold
380static void etp_thread_init (void) 384etp_thread_init (void)
381{ 385{
382 X_MUTEX_CREATE (wrklock); 386 X_MUTEX_CREATE (wrklock);
383 X_MUTEX_CREATE (reslock); 387 X_MUTEX_CREATE (reslock);
384 X_MUTEX_CREATE (reqlock); 388 X_MUTEX_CREATE (reqlock);
385 X_COND_CREATE (reqwait); 389 X_COND_CREATE (reqwait);
386} 390}
387 391
392static void ecb_cold
388static void etp_atfork_prepare (void) 393etp_atfork_prepare (void)
389{ 394{
390 X_LOCK (wrklock); 395 X_LOCK (wrklock);
391 X_LOCK (reqlock); 396 X_LOCK (reqlock);
392 X_LOCK (reslock); 397 X_LOCK (reslock);
393#if !HAVE_PREADWRITE 398#if !HAVE_PREADWRITE
394 X_LOCK (preadwritelock); 399 X_LOCK (preadwritelock);
395#endif 400#endif
396} 401}
397 402
403static void ecb_cold
398static void etp_atfork_parent (void) 404etp_atfork_parent (void)
399{ 405{
400#if !HAVE_PREADWRITE 406#if !HAVE_PREADWRITE
401 X_UNLOCK (preadwritelock); 407 X_UNLOCK (preadwritelock);
402#endif 408#endif
403 X_UNLOCK (reslock); 409 X_UNLOCK (reslock);
404 X_UNLOCK (reqlock); 410 X_UNLOCK (reqlock);
405 X_UNLOCK (wrklock); 411 X_UNLOCK (wrklock);
406} 412}
407 413
414static void ecb_cold
408static void etp_atfork_child (void) 415etp_atfork_child (void)
409{ 416{
410 ETP_REQ *prv; 417 ETP_REQ *prv;
411 418
412 while ((prv = reqq_shift (&req_queue))) 419 while ((prv = reqq_shift (&req_queue)))
413 ETP_DESTROY (prv); 420 ETP_DESTROY (prv);
433 npending = 0; 440 npending = 0;
434 441
435 etp_thread_init (); 442 etp_thread_init ();
436} 443}
437 444
438static void 445static void ecb_cold
439etp_once_init (void) 446etp_once_init (void)
440{ 447{
441 etp_thread_init (); 448 etp_thread_init ();
442 X_THREAD_ATFORK (etp_atfork_prepare, etp_atfork_parent, etp_atfork_child); 449 X_THREAD_ATFORK (etp_atfork_prepare, etp_atfork_parent, etp_atfork_child);
443} 450}
444 451
445static int 452static int ecb_cold
446etp_init (void (*want_poll)(void), void (*done_poll)(void)) 453etp_init (void (*want_poll)(void), void (*done_poll)(void))
447{ 454{
448 static pthread_once_t doinit = PTHREAD_ONCE_INIT; 455 static pthread_once_t doinit = PTHREAD_ONCE_INIT;
449 456
450 pthread_once (&doinit, etp_once_init); 457 pthread_once (&doinit, etp_once_init);
455 return 0; 462 return 0;
456} 463}
457 464
458X_THREAD_PROC (etp_proc); 465X_THREAD_PROC (etp_proc);
459 466
467static void ecb_cold
460static void etp_start_thread (void) 468etp_start_thread (void)
461{ 469{
462 etp_worker *wrk = calloc (1, sizeof (etp_worker)); 470 etp_worker *wrk = calloc (1, sizeof (etp_worker));
463 471
464 /*TODO*/ 472 /*TODO*/
465 assert (("unable to allocate worker thread data", wrk)); 473 assert (("unable to allocate worker thread data", wrk));
478 free (wrk); 486 free (wrk);
479 487
480 X_UNLOCK (wrklock); 488 X_UNLOCK (wrklock);
481} 489}
482 490
491static void
483static void etp_maybe_start_thread (void) 492etp_maybe_start_thread (void)
484{ 493{
485 if (expect_true (etp_nthreads () >= wanted)) 494 if (ecb_expect_true (etp_nthreads () >= wanted))
486 return; 495 return;
487 496
488 /* todo: maybe use idle here, but might be less exact */ 497 /* todo: maybe use idle here, but might be less exact */
489 if (expect_true (0 <= (int)etp_nthreads () + (int)etp_npending () - (int)etp_nreqs ())) 498 if (ecb_expect_true (0 <= (int)etp_nthreads () + (int)etp_npending () - (int)etp_nreqs ()))
490 return; 499 return;
491 500
492 etp_start_thread (); 501 etp_start_thread ();
493} 502}
494 503
504static void ecb_cold
495static void etp_end_thread (void) 505etp_end_thread (void)
496{ 506{
497 eio_req *req = calloc (1, sizeof (eio_req)); 507 eio_req *req = calloc (1, sizeof (eio_req));
498 508
499 req->type = -1; 509 req->type = -1;
500 req->pri = ETP_PRI_MAX - ETP_PRI_MIN; 510 req->pri = ETP_PRI_MAX - ETP_PRI_MIN;
507 X_LOCK (wrklock); 517 X_LOCK (wrklock);
508 --started; 518 --started;
509 X_UNLOCK (wrklock); 519 X_UNLOCK (wrklock);
510} 520}
511 521
512static int etp_poll (void) 522static int
523etp_poll (void)
513{ 524{
514 unsigned int maxreqs; 525 unsigned int maxreqs;
515 unsigned int maxtime; 526 unsigned int maxtime;
516 struct timeval tv_start, tv_now; 527 struct timeval tv_start, tv_now;
517 528
547 558
548 X_LOCK (reqlock); 559 X_LOCK (reqlock);
549 --nreqs; 560 --nreqs;
550 X_UNLOCK (reqlock); 561 X_UNLOCK (reqlock);
551 562
552 if (expect_false (req->type == EIO_GROUP && req->size)) 563 if (ecb_expect_false (req->type == EIO_GROUP && req->size))
553 { 564 {
554 req->int1 = 1; /* mark request as delayed */ 565 req->int1 = 1; /* mark request as delayed */
555 continue; 566 continue;
556 } 567 }
557 else 568 else
558 { 569 {
559 int res = ETP_FINISH (req); 570 int res = ETP_FINISH (req);
560 if (expect_false (res)) 571 if (ecb_expect_false (res))
561 return res; 572 return res;
562 } 573 }
563 574
564 if (expect_false (maxreqs && !--maxreqs)) 575 if (ecb_expect_false (maxreqs && !--maxreqs))
565 break; 576 break;
566 577
567 if (maxtime) 578 if (maxtime)
568 { 579 {
569 gettimeofday (&tv_now, 0); 580 gettimeofday (&tv_now, 0);
575 586
576 errno = EAGAIN; 587 errno = EAGAIN;
577 return -1; 588 return -1;
578} 589}
579 590
591static void
580static void etp_cancel (ETP_REQ *req) 592etp_cancel (ETP_REQ *req)
581{ 593{
582 X_LOCK (wrklock); 594 req->cancelled = 1;
583 req->flags |= EIO_FLAG_CANCELLED;
584 X_UNLOCK (wrklock);
585 595
586 eio_grp_cancel (req); 596 eio_grp_cancel (req);
587} 597}
588 598
599static void
589static void etp_submit (ETP_REQ *req) 600etp_submit (ETP_REQ *req)
590{ 601{
591 req->pri -= ETP_PRI_MIN; 602 req->pri -= ETP_PRI_MIN;
592 603
593 if (expect_false (req->pri < ETP_PRI_MIN - ETP_PRI_MIN)) req->pri = ETP_PRI_MIN - ETP_PRI_MIN; 604 if (ecb_expect_false (req->pri < ETP_PRI_MIN - ETP_PRI_MIN)) req->pri = ETP_PRI_MIN - ETP_PRI_MIN;
594 if (expect_false (req->pri > ETP_PRI_MAX - ETP_PRI_MIN)) req->pri = ETP_PRI_MAX - ETP_PRI_MIN; 605 if (ecb_expect_false (req->pri > ETP_PRI_MAX - ETP_PRI_MIN)) req->pri = ETP_PRI_MAX - ETP_PRI_MIN;
595 606
596 if (expect_false (req->type == EIO_GROUP)) 607 if (ecb_expect_false (req->type == EIO_GROUP))
597 { 608 {
598 /* I hope this is worth it :/ */ 609 /* I hope this is worth it :/ */
599 X_LOCK (reqlock); 610 X_LOCK (reqlock);
600 ++nreqs; 611 ++nreqs;
601 X_UNLOCK (reqlock); 612 X_UNLOCK (reqlock);
620 631
621 etp_maybe_start_thread (); 632 etp_maybe_start_thread ();
622 } 633 }
623} 634}
624 635
636static void ecb_cold
625static void etp_set_max_poll_time (double nseconds) 637etp_set_max_poll_time (double nseconds)
626{ 638{
627 if (WORDACCESS_UNSAFE) X_LOCK (reslock); 639 if (WORDACCESS_UNSAFE) X_LOCK (reslock);
628 max_poll_time = nseconds * EIO_TICKS; 640 max_poll_time = nseconds * EIO_TICKS;
629 if (WORDACCESS_UNSAFE) X_UNLOCK (reslock); 641 if (WORDACCESS_UNSAFE) X_UNLOCK (reslock);
630} 642}
631 643
644static void ecb_cold
632static void etp_set_max_poll_reqs (unsigned int maxreqs) 645etp_set_max_poll_reqs (unsigned int maxreqs)
633{ 646{
634 if (WORDACCESS_UNSAFE) X_LOCK (reslock); 647 if (WORDACCESS_UNSAFE) X_LOCK (reslock);
635 max_poll_reqs = maxreqs; 648 max_poll_reqs = maxreqs;
636 if (WORDACCESS_UNSAFE) X_UNLOCK (reslock); 649 if (WORDACCESS_UNSAFE) X_UNLOCK (reslock);
637} 650}
638 651
652static void ecb_cold
639static void etp_set_max_idle (unsigned int nthreads) 653etp_set_max_idle (unsigned int nthreads)
640{ 654{
641 if (WORDACCESS_UNSAFE) X_LOCK (reqlock); 655 if (WORDACCESS_UNSAFE) X_LOCK (reqlock);
642 max_idle = nthreads; 656 max_idle = nthreads;
643 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); 657 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock);
644} 658}
645 659
660static void ecb_cold
646static void etp_set_idle_timeout (unsigned int seconds) 661etp_set_idle_timeout (unsigned int seconds)
647{ 662{
648 if (WORDACCESS_UNSAFE) X_LOCK (reqlock); 663 if (WORDACCESS_UNSAFE) X_LOCK (reqlock);
649 idle_timeout = seconds; 664 idle_timeout = seconds;
650 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); 665 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock);
651} 666}
652 667
668static void ecb_cold
653static void etp_set_min_parallel (unsigned int nthreads) 669etp_set_min_parallel (unsigned int nthreads)
654{ 670{
655 if (wanted < nthreads) 671 if (wanted < nthreads)
656 wanted = nthreads; 672 wanted = nthreads;
657} 673}
658 674
675static void ecb_cold
659static void etp_set_max_parallel (unsigned int nthreads) 676etp_set_max_parallel (unsigned int nthreads)
660{ 677{
661 if (wanted > nthreads) 678 if (wanted > nthreads)
662 wanted = nthreads; 679 wanted = nthreads;
663 680
664 while (started > wanted) 681 while (started > wanted)
665 etp_end_thread (); 682 etp_end_thread ();
666} 683}
667 684
668/*****************************************************************************/ 685/*****************************************************************************/
669 686
687static void
670static void grp_try_feed (eio_req *grp) 688grp_try_feed (eio_req *grp)
671{ 689{
672 while (grp->size < grp->int2 && !EIO_CANCELLED (grp)) 690 while (grp->size < grp->int2 && !EIO_CANCELLED (grp))
673 { 691 {
674 grp->flags &= ~EIO_FLAG_GROUPADD; 692 grp->flags &= ~EIO_FLAG_GROUPADD;
675 693
682 break; 700 break;
683 } 701 }
684 } 702 }
685} 703}
686 704
705static int
687static int grp_dec (eio_req *grp) 706grp_dec (eio_req *grp)
688{ 707{
689 --grp->size; 708 --grp->size;
690 709
691 /* call feeder, if applicable */ 710 /* call feeder, if applicable */
692 grp_try_feed (grp); 711 grp_try_feed (grp);
696 return eio_finish (grp); 715 return eio_finish (grp);
697 else 716 else
698 return 0; 717 return 0;
699} 718}
700 719
720static void
701void eio_destroy (eio_req *req) 721eio_destroy (eio_req *req)
702{ 722{
703 if ((req)->flags & EIO_FLAG_PTR1_FREE) free (req->ptr1); 723 if ((req)->flags & EIO_FLAG_PTR1_FREE) free (req->ptr1);
704 if ((req)->flags & EIO_FLAG_PTR2_FREE) free (req->ptr2); 724 if ((req)->flags & EIO_FLAG_PTR2_FREE) free (req->ptr2);
705 725
706 EIO_DESTROY (req); 726 EIO_DESTROY (req);
707} 727}
708 728
729static int
709static int eio_finish (eio_req *req) 730eio_finish (eio_req *req)
710{ 731{
711 int res = EIO_FINISH (req); 732 int res = EIO_FINISH (req);
712 733
713 if (req->grp) 734 if (req->grp)
714 { 735 {
722 if (grp->grp_first == req) 743 if (grp->grp_first == req)
723 grp->grp_first = req->grp_next; 744 grp->grp_first = req->grp_next;
724 745
725 res2 = grp_dec (grp); 746 res2 = grp_dec (grp);
726 747
727 if (!res && res2) 748 if (!res)
728 res = res2; 749 res = res2;
729 } 750 }
730 751
731 eio_destroy (req); 752 eio_destroy (req);
732 753
733 return res; 754 return res;
734} 755}
735 756
757void
736void eio_grp_cancel (eio_req *grp) 758eio_grp_cancel (eio_req *grp)
737{ 759{
738 for (grp = grp->grp_first; grp; grp = grp->grp_next) 760 for (grp = grp->grp_first; grp; grp = grp->grp_next)
739 eio_cancel (grp); 761 eio_cancel (grp);
740} 762}
741 763
764void
742void eio_cancel (eio_req *req) 765eio_cancel (eio_req *req)
743{ 766{
744 etp_cancel (req); 767 etp_cancel (req);
745} 768}
746 769
770void
747void eio_submit (eio_req *req) 771eio_submit (eio_req *req)
748{ 772{
749 etp_submit (req); 773 etp_submit (req);
750} 774}
751 775
752unsigned int eio_nreqs (void) 776unsigned int
777eio_nreqs (void)
753{ 778{
754 return etp_nreqs (); 779 return etp_nreqs ();
755} 780}
756 781
757unsigned int eio_nready (void) 782unsigned int
783eio_nready (void)
758{ 784{
759 return etp_nready (); 785 return etp_nready ();
760} 786}
761 787
762unsigned int eio_npending (void) 788unsigned int
789eio_npending (void)
763{ 790{
764 return etp_npending (); 791 return etp_npending ();
765} 792}
766 793
767unsigned int eio_nthreads (void) 794unsigned int ecb_cold
795eio_nthreads (void)
768{ 796{
769 return etp_nthreads (); 797 return etp_nthreads ();
770} 798}
771 799
800void ecb_cold
772void eio_set_max_poll_time (double nseconds) 801eio_set_max_poll_time (double nseconds)
773{ 802{
774 etp_set_max_poll_time (nseconds); 803 etp_set_max_poll_time (nseconds);
775} 804}
776 805
806void ecb_cold
777void eio_set_max_poll_reqs (unsigned int maxreqs) 807eio_set_max_poll_reqs (unsigned int maxreqs)
778{ 808{
779 etp_set_max_poll_reqs (maxreqs); 809 etp_set_max_poll_reqs (maxreqs);
780} 810}
781 811
812void ecb_cold
782void eio_set_max_idle (unsigned int nthreads) 813eio_set_max_idle (unsigned int nthreads)
783{ 814{
784 etp_set_max_idle (nthreads); 815 etp_set_max_idle (nthreads);
785} 816}
786 817
818void ecb_cold
787void eio_set_idle_timeout (unsigned int seconds) 819eio_set_idle_timeout (unsigned int seconds)
788{ 820{
789 etp_set_idle_timeout (seconds); 821 etp_set_idle_timeout (seconds);
790} 822}
791 823
824void ecb_cold
792void eio_set_min_parallel (unsigned int nthreads) 825eio_set_min_parallel (unsigned int nthreads)
793{ 826{
794 etp_set_min_parallel (nthreads); 827 etp_set_min_parallel (nthreads);
795} 828}
796 829
830void ecb_cold
797void eio_set_max_parallel (unsigned int nthreads) 831eio_set_max_parallel (unsigned int nthreads)
798{ 832{
799 etp_set_max_parallel (nthreads); 833 etp_set_max_parallel (nthreads);
800} 834}
801 835
802int eio_poll (void) 836int eio_poll (void)
872#ifndef HAVE_FUTIMES 906#ifndef HAVE_FUTIMES
873 907
874# undef futimes 908# undef futimes
875# define futimes(fd,times) eio__futimes (fd, times) 909# define futimes(fd,times) eio__futimes (fd, times)
876 910
911static int
877static int eio__futimes (int fd, const struct timeval tv[2]) 912eio__futimes (int fd, const struct timeval tv[2])
878{ 913{
879 errno = ENOSYS; 914 errno = ENOSYS;
880 return -1; 915 return -1;
881} 916}
882 917
886# undef fdatasync 921# undef fdatasync
887# define fdatasync(fd) fsync (fd) 922# define fdatasync(fd) fsync (fd)
888#endif 923#endif
889 924
890/* sync_file_range always needs emulation */ 925/* sync_file_range always needs emulation */
891int 926static int
892eio__sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags) 927eio__sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags)
893{ 928{
894#if HAVE_SYNC_FILE_RANGE 929#if HAVE_SYNC_FILE_RANGE
895 int res; 930 int res;
896 931
913 /* even though we could play tricks with the flags, it's better to always 948 /* even though we could play tricks with the flags, it's better to always
914 * call fdatasync, as that matches the expectation of its users best */ 949 * call fdatasync, as that matches the expectation of its users best */
915 return fdatasync (fd); 950 return fdatasync (fd);
916} 951}
917 952
953static int
954eio__fallocate (int fd, int mode, off_t offset, size_t nbytes)
955{
956#if HAVE_FALLOCATE
957 return fallocate (fd, offset, nbytes, flags);
958#else
959 errno = ENOSYS;
960 return -1;
961#endif
962}
963
918#if !HAVE_READAHEAD 964#if !HAVE_READAHEAD
919# undef readahead 965# undef readahead
920# define readahead(fd,offset,count) eio__readahead (fd, offset, count, self) 966# define readahead(fd,offset,count) eio__readahead (fd, offset, count, self)
921 967
922static ssize_t 968static ssize_t
950 if (!count) 996 if (!count)
951 return 0; 997 return 0;
952 998
953 for (;;) 999 for (;;)
954 { 1000 {
1001#ifdef __APPLE__
1002# undef HAVE_SENDFILE /* broken, as everything on os x */
1003#endif
955#if HAVE_SENDFILE 1004#if HAVE_SENDFILE
956# if __linux 1005# if __linux
957 off_t soffset = offset; 1006 off_t soffset = offset;
958 res = sendfile (ofd, ifd, &soffset, count); 1007 res = sendfile (ofd, ifd, &soffset, count);
959 1008
1084 count -= cnt; 1133 count -= cnt;
1085 } 1134 }
1086 } 1135 }
1087 1136
1088 return res; 1137 return res;
1138}
1139
1140#ifdef PAGESIZE
1141# define eio_pagesize() PAGESIZE
1142#else
1143static intptr_t
1144eio_pagesize (void)
1145{
1146 static intptr_t page;
1147
1148 if (!page)
1149 page = sysconf (_SC_PAGESIZE);
1150
1151 return page;
1152}
1153#endif
1154
1155static void
1156eio_page_align (void **addr, size_t *length)
1157{
1158 intptr_t mask = eio_pagesize () - 1;
1159
1160 /* round down addr */
1161 intptr_t adj = mask & (intptr_t)*addr;
1162
1163 *addr = (void *)((intptr_t)*addr - adj);
1164 *length += adj;
1165
1166 /* round up length */
1167 *length = (*length + mask) & ~mask;
1168}
1169
1170#if !_POSIX_MEMLOCK
1171# define eio__mlockall(a) ((errno = ENOSYS), -1)
1172#else
1173
1174static int
1175eio__mlockall (int flags)
1176{
1177 #if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7
1178 extern int mallopt (int, int);
1179 mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */
1180 #endif
1181
1182 if (EIO_MCL_CURRENT != MCL_CURRENT
1183 || EIO_MCL_FUTURE != MCL_FUTURE)
1184 {
1185 flags = 0
1186 | (flags & EIO_MCL_CURRENT ? MCL_CURRENT : 0)
1187 | (flags & EIO_MCL_FUTURE ? MCL_FUTURE : 0);
1188 }
1189
1190 return mlockall (flags);
1191}
1192#endif
1193
1194#if !_POSIX_MEMLOCK_RANGE
1195# define eio__mlock(a,b) ((errno = ENOSYS), -1)
1196#else
1197
1198static int
1199eio__mlock (void *addr, size_t length)
1200{
1201 eio_page_align (&addr, &length);
1202
1203 return mlock (addr, length);
1204}
1205
1206#endif
1207
1208#if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO)
1209# define eio__msync(a,b,c) ((errno = ENOSYS), -1)
1210#else
1211
1212static int
1213eio__msync (void *mem, size_t len, int flags)
1214{
1215 eio_page_align (&mem, &len);
1216
1217 if (EIO_MS_ASYNC != MS_SYNC
1218 || EIO_MS_INVALIDATE != MS_INVALIDATE
1219 || EIO_MS_SYNC != MS_SYNC)
1220 {
1221 flags = 0
1222 | (flags & EIO_MS_ASYNC ? MS_ASYNC : 0)
1223 | (flags & EIO_MS_INVALIDATE ? MS_INVALIDATE : 0)
1224 | (flags & EIO_MS_SYNC ? MS_SYNC : 0);
1225 }
1226
1227 return msync (mem, len, flags);
1228}
1229
1230#endif
1231
1232static int
1233eio__mtouch (eio_req *req)
1234{
1235 void *mem = req->ptr2;
1236 size_t len = req->size;
1237 int flags = req->int1;
1238
1239 eio_page_align (&mem, &len);
1240
1241 {
1242 intptr_t addr = (intptr_t)mem;
1243 intptr_t end = addr + len;
1244 intptr_t page = eio_pagesize ();
1245
1246 if (addr < end)
1247 if (flags & EIO_MT_MODIFY) /* modify */
1248 do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len && !EIO_CANCELLED (req));
1249 else
1250 do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len && !EIO_CANCELLED (req));
1251 }
1252
1253 return 0;
1254}
1255
1256/*****************************************************************************/
1257/* requests implemented outside eio_execute, because they are so large */
1258
1259static void
1260eio__realpath (eio_req *req, etp_worker *self)
1261{
1262 char *rel = req->ptr1;
1263 char *res;
1264 char *tmp1, *tmp2;
1265#if SYMLOOP_MAX > 32
1266 int symlinks = SYMLOOP_MAX;
1267#else
1268 int symlinks = 32;
1269#endif
1270
1271 req->result = -1;
1272
1273 errno = EINVAL;
1274 if (!rel)
1275 return;
1276
1277 errno = ENOENT;
1278 if (!*rel)
1279 return;
1280
1281 if (!req->ptr2)
1282 {
1283 X_LOCK (wrklock);
1284 req->flags |= EIO_FLAG_PTR2_FREE;
1285 X_UNLOCK (wrklock);
1286 req->ptr2 = malloc (PATH_MAX * 3);
1287
1288 errno = ENOMEM;
1289 if (!req->ptr2)
1290 return;
1291 }
1292
1293 res = req->ptr2;
1294 tmp1 = res + PATH_MAX;
1295 tmp2 = tmp1 + PATH_MAX;
1296
1297#if 0 /* disabled, the musl way to do things is just too racy */
1298#if __linux && defined(O_NONBLOCK) && defined(O_NOATIME)
1299 /* on linux we may be able to ask the kernel */
1300 {
1301 int fd = open (rel, O_RDONLY | O_NONBLOCK | O_NOCTTY | O_NOATIME);
1302
1303 if (fd >= 0)
1304 {
1305 sprintf (tmp1, "/proc/self/fd/%d", fd);
1306 req->result = readlink (tmp1, res, PATH_MAX);
1307 close (fd);
1308
1309 /* here we should probably stat the open file and the disk file, to make sure they still match */
1310
1311 if (req->result > 0)
1312 goto done;
1313 }
1314 else if (errno == ELOOP || errno == ENAMETOOLONG || errno == ENOENT || errno == ENOTDIR || errno == EIO)
1315 return;
1316 }
1317#endif
1318#endif
1319
1320 if (*rel != '/')
1321 {
1322 if (!getcwd (res, PATH_MAX))
1323 return;
1324
1325 if (res [1]) /* only use if not / */
1326 res += strlen (res);
1327 }
1328
1329 while (*rel)
1330 {
1331 ssize_t len, linklen;
1332 char *beg = rel;
1333
1334 while (*rel && *rel != '/')
1335 ++rel;
1336
1337 len = rel - beg;
1338
1339 if (!len) /* skip slashes */
1340 {
1341 ++rel;
1342 continue;
1343 }
1344
1345 if (beg [0] == '.')
1346 {
1347 if (len == 1)
1348 continue; /* . - nop */
1349
1350 if (beg [1] == '.' && len == 2)
1351 {
1352 /* .. - back up one component, if possible */
1353
1354 while (res != req->ptr2)
1355 if (*--res == '/')
1356 break;
1357
1358 continue;
1359 }
1360 }
1361
1362 errno = ENAMETOOLONG;
1363 if (res + 1 + len + 1 >= tmp1)
1364 return;
1365
1366 /* copy one component */
1367 *res = '/';
1368 memcpy (res + 1, beg, len);
1369
1370 /* zero-terminate, for readlink */
1371 res [len + 1] = 0;
1372
1373 /* now check if it's a symlink */
1374 linklen = readlink (req->ptr2, tmp1, PATH_MAX);
1375
1376 if (linklen < 0)
1377 {
1378 if (errno != EINVAL)
1379 return;
1380
1381 /* it's a normal directory. hopefully */
1382 res += len + 1;
1383 }
1384 else
1385 {
1386 /* yay, it was a symlink - build new path in tmp2 */
1387 int rellen = strlen (rel);
1388
1389 errno = ENAMETOOLONG;
1390 if (linklen + 1 + rellen >= PATH_MAX)
1391 return;
1392
1393 errno = ELOOP;
1394 if (!--symlinks)
1395 return;
1396
1397 if (*tmp1 == '/')
1398 res = req->ptr2; /* symlink resolves to an absolute path */
1399
1400 /* we need to be careful, as rel might point into tmp2 already */
1401 memmove (tmp2 + linklen + 1, rel, rellen + 1);
1402 tmp2 [linklen] = '/';
1403 memcpy (tmp2, tmp1, linklen);
1404
1405 rel = tmp2;
1406 }
1407 }
1408
1409 /* special case for the lone root path */
1410 if (res == req->ptr2)
1411 *res++ = '/';
1412
1413 req->result = res - (char *)req->ptr2;
1414
1415done:
1416 req->ptr2 = realloc (req->ptr2, req->result); /* trade time for space savings */
1089} 1417}
1090 1418
1091static signed char 1419static signed char
1092eio_dent_cmp (const eio_dirent *a, const eio_dirent *b) 1420eio_dent_cmp (const eio_dirent *a, const eio_dirent *b)
1093{ 1421{
1275 1603
1276 X_LOCK (wrklock); 1604 X_LOCK (wrklock);
1277 /* the corresponding closedir is in ETP_WORKER_CLEAR */ 1605 /* the corresponding closedir is in ETP_WORKER_CLEAR */
1278 self->dirp = dirp = opendir (req->ptr1); 1606 self->dirp = dirp = opendir (req->ptr1);
1279 1607
1608 if (req->flags & EIO_FLAG_PTR1_FREE)
1609 free (req->ptr1);
1610
1280 req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE; 1611 req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE;
1281 req->ptr1 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0; 1612 req->ptr1 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0;
1282 req->ptr2 = names = malloc (namesalloc); 1613 req->ptr2 = names = malloc (namesalloc);
1283 X_UNLOCK (wrklock); 1614 X_UNLOCK (wrklock);
1284 1615
1335 /* skip . and .. entries */ 1666 /* skip . and .. entries */
1336 if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) 1667 if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2])))
1337 { 1668 {
1338 int len = D_NAMLEN (entp) + 1; 1669 int len = D_NAMLEN (entp) + 1;
1339 1670
1340 while (expect_false (namesoffs + len > namesalloc)) 1671 while (ecb_expect_false (namesoffs + len > namesalloc))
1341 { 1672 {
1342 namesalloc *= 2; 1673 namesalloc *= 2;
1343 X_LOCK (wrklock); 1674 X_LOCK (wrklock);
1344 req->ptr2 = names = realloc (names, namesalloc); 1675 req->ptr2 = names = realloc (names, namesalloc);
1345 X_UNLOCK (wrklock); 1676 X_UNLOCK (wrklock);
1352 1683
1353 if (dents) 1684 if (dents)
1354 { 1685 {
1355 struct eio_dirent *ent; 1686 struct eio_dirent *ent;
1356 1687
1357 if (expect_false (dentoffs == dentalloc)) 1688 if (ecb_expect_false (dentoffs == dentalloc))
1358 { 1689 {
1359 dentalloc *= 2; 1690 dentalloc *= 2;
1360 X_LOCK (wrklock); 1691 X_LOCK (wrklock);
1361 req->ptr1 = dents = realloc (dents, dentalloc * sizeof (eio_dirent)); 1692 req->ptr1 = dents = realloc (dents, dentalloc * sizeof (eio_dirent));
1362 X_UNLOCK (wrklock); 1693 X_UNLOCK (wrklock);
1450 break; 1781 break;
1451 } 1782 }
1452 } 1783 }
1453} 1784}
1454 1785
1455#ifdef PAGESIZE
1456# define eio_pagesize() PAGESIZE
1457#else
1458static intptr_t
1459eio_pagesize (void)
1460{
1461 static intptr_t page;
1462
1463 if (!page)
1464 page = sysconf (_SC_PAGESIZE);
1465
1466 return page;
1467}
1468#endif
1469
1470static void
1471eio_page_align (void **addr, size_t *length)
1472{
1473 intptr_t mask = eio_pagesize () - 1;
1474
1475 /* round down addr */
1476 intptr_t adj = mask & (intptr_t)*addr;
1477
1478 *addr = (void *)((intptr_t)*addr - adj);
1479 *length += adj;
1480
1481 /* round up length */
1482 *length = (*length + mask) & ~mask;
1483}
1484
1485#if !_POSIX_MEMLOCK
1486# define eio__mlockall(a) ((errno = ENOSYS), -1)
1487#else
1488
1489static int
1490eio__mlockall (int flags)
1491{
1492 #if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7
1493 extern int mallopt (int, int);
1494 mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */
1495 #endif
1496
1497 if (EIO_MCL_CURRENT != MCL_CURRENT
1498 || EIO_MCL_FUTURE != MCL_FUTURE)
1499 {
1500 flags = 0
1501 | (flags & EIO_MCL_CURRENT ? MCL_CURRENT : 0)
1502 | (flags & EIO_MCL_FUTURE ? MCL_FUTURE : 0);
1503 }
1504
1505 return mlockall (flags);
1506}
1507#endif
1508
1509#if !_POSIX_MEMLOCK_RANGE
1510# define eio__mlock(a,b) ((errno = ENOSYS), -1)
1511#else
1512
1513static int
1514eio__mlock (void *addr, size_t length)
1515{
1516 eio_page_align (&addr, &length);
1517
1518 return mlock (addr, length);
1519}
1520
1521#endif
1522
1523#if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO)
1524# define eio__msync(a,b,c) ((errno = ENOSYS), -1)
1525#else
1526
1527int
1528eio__msync (void *mem, size_t len, int flags)
1529{
1530 eio_page_align (&mem, &len);
1531
1532 if (EIO_MS_ASYNC != MS_SYNC
1533 || EIO_MS_INVALIDATE != MS_INVALIDATE
1534 || EIO_MS_SYNC != MS_SYNC)
1535 {
1536 flags = 0
1537 | (flags & EIO_MS_ASYNC ? MS_ASYNC : 0)
1538 | (flags & EIO_MS_INVALIDATE ? MS_INVALIDATE : 0)
1539 | (flags & EIO_MS_SYNC ? MS_SYNC : 0);
1540 }
1541
1542 return msync (mem, len, flags);
1543}
1544
1545#endif
1546
1547int
1548eio__mtouch (eio_req *req)
1549{
1550 void *mem = req->ptr2;
1551 size_t len = req->size;
1552 int flags = req->int1;
1553
1554 eio_page_align (&mem, &len);
1555
1556 {
1557 intptr_t addr = (intptr_t)mem;
1558 intptr_t end = addr + len;
1559 intptr_t page = eio_pagesize ();
1560
1561 if (addr < end)
1562 if (flags & EIO_MT_MODIFY) /* modify */
1563 do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len && !EIO_CANCELLED (req));
1564 else
1565 do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len && !EIO_CANCELLED (req));
1566 }
1567
1568 return 0;
1569}
1570
1571/*****************************************************************************/ 1786/*****************************************************************************/
1572 1787
1573#define ALLOC(len) \ 1788#define ALLOC(len) \
1574 if (!req->ptr2) \ 1789 if (!req->ptr2) \
1575 { \ 1790 { \
1632 X_UNLOCK (reqlock); 1847 X_UNLOCK (reqlock);
1633 1848
1634 if (req->type < 0) 1849 if (req->type < 0)
1635 goto quit; 1850 goto quit;
1636 1851
1637 if (!EIO_CANCELLED (req))
1638 ETP_EXECUTE (self, req); 1852 ETP_EXECUTE (self, req);
1639 1853
1640 X_LOCK (reslock); 1854 X_LOCK (reslock);
1641 1855
1642 ++npending; 1856 ++npending;
1643 1857
1658 return 0; 1872 return 0;
1659} 1873}
1660 1874
1661/*****************************************************************************/ 1875/*****************************************************************************/
1662 1876
1877int ecb_cold
1663int eio_init (void (*want_poll)(void), void (*done_poll)(void)) 1878eio_init (void (*want_poll)(void), void (*done_poll)(void))
1664{ 1879{
1665 return etp_init (want_poll, done_poll); 1880 return etp_init (want_poll, done_poll);
1666} 1881}
1667 1882
1883ecb_inline void
1668static void eio_api_destroy (eio_req *req) 1884eio_api_destroy (eio_req *req)
1669{ 1885{
1670 free (req); 1886 free (req);
1671} 1887}
1672 1888
1673#define REQ(rtype) \ 1889#define REQ(rtype) \
1692 { \ 1908 { \
1693 eio_api_destroy (req); \ 1909 eio_api_destroy (req); \
1694 return 0; \ 1910 return 0; \
1695 } 1911 }
1696 1912
1913static void
1697static void eio_execute (etp_worker *self, eio_req *req) 1914eio_execute (etp_worker *self, eio_req *req)
1698{ 1915{
1916 if (ecb_expect_false (EIO_CANCELLED (req)))
1917 {
1918 req->result = -1;
1919 req->errorno = ECANCELED;
1920 return;
1921 }
1922
1699 switch (req->type) 1923 switch (req->type)
1700 { 1924 {
1701 case EIO_READ: ALLOC (req->size); 1925 case EIO_READ: ALLOC (req->size);
1702 req->result = req->offs >= 0 1926 req->result = req->offs >= 0
1703 ? pread (req->int1, req->ptr2, req->size, req->offs) 1927 ? pread (req->int1, req->ptr2, req->size, req->offs)
1737 case EIO_RENAME: req->result = rename (req->ptr1, req->ptr2); break; 1961 case EIO_RENAME: req->result = rename (req->ptr1, req->ptr2); break;
1738 case EIO_LINK: req->result = link (req->ptr1, req->ptr2); break; 1962 case EIO_LINK: req->result = link (req->ptr1, req->ptr2); break;
1739 case EIO_SYMLINK: req->result = symlink (req->ptr1, req->ptr2); break; 1963 case EIO_SYMLINK: req->result = symlink (req->ptr1, req->ptr2); break;
1740 case EIO_MKNOD: req->result = mknod (req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break; 1964 case EIO_MKNOD: req->result = mknod (req->ptr1, (mode_t)req->int2, (dev_t)req->offs); break;
1741 1965
1966 case EIO_REALPATH: eio__realpath (req, self); break;
1967
1742 case EIO_READLINK: ALLOC (PATH_MAX); 1968 case EIO_READLINK: ALLOC (PATH_MAX);
1743 req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break; 1969 req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break;
1744 1970
1745 case EIO_SYNC: req->result = 0; sync (); break; 1971 case EIO_SYNC: req->result = 0; sync (); break;
1746 case EIO_FSYNC: req->result = fsync (req->int1); break; 1972 case EIO_FSYNC: req->result = fsync (req->int1); break;
1748 case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break; 1974 case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break;
1749 case EIO_MTOUCH: req->result = eio__mtouch (req); break; 1975 case EIO_MTOUCH: req->result = eio__mtouch (req); break;
1750 case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break; 1976 case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break;
1751 case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; 1977 case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break;
1752 case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; 1978 case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break;
1979 case EIO_FALLOCATE: req->result = eio__fallocate (req->int1, req->int2, req->offs, req->size); break;
1753 1980
1754 case EIO_READDIR: eio__scandir (req, self); break; 1981 case EIO_READDIR: eio__scandir (req, self); break;
1755 1982
1756 case EIO_BUSY: 1983 case EIO_BUSY:
1757#ifdef _WIN32 1984#ifdef _WIN32
1857eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data) 2084eio_req *eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data)
1858{ 2085{
1859 REQ (EIO_SYNC_FILE_RANGE); req->int1 = fd; req->offs = offset; req->size = nbytes; req->int2 = flags; SEND; 2086 REQ (EIO_SYNC_FILE_RANGE); req->int1 = fd; req->offs = offset; req->size = nbytes; req->int2 = flags; SEND;
1860} 2087}
1861 2088
2089eio_req *eio_fallocate (int fd, int mode, off_t offset, size_t len, int pri, eio_cb cb, void *data)
2090{
2091 REQ (EIO_FALLOCATE); req->int1 = fd; req->int2 = mode; req->offs = offset; req->size = len; SEND;
2092}
2093
1862eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data) 2094eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data)
1863{ 2095{
1864 REQ (EIO_FDATASYNC); req->int1 = fd; SEND; 2096 REQ (EIO_FDATASYNC); req->int1 = fd; SEND;
1865} 2097}
1866 2098
1961} 2193}
1962 2194
1963eio_req *eio_readlink (const char *path, int pri, eio_cb cb, void *data) 2195eio_req *eio_readlink (const char *path, int pri, eio_cb cb, void *data)
1964{ 2196{
1965 return eio__1path (EIO_READLINK, path, pri, cb, data); 2197 return eio__1path (EIO_READLINK, path, pri, cb, data);
2198}
2199
2200eio_req *eio_realpath (const char *path, int pri, eio_cb cb, void *data)
2201{
2202 return eio__1path (EIO_REALPATH, path, pri, cb, data);
1966} 2203}
1967 2204
1968eio_req *eio_stat (const char *path, int pri, eio_cb cb, void *data) 2205eio_req *eio_stat (const char *path, int pri, eio_cb cb, void *data)
1969{ 2206{
1970 return eio__1path (EIO_STAT, path, pri, cb, data); 2207 return eio__1path (EIO_STAT, path, pri, cb, data);
2029eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data) 2266eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data)
2030{ 2267{
2031 return eio__2path (EIO_RENAME, path, new_path, pri, cb, data); 2268 return eio__2path (EIO_RENAME, path, new_path, pri, cb, data);
2032} 2269}
2033 2270
2034eio_req *eio_custom (void (*)(eio_req *) execute, int pri, eio_cb cb, void *data); 2271eio_req *eio_custom (void (*execute)(eio_req *), int pri, eio_cb cb, void *data)
2035{ 2272{
2036 REQ (EIO_CUSTOM); req->feed = execute; SEND; 2273 REQ (EIO_CUSTOM); req->feed = execute; SEND;
2037} 2274}
2038 2275
2039#endif 2276#endif
2050#undef SEND 2287#undef SEND
2051 2288
2052/*****************************************************************************/ 2289/*****************************************************************************/
2053/* grp functions */ 2290/* grp functions */
2054 2291
2292void
2055void eio_grp_feed (eio_req *grp, void (*feed)(eio_req *req), int limit) 2293eio_grp_feed (eio_req *grp, void (*feed)(eio_req *req), int limit)
2056{ 2294{
2057 grp->int2 = limit; 2295 grp->int2 = limit;
2058 grp->feed = feed; 2296 grp->feed = feed;
2059 2297
2060 grp_try_feed (grp); 2298 grp_try_feed (grp);
2061} 2299}
2062 2300
2301void
2063void eio_grp_limit (eio_req *grp, int limit) 2302eio_grp_limit (eio_req *grp, int limit)
2064{ 2303{
2065 grp->int2 = limit; 2304 grp->int2 = limit;
2066 2305
2067 grp_try_feed (grp); 2306 grp_try_feed (grp);
2068} 2307}
2069 2308
2309void
2070void eio_grp_add (eio_req *grp, eio_req *req) 2310eio_grp_add (eio_req *grp, eio_req *req)
2071{ 2311{
2072 assert (("cannot add requests to IO::AIO::GRP after the group finished", grp->int1 != 2)); 2312 assert (("cannot add requests to IO::AIO::GRP after the group finished", grp->int1 != 2));
2073 2313
2074 grp->flags |= EIO_FLAG_GROUPADD; 2314 grp->flags |= EIO_FLAG_GROUPADD;
2075 2315
2086} 2326}
2087 2327
2088/*****************************************************************************/ 2328/*****************************************************************************/
2089/* misc garbage */ 2329/* misc garbage */
2090 2330
2331ssize_t
2091ssize_t eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count) 2332eio_sendfile_sync (int ofd, int ifd, off_t offset, size_t count)
2092{ 2333{
2093 etp_worker wrk; 2334 etp_worker wrk;
2094 ssize_t ret; 2335 ssize_t ret;
2095 2336
2096 wrk.dbuf = 0; 2337 wrk.dbuf = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines