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.20 by root, Thu Jun 19 09:05:43 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;
946 948
947 if (errno) 949 if (errno)
948 res = -1; 950 res = -1;
949 951
950 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;
951} 982}
952 983
953/*****************************************************************************/ 984/*****************************************************************************/
954 985
955#define ALLOC(len) \ 986#define ALLOC(len) \
1122 req->result = readlink (req->ptr1, req->ptr2, NAME_MAX); break; 1153 req->result = readlink (req->ptr1, req->ptr2, NAME_MAX); break;
1123 1154
1124 case EIO_SYNC: req->result = 0; sync (); break; 1155 case EIO_SYNC: req->result = 0; sync (); break;
1125 case EIO_FSYNC: req->result = fsync (req->int1); break; 1156 case EIO_FSYNC: req->result = fsync (req->int1); break;
1126 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;
1127 1160
1128 case EIO_READDIR: eio__scandir (req, self); break; 1161 case EIO_READDIR: eio__scandir (req, self); break;
1129 1162
1130 case EIO_BUSY: 1163 case EIO_BUSY:
1131#ifdef _WIN32 1164#ifdef _WIN32
1170 case EIO_NOP: 1203 case EIO_NOP:
1171 req->result = 0; 1204 req->result = 0;
1172 break; 1205 break;
1173 1206
1174 case EIO_CUSTOM: 1207 case EIO_CUSTOM:
1175 req->feed (req); 1208 ((void (*)(eio_req *))req->feed) (req);
1176 break; 1209 break;
1177 1210
1178 default: 1211 default:
1179 req->result = -1; 1212 req->result = -1;
1180 break; 1213 break;
1201} 1234}
1202 1235
1203eio_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)
1204{ 1237{
1205 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;
1206} 1249}
1207 1250
1208eio_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)
1209{ 1252{
1210 REQ (EIO_FDATASYNC); req->int1 = fd; SEND; 1253 REQ (EIO_FDATASYNC); req->int1 = fd; SEND;
1367 return eio__2path (EIO_RENAME, path, new_path, pri, cb, data); 1410 return eio__2path (EIO_RENAME, path, new_path, pri, cb, data);
1368} 1411}
1369 1412
1370eio_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)
1371{ 1414{
1372 REQ (EIO_CUSTOM); req->feed = execute; SEND; 1415 REQ (EIO_CUSTOM); req->feed = (void (*)(eio_req *))execute; SEND;
1373} 1416}
1374 1417
1375#endif 1418#endif
1376 1419
1377eio_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