00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "defs.h"
00022
00023
00024
00025
00026 #ifdef DARWIN
00027 int main(void)
00028 {
00029 printf("DARWIN doesn't support AIO.\n");
00030 exit(EXIT_SUCCESS);
00031 }
00032 #else
00033 #include <aio.h>
00034
00035 #define PATH "/aup/c3/datafile.txt"
00036 #define FREQ 8000
00037
00038 static void synchronous(void)
00039 {
00040 int fd, count = 0;
00041 ssize_t nread;
00042 char buf1[512], buf2[512];
00043
00044 ec_neg1( fd = open(PATH, O_RDONLY) )
00045 timestart();
00046 while (true) {
00047 ec_neg1( nread = read(fd, buf1, sizeof(buf1)) )
00048 if (nread == 0)
00049 break;
00050 if (count % FREQ == 0)
00051 ec_neg1( read(STDIN_FILENO, buf2, sizeof(buf2)) )
00052 count++;
00053 }
00054 timestop("synchronous");
00055 printf("read %d blocks\n", count);
00056 return;
00057
00058 EC_CLEANUP_BGN
00059 EC_FLUSH("synchronous")
00060 EC_CLEANUP_END
00061 }
00062
00063 static void asynchronous(void)
00064 {
00065 int fd, count = 0;
00066 ssize_t nread;
00067 char buf1[512], buf2[512];
00068 struct aiocb cb;
00069 const struct aiocb *list[1] = { &cb };
00070
00071 memset(&cb, 0, sizeof(cb));
00072 cb.aio_fildes = STDIN_FILENO;
00073 cb.aio_buf = buf2;
00074 cb.aio_nbytes = sizeof(buf2);
00075 cb.aio_sigevent.sigev_notify = SIGEV_NONE;
00076 ec_neg1( fd = open(PATH, O_RDONLY) )
00077 timestart();
00078 while (true) {
00079 ec_neg1( nread = read(fd, buf1, sizeof(buf1)) )
00080 if (nread == 0)
00081 break;
00082 if (count % FREQ == 0) {
00083 if (count > 1) {
00084 ec_neg1( aio_suspend(list, 1, NULL) )
00085 ec_rv( aio_error(&cb) )
00086 }
00087 ec_neg1( aio_read(&cb) )
00088 }
00089 count++;
00090 }
00091 timestop("asynchronous");
00092 printf("read %d blocks\n", count);
00093 return;
00094
00095 EC_CLEANUP_BGN
00096 EC_FLUSH("asynchronous")
00097 EC_CLEANUP_END
00098 }
00099
00100 int main(void)
00101 {
00102 synchronous();
00103 asynchronous();
00104 exit(EXIT_SUCCESS);
00105 }
00106
00107 #endif