Merge pull request #1405 from boydgreenfield/add_mmap_map_populate

Add mmap map populate
This commit is contained in:
Andreas Rumpf
2014-08-12 19:50:14 +02:00
2 changed files with 12 additions and 2 deletions

View File

@@ -1579,6 +1579,16 @@ var
MSG_OOB* {.importc, header: "<sys/socket.h>".}: cint
## Out-of-band data.
when defined(linux):
var
MAP_POPULATE* {.importc, header: "<sys/mman.h>".}: cint
## Populate (prefault) page tables for a mapping.
else:
var
MAP_POPULATE*: cint = 0
when defined(macosx):
var
MSG_HAVEMORE* {.importc, header: "<sys/socket.h>".}: cint

View File

@@ -54,7 +54,7 @@ proc mapMem*(m: var TMemFile, mode: TFileMode = fmRead,
nil,
mappedSize,
if readonly: PROT_READ else: PROT_READ or PROT_WRITE,
if readonly: MAP_PRIVATE else: MAP_SHARED,
if readonly: (MAP_PRIVATE or MAP_POPULATE) else: (MAP_SHARED or MAP_POPULATE),
m.handle, offset)
if result == cast[pointer](MAP_FAILED):
osError(osLastError())
@@ -207,7 +207,7 @@ proc open*(filename: string, mode: TFileMode = fmRead,
nil,
result.size,
if readonly: PROT_READ else: PROT_READ or PROT_WRITE,
if readonly: MAP_PRIVATE else: MAP_SHARED,
if readonly: (MAP_PRIVATE or MAP_POPULATE) else: (MAP_SHARED or MAP_POPULATE),
result.handle,
offset)