… | |
… | |
35 | * and other provisions required by the GPL. If you do not delete the |
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 |
36 | * provisions above, a recipient may use your version of this file under |
37 | * either the BSD or the GPL. |
37 | * either the BSD or the GPL. |
38 | */ |
38 | */ |
39 | |
39 | |
|
|
40 | #ifndef _WIN32 |
|
|
41 | # include "config.h" |
|
|
42 | #endif |
|
|
43 | |
40 | #include "eio.h" |
44 | #include "eio.h" |
41 | |
45 | |
42 | #ifdef EIO_STACKSIZE |
46 | #ifdef EIO_STACKSIZE |
43 | # define XTHREAD_STACKSIZE EIO_STACKSIZE |
47 | # define XTHREAD_STACKSIZE EIO_STACKSIZE |
44 | #endif |
48 | #endif |
… | |
… | |
54 | #include <sys/statvfs.h> |
58 | #include <sys/statvfs.h> |
55 | #include <limits.h> |
59 | #include <limits.h> |
56 | #include <fcntl.h> |
60 | #include <fcntl.h> |
57 | #include <assert.h> |
61 | #include <assert.h> |
58 | |
62 | |
|
|
63 | /* intptr_t comes from unistd.h, says POSIX/UNIX/tradition */ |
|
|
64 | /* intptr_t only comes form stdint.h, says idiot openbsd coder */ |
|
|
65 | #if HAVE_STDINT_H |
|
|
66 | # include <stdint.h> |
|
|
67 | #endif |
|
|
68 | |
59 | #ifndef EIO_FINISH |
69 | #ifndef EIO_FINISH |
60 | # define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0 |
70 | # define EIO_FINISH(req) ((req)->finish) && !EIO_CANCELLED (req) ? (req)->finish (req) : 0 |
61 | #endif |
71 | #endif |
62 | |
72 | |
63 | #ifndef EIO_DESTROY |
73 | #ifndef EIO_DESTROY |
… | |
… | |
71 | #ifdef _WIN32 |
81 | #ifdef _WIN32 |
72 | |
82 | |
73 | /*doh*/ |
83 | /*doh*/ |
74 | #else |
84 | #else |
75 | |
85 | |
76 | # include "config.h" |
|
|
77 | # include <sys/time.h> |
86 | # include <sys/time.h> |
78 | # include <sys/select.h> |
87 | # include <sys/select.h> |
79 | # include <unistd.h> |
88 | # include <unistd.h> |
80 | # include <utime.h> |
89 | # include <utime.h> |
81 | # include <signal.h> |
90 | # include <signal.h> |
… | |
… | |
132 | #endif |
141 | #endif |
133 | #ifndef D_NAMLEN |
142 | #ifndef D_NAMLEN |
134 | # define D_NAMLEN(de) strlen ((de)->d_name) |
143 | # define D_NAMLEN(de) strlen ((de)->d_name) |
135 | #endif |
144 | #endif |
136 | |
145 | |
137 | /* number of seconds after which an idle threads exit */ |
|
|
138 | #define IDLE_TIMEOUT 10 |
|
|
139 | |
|
|
140 | /* used for struct dirent, AIX doesn't provide it */ |
146 | /* used for struct dirent, AIX doesn't provide it */ |
141 | #ifndef NAME_MAX |
147 | #ifndef NAME_MAX |
142 | # define NAME_MAX 4096 |
148 | # define NAME_MAX 4096 |
143 | #endif |
149 | #endif |
144 | |
150 | |
… | |
… | |
223 | static unsigned int max_poll_reqs; /* reslock */ |
229 | static unsigned int max_poll_reqs; /* reslock */ |
224 | |
230 | |
225 | static volatile unsigned int nreqs; /* reqlock */ |
231 | static volatile unsigned int nreqs; /* reqlock */ |
226 | static volatile unsigned int nready; /* reqlock */ |
232 | static volatile unsigned int nready; /* reqlock */ |
227 | static volatile unsigned int npending; /* reqlock */ |
233 | static volatile unsigned int npending; /* reqlock */ |
228 | static volatile unsigned int max_idle = 4; |
234 | static volatile unsigned int max_idle = 4; /* maximum number of threads that can idle indefinitely */ |
|
|
235 | static volatile unsigned int idle_timeout = 10; /* number of seconds after which an idle threads exit */ |
229 | |
236 | |
230 | static xmutex_t wrklock = X_MUTEX_INIT; |
237 | static xmutex_t wrklock; |
231 | static xmutex_t reslock = X_MUTEX_INIT; |
238 | static xmutex_t reslock; |
232 | static xmutex_t reqlock = X_MUTEX_INIT; |
239 | static xmutex_t reqlock; |
233 | static xcond_t reqwait = X_COND_INIT; |
240 | static xcond_t reqwait; |
234 | |
241 | |
235 | #if !HAVE_PREADWRITE |
242 | #if !HAVE_PREADWRITE |
236 | /* |
243 | /* |
237 | * make our pread/pwrite emulation safe against themselves, but not against |
244 | * make our pread/pwrite emulation safe against themselves, but not against |
238 | * normal read/write by using a mutex. slows down execution a lot, |
245 | * normal read/write by using a mutex. slows down execution a lot, |
… | |
… | |
368 | } |
375 | } |
369 | |
376 | |
370 | abort (); |
377 | abort (); |
371 | } |
378 | } |
372 | |
379 | |
|
|
380 | static void etp_thread_init (void) |
|
|
381 | { |
|
|
382 | X_MUTEX_CREATE (wrklock); |
|
|
383 | X_MUTEX_CREATE (reslock); |
|
|
384 | X_MUTEX_CREATE (reqlock); |
|
|
385 | X_COND_CREATE (reqwait); |
|
|
386 | } |
|
|
387 | |
373 | static void etp_atfork_prepare (void) |
388 | static void etp_atfork_prepare (void) |
374 | { |
389 | { |
375 | X_LOCK (wrklock); |
390 | X_LOCK (wrklock); |
376 | X_LOCK (reqlock); |
391 | X_LOCK (reqlock); |
377 | X_LOCK (reslock); |
392 | X_LOCK (reslock); |
… | |
… | |
415 | idle = 0; |
430 | idle = 0; |
416 | nreqs = 0; |
431 | nreqs = 0; |
417 | nready = 0; |
432 | nready = 0; |
418 | npending = 0; |
433 | npending = 0; |
419 | |
434 | |
420 | etp_atfork_parent (); |
435 | etp_thread_init (); |
421 | } |
436 | } |
422 | |
437 | |
423 | static void |
438 | static void |
424 | etp_once_init (void) |
439 | etp_once_init (void) |
425 | { |
440 | { |
|
|
441 | etp_thread_init (); |
426 | X_THREAD_ATFORK (etp_atfork_prepare, etp_atfork_parent, etp_atfork_child); |
442 | X_THREAD_ATFORK (etp_atfork_prepare, etp_atfork_parent, etp_atfork_child); |
427 | } |
443 | } |
428 | |
444 | |
429 | static int |
445 | static int |
430 | etp_init (void (*want_poll)(void), void (*done_poll)(void)) |
446 | etp_init (void (*want_poll)(void), void (*done_poll)(void)) |
… | |
… | |
621 | } |
637 | } |
622 | |
638 | |
623 | static void etp_set_max_idle (unsigned int nthreads) |
639 | static void etp_set_max_idle (unsigned int nthreads) |
624 | { |
640 | { |
625 | if (WORDACCESS_UNSAFE) X_LOCK (reqlock); |
641 | if (WORDACCESS_UNSAFE) X_LOCK (reqlock); |
626 | max_idle = nthreads <= 0 ? 1 : nthreads; |
642 | max_idle = nthreads; |
|
|
643 | if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); |
|
|
644 | } |
|
|
645 | |
|
|
646 | static void etp_set_idle_timeout (unsigned int seconds) |
|
|
647 | { |
|
|
648 | if (WORDACCESS_UNSAFE) X_LOCK (reqlock); |
|
|
649 | idle_timeout = seconds; |
627 | if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); |
650 | if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); |
628 | } |
651 | } |
629 | |
652 | |
630 | static void etp_set_min_parallel (unsigned int nthreads) |
653 | static void etp_set_min_parallel (unsigned int nthreads) |
631 | { |
654 | { |
… | |
… | |
757 | } |
780 | } |
758 | |
781 | |
759 | void eio_set_max_idle (unsigned int nthreads) |
782 | void eio_set_max_idle (unsigned int nthreads) |
760 | { |
783 | { |
761 | etp_set_max_idle (nthreads); |
784 | etp_set_max_idle (nthreads); |
|
|
785 | } |
|
|
786 | |
|
|
787 | void eio_set_idle_timeout (unsigned int seconds) |
|
|
788 | { |
|
|
789 | etp_set_idle_timeout (seconds); |
762 | } |
790 | } |
763 | |
791 | |
764 | void eio_set_min_parallel (unsigned int nthreads) |
792 | void eio_set_min_parallel (unsigned int nthreads) |
765 | { |
793 | { |
766 | etp_set_min_parallel (nthreads); |
794 | etp_set_min_parallel (nthreads); |
… | |
… | |
914 | |
942 | |
915 | /* sendfile always needs emulation */ |
943 | /* sendfile always needs emulation */ |
916 | static ssize_t |
944 | static ssize_t |
917 | eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) |
945 | eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) |
918 | { |
946 | { |
|
|
947 | ssize_t written = 0; |
919 | ssize_t res; |
948 | ssize_t res; |
920 | |
949 | |
921 | if (!count) |
950 | if (!count) |
922 | return 0; |
951 | return 0; |
923 | |
952 | |
|
|
953 | for (;;) |
|
|
954 | { |
924 | #if HAVE_SENDFILE |
955 | #if HAVE_SENDFILE |
925 | # if __linux |
956 | # if __linux |
|
|
957 | off_t soffset = offset; |
926 | res = sendfile (ofd, ifd, &offset, count); |
958 | res = sendfile (ofd, ifd, &soffset, count); |
927 | |
959 | |
928 | # elif __FreeBSD__ |
960 | # elif __FreeBSD__ |
929 | /* |
961 | /* |
930 | * Of course, the freebsd sendfile is a dire hack with no thoughts |
962 | * Of course, the freebsd sendfile is a dire hack with no thoughts |
931 | * wasted on making it similar to other I/O functions. |
963 | * wasted on making it similar to other I/O functions. |
932 | */ |
964 | */ |
933 | { |
|
|
934 | off_t sbytes; |
965 | off_t sbytes; |
935 | res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0); |
966 | res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0); |
936 | |
967 | |
937 | #if 0 /* according to the manpage, this is correct, but broken behaviour */ |
968 | #if 0 /* according to the manpage, this is correct, but broken behaviour */ |
938 | /* freebsd' sendfile will return 0 on success */ |
969 | /* freebsd' sendfile will return 0 on success */ |
939 | /* freebsd 8 documents it as only setting *sbytes on EINTR and EAGAIN, but */ |
970 | /* freebsd 8 documents it as only setting *sbytes on EINTR and EAGAIN, but */ |
940 | /* not on e.g. EIO or EPIPE - sounds broken */ |
971 | /* not on e.g. EIO or EPIPE - sounds broken */ |
941 | if ((res < 0 && (errno == EAGAIN || errno == EINTR) && sbytes) || res == 0) |
972 | if ((res < 0 && (errno == EAGAIN || errno == EINTR) && sbytes) || res == 0) |
942 | res = sbytes; |
973 | res = sbytes; |
943 | #endif |
974 | #endif |
944 | |
975 | |
945 | /* according to source inspection, this is correct, and useful behaviour */ |
976 | /* according to source inspection, this is correct, and useful behaviour */ |
946 | if (sbytes) |
977 | if (sbytes) |
947 | res = sbytes; |
978 | res = sbytes; |
948 | } |
|
|
949 | |
979 | |
950 | # elif defined (__APPLE__) |
980 | # elif defined (__APPLE__) |
951 | |
|
|
952 | { |
|
|
953 | off_t sbytes = count; |
981 | off_t sbytes = count; |
954 | res = sendfile (ifd, ofd, offset, &sbytes, 0, 0); |
982 | res = sendfile (ifd, ofd, offset, &sbytes, 0, 0); |
955 | |
983 | |
956 | /* according to the manpage, sbytes is always valid */ |
984 | /* according to the manpage, sbytes is always valid */ |
957 | if (sbytes) |
985 | if (sbytes) |
958 | res = sbytes; |
986 | res = sbytes; |
959 | } |
|
|
960 | |
987 | |
961 | # elif __hpux |
988 | # elif __hpux |
962 | res = sendfile (ofd, ifd, offset, count, 0, 0); |
989 | res = sendfile (ofd, ifd, offset, count, 0, 0); |
963 | |
990 | |
964 | # elif __solaris |
991 | # elif __solaris |
965 | { |
|
|
966 | struct sendfilevec vec; |
992 | struct sendfilevec vec; |
967 | size_t sbytes; |
993 | size_t sbytes; |
968 | |
994 | |
969 | vec.sfv_fd = ifd; |
995 | vec.sfv_fd = ifd; |
970 | vec.sfv_flag = 0; |
996 | vec.sfv_flag = 0; |
971 | vec.sfv_off = offset; |
997 | vec.sfv_off = offset; |
972 | vec.sfv_len = count; |
998 | vec.sfv_len = count; |
973 | |
999 | |
974 | res = sendfilev (ofd, &vec, 1, &sbytes); |
1000 | res = sendfilev (ofd, &vec, 1, &sbytes); |
975 | |
1001 | |
976 | if (res < 0 && sbytes) |
1002 | if (res < 0 && sbytes) |
977 | res = sbytes; |
1003 | res = sbytes; |
978 | } |
|
|
979 | |
1004 | |
980 | # endif |
1005 | # endif |
981 | |
1006 | |
982 | #elif defined (_WIN32) |
1007 | #elif defined (_WIN32) |
983 | |
|
|
984 | /* does not work, just for documentation of what would need to be done */ |
1008 | /* does not work, just for documentation of what would need to be done */ |
985 | { |
1009 | /* actually, cannot be done like this, as TransmitFile changes the file offset, */ |
|
|
1010 | /* libeio guarantees that the file offset does not change, and windows */ |
|
|
1011 | /* has no way to get an independent handle to the same file description */ |
986 | HANDLE h = TO_SOCKET (ifd); |
1012 | HANDLE h = TO_SOCKET (ifd); |
987 | SetFilePointer (h, offset, 0, FILE_BEGIN); |
1013 | SetFilePointer (h, offset, 0, FILE_BEGIN); |
988 | res = TransmitFile (TO_SOCKET (ofd), h, count, 0, 0, 0, 0); |
1014 | res = TransmitFile (TO_SOCKET (ofd), h, count, 0, 0, 0, 0); |
989 | } |
|
|
990 | |
1015 | |
991 | #else |
1016 | #else |
992 | res = -1; |
1017 | res = -1; |
993 | errno = ENOSYS; |
1018 | errno = ENOSYS; |
994 | #endif |
1019 | #endif |
995 | |
1020 | |
|
|
1021 | /* we assume sendfile can copy at least 128mb in one go */ |
|
|
1022 | if (res <= 128 * 1024 * 1024) |
|
|
1023 | { |
|
|
1024 | if (res > 0) |
|
|
1025 | written += res; |
|
|
1026 | |
|
|
1027 | if (written) |
|
|
1028 | return written; |
|
|
1029 | |
|
|
1030 | break; |
|
|
1031 | } |
|
|
1032 | else |
|
|
1033 | { |
|
|
1034 | /* if we requested more, then probably the kernel was lazy */ |
|
|
1035 | written += res; |
|
|
1036 | offset += res; |
|
|
1037 | count -= res; |
|
|
1038 | |
|
|
1039 | if (!count) |
|
|
1040 | return written; |
|
|
1041 | } |
|
|
1042 | } |
|
|
1043 | |
996 | if (res < 0 |
1044 | if (res < 0 |
997 | && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK |
1045 | && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK |
998 | /* BSDs */ |
1046 | /* BSDs */ |
999 | #ifdef ENOTSUP /* sigh, if the steenking pile called openbsd would only try to at least compile posix code... */ |
1047 | #ifdef ENOTSUP /* sigh, if the steenking pile called openbsd would only try to at least compile posix code... */ |
1000 | || errno == ENOTSUP |
1048 | || errno == ENOTSUP |
1001 | #endif |
1049 | #endif |
… | |
… | |
1041 | } |
1089 | } |
1042 | |
1090 | |
1043 | static signed char |
1091 | static signed char |
1044 | eio_dent_cmp (const eio_dirent *a, const eio_dirent *b) |
1092 | eio_dent_cmp (const eio_dirent *a, const eio_dirent *b) |
1045 | { |
1093 | { |
1046 | return a->score - b->score ? a->score - b->score /* works because our signed char is always 0..100 */ |
1094 | return a->score - b->score ? a->score - b->score /* works because our signed char is always 0..100 */ |
1047 | : a->inode < b->inode ? -1 : a->inode > b->inode ? 1 : 0; |
1095 | : a->inode < b->inode ? -1 |
|
|
1096 | : a->inode > b->inode ? 1 |
|
|
1097 | : 0; |
1048 | } |
1098 | } |
1049 | |
1099 | |
1050 | #define EIO_DENT_CMP(i,op,j) eio_dent_cmp (&i, &j) op 0 |
1100 | #define EIO_DENT_CMP(i,op,j) eio_dent_cmp (&i, &j) op 0 |
1051 | |
1101 | |
1052 | #define EIO_SORT_CUTOFF 30 /* quite high, but performs well on many filesystems */ |
1102 | #define EIO_SORT_CUTOFF 30 /* quite high, but performs well on many filesystems */ |
… | |
… | |
1058 | unsigned char bits [9 + sizeof (ino_t) * 8]; |
1108 | unsigned char bits [9 + sizeof (ino_t) * 8]; |
1059 | unsigned char *bit = bits; |
1109 | unsigned char *bit = bits; |
1060 | |
1110 | |
1061 | assert (CHAR_BIT == 8); |
1111 | assert (CHAR_BIT == 8); |
1062 | assert (sizeof (eio_dirent) * 8 < 256); |
1112 | assert (sizeof (eio_dirent) * 8 < 256); |
1063 | assert (offsetof (eio_dirent, inode)); /* we use 0 as sentinel */ |
1113 | assert (offsetof (eio_dirent, inode)); /* we use bit #0 as sentinel */ |
1064 | assert (offsetof (eio_dirent, score)); /* we use 0 as sentinel */ |
1114 | assert (offsetof (eio_dirent, score)); /* we use bit #0 as sentinel */ |
1065 | |
1115 | |
1066 | if (size <= EIO_SORT_FAST) |
1116 | if (size <= EIO_SORT_FAST) |
1067 | return; |
1117 | return; |
1068 | |
1118 | |
1069 | /* first prepare an array of bits to test in our radix sort */ |
1119 | /* first prepare an array of bits to test in our radix sort */ |
… | |
… | |
1224 | flags &= ~(EIO_READDIR_DIRS_FIRST | EIO_READDIR_STAT_ORDER); |
1274 | flags &= ~(EIO_READDIR_DIRS_FIRST | EIO_READDIR_STAT_ORDER); |
1225 | |
1275 | |
1226 | X_LOCK (wrklock); |
1276 | X_LOCK (wrklock); |
1227 | /* the corresponding closedir is in ETP_WORKER_CLEAR */ |
1277 | /* the corresponding closedir is in ETP_WORKER_CLEAR */ |
1228 | self->dirp = dirp = opendir (req->ptr1); |
1278 | self->dirp = dirp = opendir (req->ptr1); |
|
|
1279 | |
1229 | req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE; |
1280 | req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE; |
1230 | req->ptr1 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0; |
1281 | req->ptr1 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0; |
1231 | req->ptr2 = names = malloc (namesalloc); |
1282 | req->ptr2 = names = malloc (namesalloc); |
1232 | X_UNLOCK (wrklock); |
1283 | X_UNLOCK (wrklock); |
1233 | |
1284 | |
… | |
… | |
1245 | /* sort etc. */ |
1296 | /* sort etc. */ |
1246 | req->int1 = flags; |
1297 | req->int1 = flags; |
1247 | req->result = dentoffs; |
1298 | req->result = dentoffs; |
1248 | |
1299 | |
1249 | if (flags & EIO_READDIR_STAT_ORDER) |
1300 | if (flags & EIO_READDIR_STAT_ORDER) |
1250 | eio_dent_sort (dents, dentoffs, 0, inode_bits); /* sort by inode exclusively */ |
1301 | eio_dent_sort (dents, dentoffs, flags & EIO_READDIR_DIRS_FIRST ? 7 : 0, inode_bits); |
1251 | else if (flags & EIO_READDIR_DIRS_FIRST) |
1302 | else if (flags & EIO_READDIR_DIRS_FIRST) |
1252 | if (flags & EIO_READDIR_FOUND_UNKNOWN) |
1303 | if (flags & EIO_READDIR_FOUND_UNKNOWN) |
1253 | eio_dent_sort (dents, dentoffs, 7, inode_bits); /* sort by score and inode */ |
1304 | eio_dent_sort (dents, dentoffs, 7, inode_bits); /* sort by score and inode */ |
1254 | else |
1305 | else |
1255 | { |
1306 | { |
… | |
… | |
1257 | eio_dirent *oth = dents + dentoffs; |
1308 | eio_dirent *oth = dents + dentoffs; |
1258 | eio_dirent *dir = dents; |
1309 | eio_dirent *dir = dents; |
1259 | |
1310 | |
1260 | /* now partition dirs to the front, and non-dirs to the back */ |
1311 | /* now partition dirs to the front, and non-dirs to the back */ |
1261 | /* by walking from both sides and swapping if necessary */ |
1312 | /* by walking from both sides and swapping if necessary */ |
1262 | /* also clear score, so it doesn't influence sorting */ |
|
|
1263 | while (oth > dir) |
1313 | while (oth > dir) |
1264 | { |
1314 | { |
1265 | if (dir->type == EIO_DT_DIR) |
1315 | if (dir->type == EIO_DT_DIR) |
1266 | ++dir; |
1316 | ++dir; |
1267 | else if ((--oth)->type == EIO_DT_DIR) |
1317 | else if ((--oth)->type == EIO_DT_DIR) |
… | |
… | |
1270 | |
1320 | |
1271 | ++dir; |
1321 | ++dir; |
1272 | } |
1322 | } |
1273 | } |
1323 | } |
1274 | |
1324 | |
1275 | /* now sort the dirs only */ |
1325 | /* now sort the dirs only (dirs all have the same score) */ |
1276 | eio_dent_sort (dents, dir - dents, 0, inode_bits); |
1326 | eio_dent_sort (dents, dir - dents, 0, inode_bits); |
1277 | } |
1327 | } |
1278 | |
1328 | |
1279 | break; |
1329 | break; |
1280 | } |
1330 | } |
… | |
… | |
1493 | } |
1543 | } |
1494 | |
1544 | |
1495 | #endif |
1545 | #endif |
1496 | |
1546 | |
1497 | int |
1547 | int |
1498 | eio__mtouch (void *mem, size_t len, int flags) |
1548 | eio__mtouch (eio_req *req) |
1499 | { |
1549 | { |
|
|
1550 | void *mem = req->ptr2; |
|
|
1551 | size_t len = req->size; |
|
|
1552 | int flags = req->int1; |
|
|
1553 | |
1500 | eio_page_align (&mem, &len); |
1554 | eio_page_align (&mem, &len); |
1501 | |
1555 | |
1502 | { |
1556 | { |
1503 | intptr_t addr = (intptr_t)mem; |
1557 | intptr_t addr = (intptr_t)mem; |
1504 | intptr_t end = addr + len; |
1558 | intptr_t end = addr + len; |
1505 | intptr_t page = eio_pagesize (); |
1559 | intptr_t page = eio_pagesize (); |
1506 | |
1560 | |
1507 | if (addr < end) |
1561 | if (addr < end) |
1508 | if (flags & EIO_MT_MODIFY) /* modify */ |
1562 | if (flags & EIO_MT_MODIFY) /* modify */ |
1509 | do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len); |
1563 | do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len && !EIO_CANCELLED (req)); |
1510 | else |
1564 | else |
1511 | do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len); |
1565 | do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len && !EIO_CANCELLED (req)); |
1512 | } |
1566 | } |
1513 | |
1567 | |
1514 | return 0; |
1568 | return 0; |
1515 | } |
1569 | } |
1516 | |
1570 | |
… | |
… | |
1551 | if (req) |
1605 | if (req) |
1552 | break; |
1606 | break; |
1553 | |
1607 | |
1554 | ++idle; |
1608 | ++idle; |
1555 | |
1609 | |
1556 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
1610 | ts.tv_sec = time (0) + idle_timeout; |
1557 | if (X_COND_TIMEDWAIT (reqwait, reqlock, ts) == ETIMEDOUT) |
1611 | if (X_COND_TIMEDWAIT (reqwait, reqlock, ts) == ETIMEDOUT) |
1558 | { |
1612 | { |
1559 | if (idle > max_idle) |
1613 | if (idle > max_idle) |
1560 | { |
1614 | { |
1561 | --idle; |
1615 | --idle; |
… | |
… | |
1690 | |
1744 | |
1691 | case EIO_SYNC: req->result = 0; sync (); break; |
1745 | case EIO_SYNC: req->result = 0; sync (); break; |
1692 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
1746 | case EIO_FSYNC: req->result = fsync (req->int1); break; |
1693 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
1747 | case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; |
1694 | case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break; |
1748 | case EIO_MSYNC: req->result = eio__msync (req->ptr2, req->size, req->int1); break; |
1695 | case EIO_MTOUCH: req->result = eio__mtouch (req->ptr2, req->size, req->int1); break; |
1749 | case EIO_MTOUCH: req->result = eio__mtouch (req); break; |
1696 | case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break; |
1750 | case EIO_MLOCK: req->result = eio__mlock (req->ptr2, req->size); break; |
1697 | case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; |
1751 | case EIO_MLOCKALL: req->result = eio__mlockall (req->int1); break; |
1698 | case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; |
1752 | case EIO_SYNC_FILE_RANGE: req->result = eio__sync_file_range (req->int1, req->offs, req->size, req->int2); break; |
1699 | |
1753 | |
1700 | case EIO_READDIR: eio__scandir (req, self); break; |
1754 | case EIO_READDIR: eio__scandir (req, self); break; |
… | |
… | |
1744 | case EIO_NOP: |
1798 | case EIO_NOP: |
1745 | req->result = 0; |
1799 | req->result = 0; |
1746 | break; |
1800 | break; |
1747 | |
1801 | |
1748 | case EIO_CUSTOM: |
1802 | case EIO_CUSTOM: |
1749 | ((void (*)(eio_req *))req->feed) (req); |
1803 | req->feed (req); |
1750 | break; |
1804 | break; |
1751 | |
1805 | |
1752 | default: |
1806 | default: |
1753 | errno = ENOSYS; |
1807 | errno = ENOSYS; |
1754 | req->result = -1; |
1808 | req->result = -1; |
… | |
… | |
1975 | eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
2029 | eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data) |
1976 | { |
2030 | { |
1977 | return eio__2path (EIO_RENAME, path, new_path, pri, cb, data); |
2031 | return eio__2path (EIO_RENAME, path, new_path, pri, cb, data); |
1978 | } |
2032 | } |
1979 | |
2033 | |
1980 | eio_req *eio_custom (eio_cb execute, int pri, eio_cb cb, void *data) |
2034 | eio_req *eio_custom (void (*)(eio_req *) execute, int pri, eio_cb cb, void *data); |
1981 | { |
2035 | { |
1982 | REQ (EIO_CUSTOM); req->feed = (void (*)(eio_req *))execute; SEND; |
2036 | REQ (EIO_CUSTOM); req->feed = execute; SEND; |
1983 | } |
2037 | } |
1984 | |
2038 | |
1985 | #endif |
2039 | #endif |
1986 | |
2040 | |
1987 | eio_req *eio_grp (eio_cb cb, void *data) |
2041 | eio_req *eio_grp (eio_cb cb, void *data) |