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

Comparing libeio/eio.c (file contents):
Revision 1.120 by root, Tue Apr 24 18:47:50 2012 UTC vs.
Revision 1.121 by root, Sat Jun 2 20:13:26 2012 UTC

379static xmutex_t wrklock; 379static xmutex_t wrklock;
380static xmutex_t reslock; 380static xmutex_t reslock;
381static xmutex_t reqlock; 381static xmutex_t reqlock;
382static xcond_t reqwait; 382static 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 */
390static xmutex_t preadwritelock;
391#endif
392
393typedef struct etp_worker 384typedef 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
954static eio_ssize_t
955eio__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
970static eio_ssize_t
971eio__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
2249int ecb_cold 2201int ecb_cold
2250eio_init (void (*want_poll)(void), void (*done_poll)(void)) 2202eio_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
2259ecb_inline void 2207ecb_inline void
2260eio_api_destroy (eio_req *req) 2208eio_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; \

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines