… | |
… | |
379 | static xmutex_t wrklock; |
379 | static xmutex_t wrklock; |
380 | static xmutex_t reslock; |
380 | static xmutex_t reslock; |
381 | static xmutex_t reqlock; |
381 | static xmutex_t reqlock; |
382 | static xcond_t reqwait; |
382 | static xcond_t reqwait; |
383 | |
383 | |
384 | #if !HAVE_PREADWRITE |
|
|
385 | /* |
|
|
386 | * make our pread/pwrite emulation safe against themselves, but not against |
|
|
387 | * normal read/write by using a mutex. slows down execution a lot, |
|
|
388 | * but that's your problem, not mine. |
|
|
389 | */ |
|
|
390 | static xmutex_t preadwritelock; |
|
|
391 | #endif |
|
|
392 | |
|
|
393 | typedef struct etp_worker |
384 | typedef struct etp_worker |
394 | { |
385 | { |
395 | struct tmpbuf tmpbuf; |
386 | struct tmpbuf tmpbuf; |
396 | |
387 | |
397 | /* locked by wrklock */ |
388 | /* locked by wrklock */ |
… | |
… | |
942 | return etp_poll (); |
933 | return etp_poll (); |
943 | } |
934 | } |
944 | |
935 | |
945 | /*****************************************************************************/ |
936 | /*****************************************************************************/ |
946 | /* work around various missing functions */ |
937 | /* work around various missing functions */ |
947 | |
|
|
948 | #if !HAVE_PREADWRITE |
|
|
949 | # undef pread |
|
|
950 | # undef pwrite |
|
|
951 | # define pread eio__pread |
|
|
952 | # define pwrite eio__pwrite |
|
|
953 | |
|
|
954 | static eio_ssize_t |
|
|
955 | eio__pread (int fd, void *buf, size_t count, off_t offset) |
|
|
956 | { |
|
|
957 | eio_ssize_t res; |
|
|
958 | off_t ooffset; |
|
|
959 | |
|
|
960 | X_LOCK (preadwritelock); |
|
|
961 | ooffset = lseek (fd, 0, SEEK_CUR); |
|
|
962 | lseek (fd, offset, SEEK_SET); |
|
|
963 | res = read (fd, buf, count); |
|
|
964 | lseek (fd, ooffset, SEEK_SET); |
|
|
965 | X_UNLOCK (preadwritelock); |
|
|
966 | |
|
|
967 | return res; |
|
|
968 | } |
|
|
969 | |
|
|
970 | static eio_ssize_t |
|
|
971 | eio__pwrite (int fd, void *buf, size_t count, off_t offset) |
|
|
972 | { |
|
|
973 | eio_ssize_t res; |
|
|
974 | off_t ooffset; |
|
|
975 | |
|
|
976 | X_LOCK (preadwritelock); |
|
|
977 | ooffset = lseek (fd, 0, SEEK_CUR); |
|
|
978 | lseek (fd, offset, SEEK_SET); |
|
|
979 | res = write (fd, buf, count); |
|
|
980 | lseek (fd, ooffset, SEEK_SET); |
|
|
981 | X_UNLOCK (preadwritelock); |
|
|
982 | |
|
|
983 | return res; |
|
|
984 | } |
|
|
985 | #endif |
|
|
986 | |
938 | |
987 | #ifndef HAVE_UTIMES |
939 | #ifndef HAVE_UTIMES |
988 | |
940 | |
989 | # undef utimes |
941 | # undef utimes |
990 | # define utimes(path,times) eio__utimes (path, times) |
942 | # define utimes(path,times) eio__utimes (path, times) |
… | |
… | |
2247 | /*****************************************************************************/ |
2199 | /*****************************************************************************/ |
2248 | |
2200 | |
2249 | int ecb_cold |
2201 | int ecb_cold |
2250 | eio_init (void (*want_poll)(void), void (*done_poll)(void)) |
2202 | eio_init (void (*want_poll)(void), void (*done_poll)(void)) |
2251 | { |
2203 | { |
2252 | #if !HAVE_PREADWRITE |
|
|
2253 | X_MUTEX_CREATE (preadwritelock); |
|
|
2254 | #endif |
|
|
2255 | |
|
|
2256 | return etp_init (want_poll, done_poll); |
2204 | return etp_init (want_poll, done_poll); |
2257 | } |
2205 | } |
2258 | |
2206 | |
2259 | ecb_inline void |
2207 | ecb_inline void |
2260 | eio_api_destroy (eio_req *req) |
2208 | eio_api_destroy (eio_req *req) |
2261 | { |
2209 | { |
2262 | free (req); |
2210 | free (req); |
2263 | } |
2211 | } |
2264 | |
2212 | |
2265 | #define REQ(rtype) \ |
2213 | #define REQ(rtype) \ |
2266 | eio_req *req; \ |
2214 | eio_req *req; \ |
2267 | \ |
2215 | \ |
2268 | req = (eio_req *)calloc (1, sizeof *req); \ |
2216 | req = (eio_req *)calloc (1, sizeof *req); \ |
2269 | if (!req) \ |
2217 | if (!req) \ |
2270 | return 0; \ |
2218 | return 0; \ |