summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root>2008-09-21 00:23:45 +0000
committerroot <root>2008-09-21 00:23:45 +0000
commitf47493fa352d9c0ae7e10490c89f380195a283fc (patch)
tree81e80e5efb33fb7d589384c5fc4a851044e367b3
parent2593e3d47d7cfef64910fef19d29428fc13c2c92 (diff)
*** empty log message ***
-rw-r--r--Changes4
-rw-r--r--eio.c45
-rw-r--r--eio.h11
3 files changed, 54 insertions, 6 deletions
diff --git a/Changes b/Changes
index 3164d86..e566dd3 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
Revision history for libeio
+TODO: maybe add mincore support? available on at leats darwin, solaris, linux, freebsd
+
1.0
+ - added msync, mtouch support (untested).
+ - fixed custom support.
- "outbundled" from IO::AIO.
diff --git a/eio.c b/eio.c
index 725de8e..61456e2 100644
--- a/eio.c
+++ b/eio.c
@@ -952,6 +952,35 @@ eio__scandir (eio_req *req, etp_worker *self)
req->result = res;
}
+#if !(_POSIX_MAPPED_FILES && _POSIX_SYNCHRONIZED_IO)
+# define msync(a,b,c) ENOSYS
+#endif
+
+int
+eio__mtouch (void *mem, size_t len, int flags)
+{
+ intptr_t addr = (intptr_t)mem;
+ intptr_t end = addr + len;
+#ifdef PAGESIZE
+ const intptr_t page = PAGESIZE;
+#else
+ static intptr_t page;
+
+ if (!page)
+ page = sysconf (_SC_PAGESIZE);
+#endif
+
+ addr &= ~(page - 1); /* assume page size is always a power of two */
+
+ if (addr < end)
+ if (flags) /* modify */
+ do { *((volatile sig_atomic_t *)addr) |= 0; } while ((addr += page) < len);
+ else
+ do { *((volatile sig_atomic_t *)addr) ; } while ((addr += page) < len);
+
+ return 0;
+}
+
/*****************************************************************************/
#define ALLOC(len) \
@@ -1126,6 +1155,8 @@ static void eio_execute (etp_worker *self, eio_req *req)
case EIO_SYNC: req->result = 0; sync (); break;
case EIO_FSYNC: req->result = fsync (req->int1); break;
case EIO_FDATASYNC: req->result = fdatasync (req->int1); break;
+ case EIO_MSYNC: req->result = msync (req->ptr2, req->size, req->int1); break;
+ case EIO_MTOUCH: req->result = eio__mtouch (req->ptr2, req->size, req->int1); break;
case EIO_READDIR: eio__scandir (req, self); break;
@@ -1174,7 +1205,7 @@ static void eio_execute (etp_worker *self, eio_req *req)
break;
case EIO_CUSTOM:
- req->feed (req);
+ ((void (*)(eio_req *))req->feed) (req);
break;
default:
@@ -1207,6 +1238,16 @@ eio_req *eio_fsync (int fd, int pri, eio_cb cb, void *data)
REQ (EIO_FSYNC); req->int1 = fd; SEND;
}
+eio_req *eio_msync (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data)
+{
+ REQ (EIO_MSYNC); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND;
+}
+
+eio_req *eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data)
+{
+ REQ (EIO_MTOUCH); req->ptr2 = addr; req->size = length; req->int1 = flags; SEND;
+}
+
eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data)
{
REQ (EIO_FDATASYNC); req->int1 = fd; SEND;
@@ -1371,7 +1412,7 @@ eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb,
eio_req *eio_custom (eio_cb execute, int pri, eio_cb cb, void *data)
{
- REQ (EIO_CUSTOM); req->feed = execute; SEND;
+ REQ (EIO_CUSTOM); req->feed = (void (*)(eio_req *))execute; SEND;
}
#endif
diff --git a/eio.h b/eio.h
index fd424ba..3c9eac7 100644
--- a/eio.h
+++ b/eio.h
@@ -60,6 +60,7 @@ typedef int (*eio_cb)(eio_req *req);
#endif
enum {
+ EIO_CUSTOM,
EIO_OPEN, EIO_CLOSE, EIO_DUP2,
EIO_READ, EIO_WRITE,
EIO_READAHEAD, EIO_SENDFILE,
@@ -68,12 +69,12 @@ enum {
EIO_UTIME, EIO_FUTIME,
EIO_CHMOD, EIO_FCHMOD,
EIO_CHOWN, EIO_FCHOWN,
- EIO_SYNC, EIO_FSYNC, EIO_FDATASYNC,
+ EIO_SYNC, EIO_FSYNC, EIO_FDATASYNC, EIO_MSYNC, EIO_MTOUCH,
EIO_UNLINK, EIO_RMDIR, EIO_MKDIR, EIO_RENAME,
EIO_MKNOD, EIO_READDIR,
EIO_LINK, EIO_SYMLINK, EIO_READLINK,
EIO_GROUP, EIO_NOP,
- EIO_BUSY, EIO_CUSTOM
+ EIO_BUSY,
};
typedef double eio_tstamp; /* feel free to use double in your code directly */
@@ -86,14 +87,14 @@ struct eio_req
ssize_t result; /* result of syscall, e.g. result = read (... */
off_t offs; /* read, write, truncate, readahead: file offset */
- size_t size; /* read, write, readahead, sendfile: length */
+ size_t size; /* read, write, readahead, sendfile, msync: length */
void *ptr1; /* all applicable requests: pathname, old name */
void *ptr2; /* all applicable requests: new name or memory buffer */
eio_tstamp nv1; /* utime, futime: atime; busy: sleep time */
eio_tstamp nv2; /* utime, futime: mtime */
int type; /* EIO_xxx constant ETP */
- int int1; /* all applicable requests: file descriptor; sendfile: output fd; open: flags */
+ int int1; /* all applicable requests: file descriptor; sendfile: output fd; open, msync: flags */
long int2; /* chown, fchown: uid; sendfile: input fd; open, chmod, mkdir, mknod: file mode */
long int3; /* chown, fchown: gid; mknod: dev_t */
int errorno; /* errno value on syscall return */
@@ -160,6 +161,8 @@ eio_req *eio_busy (eio_tstamp delay, int pri, eio_cb cb, void *data); /* ti
eio_req *eio_sync (int pri, eio_cb cb, void *data);
eio_req *eio_fsync (int fd, int pri, eio_cb cb, void *data);
eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data);
+eio_req *eio_msync (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data);
+eio_req *eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data);
eio_req *eio_close (int fd, int pri, eio_cb cb, void *data);
eio_req *eio_readahead (int fd, off_t offset, size_t length, int pri, eio_cb cb, void *data);
eio_req *eio_read (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data);