Commit 9c719e4c authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent bc40f44e
......@@ -79,6 +79,8 @@ def lock(const unsigned char[::1] mem not None, int flags):
if err:
PyErr_SetFromErrno(OSError)
return # ok
# unlock unlocks mem pages from being pinned in RAM.
def unlock(const unsigned char[::1] mem not None):
......@@ -89,6 +91,8 @@ def unlock(const unsigned char[::1] mem not None):
if err:
PyErr_SetFromErrno(OSError)
return # ok
from posix.types cimport off_t
......@@ -102,6 +106,16 @@ def map_ro(int fd, off_t offset, size_t size):
return <unsigned char[:size:1]>addr
# map_into mmaps fd[offset:...] into mem's memory.
def map_into_ro(unsigned char[::1] mem not None, int fd, off_t offset):
cdef void *addr = &mem[0]
cdef size_t size = mem.shape[0]
addr = mman.mmap(addr, size, mman.PROT_READ, mman.MAP_SHARED | mman.MAP_FIXED, fd, offset)
if addr == mman.MAP_FAILED:
PyErr_SetFromErrno(OSError)
return # ok
# unmap unmaps memory covered by mem.
def unmap(const unsigned char[::1] mem not None):
......@@ -111,7 +125,8 @@ def unmap(const unsigned char[::1] mem not None):
cdef err = mman.munmap(<void *>addr, size)
if err:
PyErr_SetFromErrno(OSError)
# ok
return # ok
# advise advises kernel about use of mem's memory.
......@@ -125,3 +140,5 @@ def advise(const unsigned char[::1] mem not None, int advice):
cdef err = mman.posix_madvise(<void *>addr, size, advice)
if err:
PyErr_SetFromErrno(OSError)
return # ok
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment