Bug 865387 - Handle the read-ahead flag operation on Linux. r=Yoric

This commit is contained in:
Sankha Narayan Guria 2013-08-26 20:42:31 +05:30
Родитель 2cbe51dca0
Коммит 9b556b8e87
3 изменённых файлов: 23 добавлений и 0 удалений

Просмотреть файл

@ -15,6 +15,10 @@
#include "sys/stat.h"
#endif // defined(XP_UNIX)
#if defined(XP_LINUX)
#include <linux/fadvise.h>
#endif // defined(XP_LINUX)
#if defined(XP_MACOSX)
#include "copyfile.h"
#endif // defined(XP_MACOSX)
@ -320,6 +324,10 @@ static const dom::ConstantSpec gLibcProperties[] =
INT_CONSTANT(AT_SYMLINK_NOFOLLOW),
#endif //defined(AT_SYMLINK_NOFOLLOW)
#if defined(POSIX_FADV_SEQUENTIAL)
INT_CONSTANT(POSIX_FADV_SEQUENTIAL),
#endif //defined(POSIX_FADV_SEQUENTIAL)
// access
#if defined(F_OK)
INT_CONSTANT(F_OK),

Просмотреть файл

@ -447,6 +447,14 @@
/*buf*/ Types.void_t.out_ptr,
/*nbytes*/Types.size_t);
UnixFile.posix_fadvise =
declareFFI("posix_fadvise", ctypes.default_abi,
/*return*/ Types.int,
/*fd*/ Types.fd,
/*offset*/ Types.off_t,
/*len*/ Types.off_t,
/*advise*/ Types.int);
if (OS.Constants.libc._DARWIN_FEATURE_64_BIT_INODE) {
// Special case for MacOS X 10.5+
// Symbol name "readdir" still exists but is used for a

Просмотреть файл

@ -92,6 +92,13 @@
* @throws {OS.File.Error} In case of I/O error.
*/
File.prototype._read = function _read(buffer, nbytes, options) {
// Populate the page cache with data from a file so the subsequent reads
// from that file will not block on disk I/O.
if ((UnixFile.posix_fadvise &&
options.sequential || !("sequential" in options))) {
UnixFile.posix_fadvise(this.fd, 0, nbytes,
OS.Constants.libc.POSIX_FADV_SEQUENTIAL);
}
return throw_on_negative("read",
UnixFile.read(this.fd, buffer, nbytes)
);