… | |
… | |
47 | /* used for struct dirent, AIX doesn't provide it */ |
47 | /* used for struct dirent, AIX doesn't provide it */ |
48 | #ifndef NAME_MAX |
48 | #ifndef NAME_MAX |
49 | # define NAME_MAX 4096 |
49 | # define NAME_MAX 4096 |
50 | #endif |
50 | #endif |
51 | |
51 | |
|
|
52 | #ifndef PTHREAD_STACK_MIN |
|
|
53 | /* care for broken platforms, e.g. windows */ |
|
|
54 | # define PTHREAD_STACK_MIN 16384 |
|
|
55 | #endif |
|
|
56 | |
52 | #if __ia64 |
57 | #if __ia64 |
53 | # define STACKSIZE 65536 |
58 | # define STACKSIZE 65536 |
54 | #elif __i386 || __x86_64 /* 16k is unreasonably high :( */ |
59 | #elif __i386 || __x86_64 /* 16k is unreasonably high :( */ |
55 | # define STACKSIZE PTHREAD_STACK_MIN |
60 | # define STACKSIZE PTHREAD_STACK_MIN |
56 | #else |
61 | #else |
… | |
… | |
128 | |
133 | |
129 | static int next_pri = DEFAULT_PRI + PRI_BIAS; |
134 | static int next_pri = DEFAULT_PRI + PRI_BIAS; |
130 | |
135 | |
131 | static int started, wanted; |
136 | static int started, wanted; |
132 | static volatile int nreqs; |
137 | static volatile int nreqs; |
133 | static int max_outstanding = 1<<30; |
|
|
134 | static int respipe [2]; |
138 | static int respipe [2]; |
135 | |
139 | |
136 | #if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) |
140 | #if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) |
137 | # define AIO_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP |
141 | # define AIO_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP |
138 | #else |
142 | #else |
… | |
… | |
238 | } |
242 | } |
239 | |
243 | |
240 | abort (); |
244 | abort (); |
241 | } |
245 | } |
242 | |
246 | |
|
|
247 | static int poll_cb (); |
243 | static void req_invoke (aio_req req); |
248 | static void req_invoke (aio_req req); |
244 | static void req_free (aio_req req); |
249 | static void req_free (aio_req req); |
245 | static void req_cancel (aio_req req); |
250 | static void req_cancel (aio_req req); |
246 | |
251 | |
247 | /* must be called at most once */ |
252 | /* must be called at most once */ |
… | |
… | |
600 | |
605 | |
601 | LOCK (reqlock); |
606 | LOCK (reqlock); |
602 | reqq_push (&req_queue, req); |
607 | reqq_push (&req_queue, req); |
603 | pthread_cond_signal (&reqwait); |
608 | pthread_cond_signal (&reqwait); |
604 | UNLOCK (reqlock); |
609 | UNLOCK (reqlock); |
605 | |
|
|
606 | if (nreqs > max_outstanding) |
|
|
607 | for (;;) |
|
|
608 | { |
|
|
609 | poll_cb (); |
|
|
610 | |
|
|
611 | if (nreqs <= max_outstanding) |
|
|
612 | break; |
|
|
613 | |
|
|
614 | poll_wait (); |
|
|
615 | } |
|
|
616 | } |
610 | } |
617 | |
611 | |
618 | static void end_thread (void) |
612 | static void end_thread (void) |
619 | { |
613 | { |
620 | aio_req req; |
614 | aio_req req; |
… | |
… | |
713 | #if !HAVE_FDATASYNC |
707 | #if !HAVE_FDATASYNC |
714 | # define fdatasync fsync |
708 | # define fdatasync fsync |
715 | #endif |
709 | #endif |
716 | |
710 | |
717 | #if !HAVE_READAHEAD |
711 | #if !HAVE_READAHEAD |
718 | # define readahead aio_readahead |
712 | # define readahead(fd,offset,count) aio_readahead (fd, offset, count, self) |
719 | |
713 | |
720 | static ssize_t readahead (int fd, off_t offset, size_t count) |
714 | static ssize_t aio_readahead (int fd, off_t offset, size_t count, worker *self) |
721 | { |
715 | { |
722 | dBUF; |
716 | dBUF; |
723 | |
717 | |
724 | while (count > 0) |
718 | while (count > 0) |
725 | { |
719 | { |
… | |
… | |
730 | count -= len; |
724 | count -= len; |
731 | } |
725 | } |
732 | |
726 | |
733 | errno = 0; |
727 | errno = 0; |
734 | } |
728 | } |
|
|
729 | |
735 | #endif |
730 | #endif |
736 | |
731 | |
737 | #if !HAVE_READDIR_R |
732 | #if !HAVE_READDIR_R |
738 | # define readdir_r aio_readdir_r |
733 | # define readdir_r aio_readdir_r |
739 | |
734 | |
… | |
… | |
1116 | void |
1111 | void |
1117 | max_parallel (nthreads) |
1112 | max_parallel (nthreads) |
1118 | int nthreads |
1113 | int nthreads |
1119 | PROTOTYPE: $ |
1114 | PROTOTYPE: $ |
1120 | |
1115 | |
1121 | int |
|
|
1122 | max_outstanding (nreqs) |
|
|
1123 | int nreqs |
|
|
1124 | PROTOTYPE: $ |
|
|
1125 | CODE: |
|
|
1126 | RETVAL = max_outstanding; |
|
|
1127 | max_outstanding = nreqs; |
|
|
1128 | |
|
|
1129 | void |
1116 | void |
1130 | aio_open (pathname,flags,mode,callback=&PL_sv_undef) |
1117 | aio_open (pathname,flags,mode,callback=&PL_sv_undef) |
1131 | SV * pathname |
1118 | SV * pathname |
1132 | int flags |
1119 | int flags |
1133 | int mode |
1120 | int mode |