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
commit bba644fbd1
2 changed files with 12 additions and 2 deletions

View file

@ -1579,6 +1579,16 @@ var
MSG_OOB* {.importc, header: "<sys/socket.h>".}: cint MSG_OOB* {.importc, header: "<sys/socket.h>".}: cint
## Out-of-band data. ## 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): when defined(macosx):
var var
MSG_HAVEMORE* {.importc, header: "<sys/socket.h>".}: cint MSG_HAVEMORE* {.importc, header: "<sys/socket.h>".}: cint

View file

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