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.19 by root, Tue Jun 17 23:34:20 2008 UTC vs.
Revision 1.23 by root, Sun Sep 21 00:23:45 2008 UTC

177static mutex_t wrklock = X_MUTEX_INIT; 177static mutex_t wrklock = X_MUTEX_INIT;
178static mutex_t reslock = X_MUTEX_INIT; 178static mutex_t reslock = X_MUTEX_INIT;
179static mutex_t reqlock = X_MUTEX_INIT; 179static mutex_t reqlock = X_MUTEX_INIT;
180static cond_t reqwait = X_COND_INIT; 180static cond_t reqwait = X_COND_INIT;
181 181
182#if !HAVE_PREADWRITE
183/*
184 * make our pread/pwrite emulation safe against themselves, but not against
185 * normal read/write by using a mutex. slows down execution a lot,
186 * but that's your problem, not mine.
187 */
188static mutex_t preadwritelock = X_MUTEX_INIT;
189#endif
190
182typedef struct etp_worker 191typedef struct etp_worker
183{ 192{
184 /* locked by wrklock */ 193 /* locked by wrklock */
185 struct etp_worker *prev, *next; 194 struct etp_worker *prev, *next;
186 195
330 339
331static void etp_atfork_child (void) 340static void etp_atfork_child (void)
332{ 341{
333 ETP_REQ *prv; 342 ETP_REQ *prv;
334 343
335 while (prv = reqq_shift (&req_queue)) 344 while ((prv = reqq_shift (&req_queue)))
336 ETP_DESTROY (prv); 345 ETP_DESTROY (prv);
337 346
338 while (prv = reqq_shift (&res_queue)) 347 while ((prv = reqq_shift (&res_queue)))
339 ETP_DESTROY (prv); 348 ETP_DESTROY (prv);
340 349
341 while (wrk_first.next != &wrk_first) 350 while (wrk_first.next != &wrk_first)
342 { 351 {
343 etp_worker *wrk = wrk_first.next; 352 etp_worker *wrk = wrk_first.next;
700 709
701#if !HAVE_PREADWRITE 710#if !HAVE_PREADWRITE
702# define pread eio__pread 711# define pread eio__pread
703# define pwrite eio__pwrite 712# define pwrite eio__pwrite
704 713
705/*
706 * make our pread/pwrite safe against themselves, but not against
707 * normal read/write by using a mutex. slows down execution a lot,
708 * but that's your problem, not mine.
709 */
710static mutex_t preadwritelock = X_MUTEX_INIT;
711
712static ssize_t 714static ssize_t
713eio__pread (int fd, void *buf, size_t count, off_t offset) 715eio__pread (int fd, void *buf, size_t count, off_t offset)
714{ 716{
715 ssize_t res; 717 ssize_t res;
716 off_t ooffset; 718 off_t ooffset;
903 int memlen = 4096; 905 int memlen = 4096;
904 int memofs = 0; 906 int memofs = 0;
905 int res = 0; 907 int res = 0;
906 908
907 X_LOCK (wrklock); 909 X_LOCK (wrklock);
910 /* the corresponding closedir is in ETP_WORKER_CLEAR */
908 self->dirp = dirp = opendir (req->ptr1); 911 self->dirp = dirp = opendir (req->ptr1);
909 req->flags |= EIO_FLAG_PTR2_FREE; 912 req->flags |= EIO_FLAG_PTR2_FREE;
910 req->ptr2 = names = malloc (memlen); 913 req->ptr2 = names = malloc (memlen);
911 X_UNLOCK (wrklock); 914 X_UNLOCK (wrklock);
912 915
945 948
946 if (errno) 949 if (errno)
947 res = -1; 950 res = -1;
948 951
949 req->result = res; 952 req->result = res;
953}
954
955#if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO)
956# define msync(a,b,c) ENOSYS
957#endif
958
959int
960eio__mtouch (void *mem, size_t len, int flags)
961{
962 intptr_t addr = (intptr_t)mem;
963 intptr_t end = addr + len;
964#ifdef PAGESIZE
965 const intptr_t page = PAGESIZE;
966#else
967 static intptr_t page;
968
969 if (!page)
970 page = sysconf (_SC_PAGESIZE);
971#endif
972
973 addr &= ~(page - 1); /* assume page size is always a power of two */
974
975 if (addr < end)
976 if (flags) /* modify */
977 do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len);
978 else
979 do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len);
980
981 return 0;
950} 982}
951 983
952/*****************************************************************************/ 984/*****************************************************************************/
953 985
954#define ALLOC(len) \ 986#define ALLOC(len) \
1121 req->result = readlink (req->ptr1, req->ptr2, NAME_MAX); break; 1153 req->result = readlink (req->ptr1, req->ptr2, NAME_MAX); break;
1122 1154
1123 case EIO_SYNC: req->result = 0; sync (); break; 1155 case EIO_SYNC: req->result = 0; sync (); break;
1124 case EIO_FSYNC: req->result = fsync (req->int1); break; 1156 case EIO_FSYNC: req->result = fsync (req->int1); break;
1125 case EIO_FDATASYNC: req->result = fdatasync (req->int1); break; 1157 case EIO_FDATASYNC: req->result = fdatasync (req->int1); break;
1158 case EIO_MSYNC: req->result = msync (req->ptr2, req->size, req->int1); break;
1159 case EIO_MTOUCH: req->result = eio__mtouch (req->ptr2, req->size, req->int1); break;
1126 1160
1127 case EIO_READDIR: eio__scandir (req, self); break; 1161 case EIO_READDIR: eio__scandir (req, self); break;
1128 1162
1129 case EIO_BUSY: 1163 case EIO_BUSY:
1130#ifdef _WIN32 1164#ifdef _WIN32
1169 case EIO_NOP: 1203 case EIO_NOP:
1170 req->result = 0; 1204 req->result = 0;
1171 break; 1205 break;
1172 1206
1173 case EIO_CUSTOM: 1207 case EIO_CUSTOM:
1174 req->feed (req); 1208 ((void (*)(eio_req *))req->feed) (req);
1175 break; 1209 break;
1176 1210
1177 default: 1211 default:
1178 req->result = -1; 1212 req->result = -1;
1179 break; 1213 break;
1200} 1234}
1201 1235
1202eio_req *eio_fsync (int fd, int pri, eio_cb cb, void *data) 1236eio_req *eio_fsync (int fd, int pri, eio_cb cb, void *data)
1203{ 1237{
1204 REQ (EIO_FSYNC); req->int1 = fd; SEND; 1238 REQ (EIO_FSYNC); req->int1 = fd; SEND;
1239}
1240
1241eio_req *eio_msync (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data)
1242{
1243 REQ (EIO_MSYNC); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND;
1244}
1245
1246eio_req *eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data)
1247{
1248 REQ (EIO_MTOUCH); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND;
1205} 1249}
1206 1250
1207eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data) 1251eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data)
1208{ 1252{
1209 REQ (EIO_FDATASYNC); req->int1 = fd; SEND; 1253 REQ (EIO_FDATASYNC); req->int1 = fd; SEND;
1366 return eio__2path (EIO_RENAME, path, new_path, pri, cb, data); 1410 return eio__2path (EIO_RENAME, path, new_path, pri, cb, data);
1367} 1411}
1368 1412
1369eio_req *eio_custom (eio_cb execute, int pri, eio_cb cb, void *data) 1413eio_req *eio_custom (eio_cb execute, int pri, eio_cb cb, void *data)
1370{ 1414{
1371 REQ (EIO_CUSTOM); req->feed = execute; SEND; 1415 REQ (EIO_CUSTOM); req->feed = (void (*)(eio_req *))execute; SEND;
1372} 1416}
1373 1417
1374#endif 1418#endif
1375 1419
1376eio_req *eio_grp (eio_cb cb, void *data) 1420eio_req *eio_grp (eio_cb cb, void *data)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines