aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/mlockall/mlockall.pyx
blob: b35d661a4247b913b0f70186783ed95717475f76 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cdef extern from "<util/system/error.h>":
    int LastSystemError()

cdef extern from "<util/system/mlock.h>":
    cdef enum ELockAllMemoryFlag:
        LockCurrentMemory
        LockFutureMemory
    cppclass ELockAllMemoryFlags:
        operator=(ELockAllMemoryFlag)
    void LockAllMemory(ELockAllMemoryFlags flags) except+

def mlockall_current():
    cdef ELockAllMemoryFlags flags
    try:
        flags = LockCurrentMemory
        LockAllMemory(flags)
        return 0
    except Exception:
        return LastSystemError()