Revision 5fe4a65b lib/utils/mlock.py
b/lib/utils/mlock.py | ||
---|---|---|
34 | 34 |
ctypes = None |
35 | 35 |
|
36 | 36 |
|
37 |
# Flags for mlockall() (from bits/mman.h) |
|
37 |
# Flags for mlockall(2) (from bits/mman.h)
|
|
38 | 38 |
_MCL_CURRENT = 1 |
39 | 39 |
_MCL_FUTURE = 2 |
40 | 40 |
|
... | ... | |
42 | 42 |
def Mlockall(_ctypes=ctypes): |
43 | 43 |
"""Lock current process' virtual address space into RAM. |
44 | 44 |
|
45 |
This is equivalent to the C call mlockall(MCL_CURRENT|MCL_FUTURE),
|
|
46 |
see mlock(2) for more details. This function requires ctypes module.
|
|
45 |
This is equivalent to the C call C{mlockall(MCL_CURRENT | MCL_FUTURE)}. See
|
|
46 |
mlockall(2) for more details. This function requires the C{ctypes} module.
|
|
47 | 47 |
|
48 |
@raises errors.NoCtypesError: if ctypes module is not found
|
|
48 |
@raises errors.NoCtypesError: If the C{ctypes} module is not found
|
|
49 | 49 |
|
50 | 50 |
""" |
51 | 51 |
if _ctypes is None: |
... | ... | |
60 | 60 |
logging.error("Cannot set memory lock, ctypes cannot load libc") |
61 | 61 |
return |
62 | 62 |
|
63 |
# Some older version of the ctypes module don't have built-in functionality
|
|
64 |
# to access the errno global variable, where function error codes are stored.
|
|
65 |
# By declaring this variable as a pointer to an integer we can then access
|
|
66 |
# its value correctly, should the mlockall call fail, in order to see what
|
|
67 |
# the actual error code was.
|
|
63 |
# The ctypes module before Python 2.6 does not have built-in functionality to
|
|
64 |
# access the global errno global (which, depending on the libc and build
|
|
65 |
# options, is per thread), where function error codes are stored. Use GNU
|
|
66 |
# libc's way to retrieve errno(3) instead, which is to use the pointer named
|
|
67 |
# "__errno_location" (see errno.h and bits/errno.h).
|
|
68 | 68 |
# pylint: disable=W0212 |
69 | 69 |
libc.__errno_location.restype = _ctypes.POINTER(_ctypes.c_int) |
70 | 70 |
|
Also available in: Unified diff