From 1e36d2c1418e1cac55f0b39447088955376b69a4 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 10 Nov 2011 13:45:07 +0000 Subject: [PATCH] added QSE_FIO_NOCACHE. map QSE_FIO_SEQUENTIAL and QSE_FIO_RANDOM to some posix_fadvise flags if available --- qse/include/qse/cmn/fio.h | 5 +++-- qse/lib/cmn/fio.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/qse/include/qse/cmn/fio.h b/qse/include/qse/cmn/fio.h index 0b7e5d2a..ce62459f 100644 --- a/qse/include/qse/cmn/fio.h +++ b/qse/include/qse/cmn/fio.h @@ -59,9 +59,10 @@ enum qse_fio_open_flag_t QSE_FIO_NOSHRD = (1 << 24), QSE_FIO_NOSHWR = (1 << 25), - /* for WIN32 only. harmless(no effect) when used on other platforms */ + /* hints to OS. harmless(no effect) when used on unsupported platforms */ QSE_FIO_RANDOM = (1 << 26), /* hint that access be random */ - QSE_FIO_SEQUENTIAL = (1 << 27) /* hint that access is sequential */ + QSE_FIO_SEQUENTIAL = (1 << 27), /* hint that access is sequential */ + QSE_FIO_NOCACHE = (1 << 28) /* no system I/O cache */ }; enum qse_fio_std_t diff --git a/qse/lib/cmn/fio.c b/qse/lib/cmn/fio.c index bd129601..73517305 100644 --- a/qse/lib/cmn/fio.c +++ b/qse/lib/cmn/fio.c @@ -155,6 +155,8 @@ int qse_fio_init ( flag_and_attr |= FILE_FLAG_RANDOM_ACCESS; if (flags & QSE_FIO_SEQUENTIAL) flag_and_attr |= FILE_FLAG_SEQUENTIAL_SCAN; + if (flags & QSE_FIO_NOCACHE) + flag_and_attr |= FILE_FLAG_NO_BUFFERING; handle = CreateFile ( path, desired_access, share_mode, @@ -369,6 +371,20 @@ int qse_fio_init ( if (handle == -1) return -1; + /* set some file access hints */ + #if defined(POSIX_FADV_RANDOM) + if (flags & QSE_FIO_RANDOM) + posix_fadvise (handle, 0, 0, POSIX_FADV_RANDOM); + #endif + #if defined(POSIX_FADV_SEQUENTIAL) + if (flags & QSE_FIO_SEQUENTIAL) + posix_fadvise (handle, 0, 0, POSIX_FADV_SEQUENTIAL); + #endif + #if defined(POSIX_FADV_DONTNEED) + if (flags & QSE_FIO_NOCACHE) + posix_fadvise (handle, 0, 0, POSIX_FADV_DONTNEED); + #endif + #endif if (flags & QSE_FIO_TEXT)