From f6c28d71ab172a33c0faf98503de8a66846d1ab4 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 13 May 2008 17:08:15 +0000 Subject: *** empty log message *** --- demo.c | 103 +++++++++++++++++++++++------------------------------------------ eio.c | 97 +++++++++++++++++++++++++++++++++---------------------------- eio.h | 68 +++++++++++++++++++++---------------------- 3 files changed, 123 insertions(+), 145 deletions(-) diff --git a/demo.c b/demo.c index a21d5cb..439ae7f 100644 --- a/demo.c +++ b/demo.c @@ -128,92 +128,63 @@ main (void) do { /* avoid relative paths yourself(!) */ - eio_mkdir ("eio-test-dir", 0777, res_cb) - ->data = "mkdir"; - eio_nop (res_cb) - ->data = "nop"; + eio_mkdir ("eio-test-dir", 0777, 0, res_cb, "mkdir"); + eio_nop (0, res_cb, "nop"); event_loop (); - eio_stat ("eio-test-dir", stat_cb); - eio_lstat ("eio-test-dir", stat_cb); - eio_open ("eio-test-dir/eio-test-file", O_RDWR | O_CREAT, 0777, open_cb); - eio_symlink ("test", "eio-test-dir/eio-symlink", res_cb) - ->data = "symlink"; - eio_mknod ("eio-test-dir/eio-fifo", S_IFIFO, 0, res_cb) - ->data = "mknod"; + eio_stat ("eio-test-dir", 0, stat_cb, "stat"); + eio_lstat ("eio-test-dir", 0, stat_cb, "stat"); + eio_open ("eio-test-dir/eio-test-file", O_RDWR | O_CREAT, 0777, 0, open_cb, "open"); + eio_symlink ("test", "eio-test-dir/eio-symlink", 0, res_cb, "symlink"); + eio_mknod ("eio-test-dir/eio-fifo", S_IFIFO, 0, 0, res_cb, "mknod"); event_loop (); - eio_utime ("eio-test-dir", 12345.678, 23456.789, res_cb) - ->data = "utime"; - eio_futime (last_fd, 92345.678, 93456.789, res_cb) - ->data = "futime"; - eio_chown ("eio-test-dir", getuid (), getgid (), res_cb) - ->data = "chown"; - eio_fchown (last_fd, getuid (), getgid (), res_cb) - ->data = "fchown"; - eio_fchmod (last_fd, 0123, res_cb) - ->data = "fchmod"; - eio_readdir ("eio-test-dir", readdir_cb); - eio_readdir ("/nonexistant", readdir_cb); - eio_fstat (last_fd, stat_cb); - eio_write (last_fd, "test\nfail\n", 10, 4, res_cb) - ->data = "write"; + eio_utime ("eio-test-dir", 12345.678, 23456.789, 0, res_cb, "utime"); + eio_futime (last_fd, 92345.678, 93456.789, 0, res_cb, "futime"); + eio_chown ("eio-test-dir", getuid (), getgid (), 0, res_cb, "chown"); + eio_fchown (last_fd, getuid (), getgid (), 0, res_cb, "fchown"); + eio_fchmod (last_fd, 0123, 0, res_cb, "fchmod"); + eio_readdir ("eio-test-dir", 0, readdir_cb, "readdir"); + eio_readdir ("/nonexistant", 0, readdir_cb, "readdir"); + eio_fstat (last_fd, 0, stat_cb, "stat"); + eio_write (last_fd, "test\nfail\n", 10, 4, 0, res_cb, "write"); event_loop (); - eio_read (last_fd, 0, 8, 0, read_cb); - eio_readlink ("eio-test-dir/eio-symlink", res_cb) - ->data = "readlink"; + eio_read (last_fd, 0, 8, 0, EIO_PRI_DEFAULT, read_cb, "read"); + eio_readlink ("eio-test-dir/eio-symlink", 0, res_cb, "readlink"); event_loop (); - eio_dup2 (1, 2, res_cb) // dup stdout to stderr - ->data = "dup2"; - eio_chmod ("eio-test-dir", 0765, res_cb) - ->data = "chmod"; - eio_ftruncate (last_fd, 9, res_cb) - ->data = "ftruncate"; - eio_fdatasync (last_fd, res_cb) - ->data = "fdatasync"; - eio_fsync (last_fd, res_cb) - ->data = "fsync"; - eio_sync (res_cb) - ->data = "sync"; - eio_busy (0.5, res_cb) - ->data = "busy"; + eio_dup2 (1, 2, EIO_PRI_DEFAULT, res_cb, "dup"); // dup stdout to stderr + eio_chmod ("eio-test-dir", 0765, 0, res_cb, "chmod"); + eio_ftruncate (last_fd, 9, 0, res_cb, "ftruncate"); + eio_fdatasync (last_fd, 0, res_cb, "fdatasync"); + eio_fsync (last_fd, 0, res_cb, "fsync"); + eio_sync (0, res_cb, "sync"); + eio_busy (0.5, 0, res_cb, "busy"); event_loop (); - eio_sendfile (1, last_fd, 4, 5, res_cb) // write "test\n" to stdout - ->data = "sendfile"; - eio_fstat (last_fd, stat_cb); + eio_sendfile (1, last_fd, 4, 5, 0, res_cb, "sendfile"); // write "test\n" to stdout + eio_fstat (last_fd, 0, stat_cb, "stat"); event_loop (); - eio_truncate ("eio-test-dir/eio-test-file", 6, res_cb) - ->data = "truncate"; - eio_readahead (last_fd, 0, 64, res_cb) - ->data = "readahead"; + eio_truncate ("eio-test-dir/eio-test-file", 6, 0, res_cb, "truncate"); + eio_readahead (last_fd, 0, 64, 0, res_cb, "readahead"); event_loop (); - eio_close (last_fd, res_cb) - ->data = "close"; - eio_link ("eio-test-dir/eio-test-file", "eio-test-dir/eio-test-file-2", res_cb) - ->data = "link"; + eio_close (last_fd, 0, res_cb, "close"); + eio_link ("eio-test-dir/eio-test-file", "eio-test-dir/eio-test-file-2", 0, res_cb, "link"); event_loop (); - eio_rename ("eio-test-dir/eio-test-file", "eio-test-dir/eio-test-file-renamed", res_cb) - ->data = "rename"; + eio_rename ("eio-test-dir/eio-test-file", "eio-test-dir/eio-test-file-renamed", 0, res_cb, "rename"); event_loop (); - eio_unlink ("eio-test-dir/eio-fifo", res_cb) - ->data = "unlink"; - eio_unlink ("eio-test-dir/eio-symlink", res_cb) - ->data = "unlink"; - eio_unlink ("eio-test-dir/eio-test-file-2", res_cb) - ->data = "unlink"; - eio_unlink ("eio-test-dir/eio-test-file-renamed", res_cb) - ->data = "unlink"; + eio_unlink ("eio-test-dir/eio-fifo", 0, res_cb, "unlink"); + eio_unlink ("eio-test-dir/eio-symlink", 0, res_cb, "unlink"); + eio_unlink ("eio-test-dir/eio-test-file-2", 0, res_cb, "unlink"); + eio_unlink ("eio-test-dir/eio-test-file-renamed", 0, res_cb, "unlink"); event_loop (); - eio_rmdir ("eio-test-dir", res_cb) - ->data = "rmdir"; + eio_rmdir ("eio-test-dir", 0, res_cb, "rmdir"); event_loop (); } while (0); diff --git a/eio.c b/eio.c index b1e4728..3e71965 100644 --- a/eio.c +++ b/eio.c @@ -1067,159 +1067,159 @@ static void eio_api_destroy (eio_req *req) return 0; \ } -eio_req *eio_nop (eio_cb cb) +eio_req *eio_nop (int pri, eio_cb cb, void *data) { REQ (EIO_NOP); SEND; } -eio_req *eio_busy (double delay, eio_cb cb) +eio_req *eio_busy (double delay, int pri, eio_cb cb, void *data) { REQ (EIO_BUSY); req->nv1 = delay; SEND; } -eio_req *eio_sync (eio_cb cb) +eio_req *eio_sync (int pri, eio_cb cb, void *data) { REQ (EIO_SYNC); SEND; } -eio_req *eio_fsync (int fd, eio_cb cb) +eio_req *eio_fsync (int fd, int pri, eio_cb cb, void *data) { REQ (EIO_FSYNC); req->int1 = fd; SEND; } -eio_req *eio_fdatasync (int fd, eio_cb cb) +eio_req *eio_fdatasync (int fd, int pri, eio_cb cb, void *data) { REQ (EIO_FDATASYNC); req->int1 = fd; SEND; } -eio_req *eio_close (int fd, eio_cb cb) +eio_req *eio_close (int fd, int pri, eio_cb cb, void *data) { REQ (EIO_CLOSE); req->int1 = fd; SEND; } -eio_req *eio_readahead (int fd, off_t offset, size_t length, eio_cb cb) +eio_req *eio_readahead (int fd, off_t offset, size_t length, int pri, eio_cb cb, void *data) { REQ (EIO_READAHEAD); req->int1 = fd; req->offs = offset; req->size = length; SEND; } -eio_req *eio_read (int fd, void *data, size_t length, off_t offset, eio_cb cb) +eio_req *eio_read (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data) { - REQ (EIO_READ); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = data; SEND; + REQ (EIO_READ); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = buf; SEND; } -eio_req *eio_write (int fd, void *data, size_t length, off_t offset, eio_cb cb) +eio_req *eio_write (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data) { - REQ (EIO_WRITE); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = data; SEND; + REQ (EIO_WRITE); req->int1 = fd; req->offs = offset; req->size = length; req->ptr2 = buf; SEND; } -eio_req *eio_fstat (int fd, eio_cb cb) +eio_req *eio_fstat (int fd, int pri, eio_cb cb, void *data) { REQ (EIO_FSTAT); req->int1 = fd; SEND; } -eio_req *eio_futime (int fd, double atime, double mtime, eio_cb cb) +eio_req *eio_futime (int fd, double atime, double mtime, int pri, eio_cb cb, void *data) { REQ (EIO_FUTIME); req->int1 = fd; req->nv1 = atime; req->nv2 = mtime; SEND; } -eio_req *eio_ftruncate (int fd, off_t offset, eio_cb cb) +eio_req *eio_ftruncate (int fd, off_t offset, int pri, eio_cb cb, void *data) { REQ (EIO_FTRUNCATE); req->int1 = fd; req->offs = offset; SEND; } -eio_req *eio_fchmod (int fd, mode_t mode, eio_cb cb) +eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data) { REQ (EIO_FCHMOD); req->int1 = fd; req->int2 = (long)mode; SEND; } -eio_req *eio_fchown (int fd, uid_t uid, gid_t gid, eio_cb cb) +eio_req *eio_fchown (int fd, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) { REQ (EIO_FCHOWN); req->int1 = fd; req->int2 = (long)uid; req->int3 = (long)gid; SEND; } -eio_req *eio_dup2 (int fd, int fd2, eio_cb cb) +eio_req *eio_dup2 (int fd, int fd2, int pri, eio_cb cb, void *data) { REQ (EIO_DUP2); req->int1 = fd; req->int2 = fd2; SEND; } -eio_req *eio_sendfile (int out_fd, int in_fd, off_t in_offset, size_t length, eio_cb cb) +eio_req *eio_sendfile (int out_fd, int in_fd, off_t in_offset, size_t length, int pri, eio_cb cb, void *data) { REQ (EIO_SENDFILE); req->int1 = out_fd; req->int2 = in_fd; req->offs = in_offset; req->size = length; SEND; } -eio_req *eio_open (const char *path, int flags, mode_t mode, eio_cb cb) +eio_req *eio_open (const char *path, int flags, mode_t mode, int pri, eio_cb cb, void *data) { REQ (EIO_OPEN); PATH; req->int1 = flags; req->int2 = (long)mode; SEND; } -eio_req *eio_utime (const char *path, double atime, double mtime, eio_cb cb) +eio_req *eio_utime (const char *path, double atime, double mtime, int pri, eio_cb cb, void *data) { REQ (EIO_UTIME); PATH; req->nv1 = atime; req->nv2 = mtime; SEND; } -eio_req *eio_truncate (const char *path, off_t offset, eio_cb cb) +eio_req *eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data) { REQ (EIO_TRUNCATE); PATH; req->offs = offset; SEND; } -eio_req *eio_chown (const char *path, uid_t uid, gid_t gid, eio_cb cb) +eio_req *eio_chown (const char *path, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data) { REQ (EIO_CHOWN); PATH; req->int2 = (long)uid; req->int3 = (long)gid; SEND; } -eio_req *eio_chmod (const char *path, mode_t mode, eio_cb cb) +eio_req *eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data) { REQ (EIO_CHMOD); PATH; req->int2 = (long)mode; SEND; } -eio_req *eio_mkdir (const char *path, mode_t mode, eio_cb cb) +eio_req *eio_mkdir (const char *path, mode_t mode, int pri, eio_cb cb, void *data) { REQ (EIO_MKDIR); PATH; req->int2 = (long)mode; SEND; } static eio_req * -eio__1path (int type, const char *path, eio_cb cb) +eio__1path (int type, const char *path, int pri, eio_cb cb, void *data) { REQ (type); PATH; SEND; } -eio_req *eio_readlink (const char *path, eio_cb cb) +eio_req *eio_readlink (const char *path, int pri, eio_cb cb, void *data) { - return eio__1path (EIO_READLINK, path, cb); + return eio__1path (EIO_READLINK, path, pri, cb, data); } -eio_req *eio_stat (const char *path, eio_cb cb) +eio_req *eio_stat (const char *path, int pri, eio_cb cb, void *data) { - return eio__1path (EIO_STAT, path, cb); + return eio__1path (EIO_STAT, path, pri, cb, data); } -eio_req *eio_lstat (const char *path, eio_cb cb) +eio_req *eio_lstat (const char *path, int pri, eio_cb cb, void *data) { - return eio__1path (EIO_LSTAT, path, cb); + return eio__1path (EIO_LSTAT, path, pri, cb, data); } -eio_req *eio_unlink (const char *path, eio_cb cb) +eio_req *eio_unlink (const char *path, int pri, eio_cb cb, void *data) { - return eio__1path (EIO_UNLINK, path, cb); + return eio__1path (EIO_UNLINK, path, pri, cb, data); } -eio_req *eio_rmdir (const char *path, eio_cb cb) +eio_req *eio_rmdir (const char *path, int pri, eio_cb cb, void *data) { - return eio__1path (EIO_RMDIR, path, cb); + return eio__1path (EIO_RMDIR, path, pri, cb, data); } -eio_req *eio_readdir (const char *path, eio_cb cb) +eio_req *eio_readdir (const char *path, int pri, eio_cb cb, void *data) { - return eio__1path (EIO_READDIR, path, cb); + return eio__1path (EIO_READDIR, path, pri, cb, data); } -eio_req *eio_mknod (const char *path, mode_t mode, dev_t dev, eio_cb cb) +eio_req *eio_mknod (const char *path, mode_t mode, dev_t dev, int pri, eio_cb cb, void *data) { REQ (EIO_MKNOD); PATH; req->int2 = (long)mode; req->int2 = (long)dev; SEND; } static eio_req * -eio__2path (int type, const char *path, const char *new_path, eio_cb cb) +eio__2path (int type, const char *path, const char *new_path, int pri, eio_cb cb, void *data) { REQ (type); PATH; @@ -1234,19 +1234,26 @@ eio__2path (int type, const char *path, const char *new_path, eio_cb cb) SEND; } -eio_req *eio_link (const char *path, const char *new_path, eio_cb cb) +eio_req *eio_link (const char *path, const char *new_path, int pri, eio_cb cb, void *data) { - return eio__2path (EIO_LINK, path, new_path, cb); + return eio__2path (EIO_LINK, path, new_path, pri, cb, data); } -eio_req *eio_symlink (const char *path, const char *new_path, eio_cb cb) +eio_req *eio_symlink (const char *path, const char *new_path, int pri, eio_cb cb, void *data) { - return eio__2path (EIO_SYMLINK, path, new_path, cb); + return eio__2path (EIO_SYMLINK, path, new_path, pri, cb, data); } -eio_req *eio_rename (const char *path, const char *new_path, eio_cb cb) +eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data) { - return eio__2path (EIO_RENAME, path, new_path, cb); + return eio__2path (EIO_RENAME, path, new_path, pri, cb, data); +} + +eio_req *eio_grp (eio_cb cb, void *data) +{ + const int pri = EIO_PRI_MAX; + + REQ (EIO_GROUP); SEND; } #undef REQ diff --git a/eio.h b/eio.h index e14c3cd..61133da 100644 --- a/eio.h +++ b/eio.h @@ -78,7 +78,7 @@ enum { EIO_PRI_MIN = -4, EIO_PRI_MAX = 4, - EIO_DEFAULT_PRI = 0, + EIO_PRI_DEFAULT = 0, EIO_PRI_BIAS = -EIO_PRI_MIN, EIO_NUM_PRI = EIO_PRI_MAX + EIO_PRI_BIAS + 1 }; @@ -114,41 +114,41 @@ unsigned int eio_nthreads (void); /* number of worker threads in use currently * /*****************************************************************************/ /* high-level request API */ -eio_req *eio_nop (eio_cb cb); /* does nothing except go through the whole process */ -eio_req *eio_busy (eio_tstamp delay, eio_cb cb); /* ties a thread for this long, simulating busyness */ -eio_req *eio_sync (eio_cb cb); -eio_req *eio_fsync (int fd, eio_cb cb); -eio_req *eio_fdatasync (int fd, eio_cb cb); -eio_req *eio_close (int fd, eio_cb cb); -eio_req *eio_readahead (int fd, off_t offset, size_t length, eio_cb cb); -eio_req *eio_read (int fd, void *data, size_t length, off_t offset, eio_cb cb); -eio_req *eio_write (int fd, void *data, size_t length, off_t offset, eio_cb cb); -eio_req *eio_fstat (int fd, eio_cb cb); /* stat buffer=ptr2 allocated dynamically */ -eio_req *eio_futime (int fd, eio_tstamp atime, eio_tstamp mtime, eio_cb cb); -eio_req *eio_ftruncate (int fd, off_t offset, eio_cb cb); -eio_req *eio_fchmod (int fd, mode_t mode, eio_cb cb); -eio_req *eio_fchown (int fd, uid_t uid, gid_t gid, eio_cb cb); -eio_req *eio_dup2 (int fd, int fd2, eio_cb cb); -eio_req *eio_sendfile (int out_fd, int in_fd, off_t in_offset, size_t length, eio_cb cb); -eio_req *eio_open (const char *path, int flags, mode_t mode, eio_cb cb); -eio_req *eio_utime (const char *path, eio_tstamp atime, eio_tstamp mtime, eio_cb cb); -eio_req *eio_truncate (const char *path, off_t offset, eio_cb cb); -eio_req *eio_chown (const char *path, uid_t uid, gid_t gid, eio_cb cb); -eio_req *eio_chmod (const char *path, mode_t mode, eio_cb cb); -eio_req *eio_mkdir (const char *path, mode_t mode, eio_cb cb); -eio_req *eio_readdir (const char *path, eio_cb cb); /* result=ptr2 allocated dynamically */ -eio_req *eio_rmdir (const char *path, eio_cb cb); -eio_req *eio_unlink (const char *path, eio_cb cb); -eio_req *eio_readlink (const char *path, eio_cb cb); /* result=ptr2 allocated dynamically */ -eio_req *eio_stat (const char *path, eio_cb cb); /* stat buffer=ptr2 allocated dynamically */ -eio_req *eio_lstat (const char *path, eio_cb cb); /* stat buffer=ptr2 allocated dynamically */ -eio_req *eio_mknod (const char *path, mode_t mode, dev_t dev, eio_cb cb); -eio_req *eio_link (const char *path, const char *new_path, eio_cb cb); -eio_req *eio_symlink (const char *path, const char *new_path, eio_cb cb); -eio_req *eio_rename (const char *path, const char *new_path, eio_cb cb); +eio_req *eio_nop (int pri, eio_cb cb, void *data); /* does nothing except go through the whole process */ +eio_req *eio_busy (eio_tstamp delay, int pri, eio_cb cb, void *data); /* ties a thread for this long, simulating busyness */ +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_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); +eio_req *eio_write (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data); +eio_req *eio_fstat (int fd, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ +eio_req *eio_futime (int fd, eio_tstamp atime, eio_tstamp mtime, int pri, eio_cb cb, void *data); +eio_req *eio_ftruncate (int fd, off_t offset, int pri, eio_cb cb, void *data); +eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data); +eio_req *eio_fchown (int fd, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data); +eio_req *eio_dup2 (int fd, int fd2, int pri, eio_cb cb, void *data); +eio_req *eio_sendfile (int out_fd, int in_fd, off_t in_offset, size_t length, int pri, eio_cb cb, void *data); +eio_req *eio_open (const char *path, int flags, mode_t mode, int pri, eio_cb cb, void *data); +eio_req *eio_utime (const char *path, eio_tstamp atime, eio_tstamp mtime, int pri, eio_cb cb, void *data); +eio_req *eio_truncate (const char *path, off_t offset, int pri, eio_cb cb, void *data); +eio_req *eio_chown (const char *path, uid_t uid, gid_t gid, int pri, eio_cb cb, void *data); +eio_req *eio_chmod (const char *path, mode_t mode, int pri, eio_cb cb, void *data); +eio_req *eio_mkdir (const char *path, mode_t mode, int pri, eio_cb cb, void *data); +eio_req *eio_readdir (const char *path, int pri, eio_cb cb, void *data); /* result=ptr2 allocated dynamically */ +eio_req *eio_rmdir (const char *path, int pri, eio_cb cb, void *data); +eio_req *eio_unlink (const char *path, int pri, eio_cb cb, void *data); +eio_req *eio_readlink (const char *path, int pri, eio_cb cb, void *data); /* result=ptr2 allocated dynamically */ +eio_req *eio_stat (const char *path, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ +eio_req *eio_lstat (const char *path, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ +eio_req *eio_mknod (const char *path, mode_t mode, dev_t dev, int pri, eio_cb cb, void *data); +eio_req *eio_link (const char *path, const char *new_path, int pri, eio_cb cb, void *data); +eio_req *eio_symlink (const char *path, const char *new_path, int pri, eio_cb cb, void *data); +eio_req *eio_rename (const char *path, const char *new_path, int pri, eio_cb cb, void *data); /* for groups */ -eio_req *eio_grp (eio_cb cb); +eio_req *eio_grp (eio_cb cb, void *data); void eio_grp_feed (eio_req *grp, void (*feed)(eio_req *req), int limit); void eio_grp_limit (eio_req *grp, int limit); void eio_grp_add (eio_req *grp, eio_req *req); -- cgit v1.2.3