Bug 686691 - Plumbing to expose OS-level readhead. r=bsmedberg

This commit is contained in:
Taras Glek 2011-10-02 21:24:54 +02:00
Родитель 855486915d
Коммит 612a7be8c8
3 изменённых файлов: 16 добавлений и 3 удалений

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

@ -95,6 +95,7 @@ interface nsILocalFile : nsIFile
*/
attribute boolean followLinks;
const unsigned long OS_READAHEAD = 0x40000000;
const unsigned long DELETE_ON_CLOSE = 0x80000000;
/**
@ -102,9 +103,11 @@ interface nsILocalFile : nsIFile
* responsible for calling PR_Close on the result.
*
* @param flags the PR_Open flags from prio.h, plus optionally
* DELETE_ON_CLOSE. DELETE_ON_CLOSE may be implemented by removing
* the file (by path name) immediately after opening it, so beware
* of possible races; the file should be exclusively owned by this
* OS_READAHEAD or DELETE_ON_CLOSE. OS_READAHEAD is a hint to the
* OS that the file will be read sequentially with agressive
* readahead. DELETE_ON_CLOSE may be implemented by removing the
* file (by path name) immediately after opening it, so beware of
* possible races; the file should be exclusively owned by this
* process.
*/
[noscript] PRFileDescStar openNSPRFileDesc(in long flags, in long mode);

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

@ -88,6 +88,7 @@
#include "prproces.h"
#include "nsIDirectoryEnumerator.h"
#include "nsISimpleEnumerator.h"
#include "private/pprio.h"
#ifdef MOZ_WIDGET_GTK2
#include "nsIGIOService.h"
@ -431,6 +432,11 @@ nsLocalFile::OpenNSPRFileDesc(PRInt32 flags, PRInt32 mode, PRFileDesc **_retval)
PR_Delete(mPath.get());
}
#if defined(LINUX) && !defined(ANDROID)
if (flags & OS_READAHEAD) {
readahead(PR_FileDesc2NativeHandle(*_retval), 0, 0);
}
#endif
return NS_OK;
}

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

@ -398,6 +398,10 @@ OpenFile(const nsAFlatString &name, PRIntn osflags, PRIntn mode,
flag6 |= FILE_FLAG_DELETE_ON_CLOSE;
}
if (osflags && nsILocalFile::OS_READAHEAD) {
flag6 |= FILE_FLAG_SEQUENTIAL_SCAN;
}
HANDLE file = ::CreateFileW(name.get(), access,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, flags, flag6, NULL);