コード例 #1
0
CLOCK_BOOTTIME_ALARM = 9  # Like CLOCK_BOOTTIME but also wakes suspended system.

# From <sys/timerfd.h>

# Bits to be set in the FLAGS parameter of `timerfd_create'.
TFD_CLOEXEC = 02000000,
TFD_NONBLOCK = 04000

# Bits to be set in the FLAGS parameter of `timerfd_settime'.
TFD_TIMER_ABSTIME = 1 << 0

# Return file descriptor for new interval timer source.
#
# extern int timerfd_create (clockid_t __clock_id, int __flags)

timerfd_create = syscall.lookup(c_int, u"timerfd_create", (clockid_t, c_int))

# Set next expiration time of interval timer source UFD to UTMR.  If
# FLAGS has the TFD_TIMER_ABSTIME flag set the timeout value is
# absolute.  Optionally return the old expiration time in OTMR.
#
# extern int timerfd_settime (int __ufd, int __flags,
# 			      __const struct itimerspec *__utmr,
# 			      struct itimerspec *__otmr)
timerfd_settime = syscall.lookup(
    c_int, u"timerfd_settime",
    (c_int, c_int, POINTER(itimerspec), POINTER(itimerspec)))

# Return the next expiration time of UFD.
#
# extern int timerfd_gettime (int __ufd, struct itimerspec *__otmr)
コード例 #2
0
# From <sys/timerfd.h>

# Bits to be set in the FLAGS parameter of `timerfd_create'.
TFD_CLOEXEC = 0o2000000,
TFD_NONBLOCK = 0o4000

# Bits to be set in the FLAGS parameter of `timerfd_settime'.
TFD_TIMER_ABSTIME = 1 << 0



# Return file descriptor for new interval timer source.
#
# extern int timerfd_create (clockid_t __clock_id, int __flags)

timerfd_create = syscall.lookup(c_int, "timerfd_create", (clockid_t, c_int))

# Set next expiration time of interval timer source UFD to UTMR.  If
# FLAGS has the TFD_TIMER_ABSTIME flag set the timeout value is
# absolute.  Optionally return the old expiration time in OTMR.
#
# extern int timerfd_settime (int __ufd, int __flags,
# 			      __const struct itimerspec *__utmr,
# 			      struct itimerspec *__otmr)
timerfd_settime = syscall.lookup(c_int, "timerfd_settime", (c_int, c_int, POINTER(itimerspec), POINTER(itimerspec)))

# Return the next expiration time of UFD.
#
# extern int timerfd_gettime (int __ufd, struct itimerspec *__otmr)

timerfd_gettime = syscall.lookup(c_int, "timerfd_gettime", (c_int, POINTER(itimerspec)))
コード例 #3
0
from ctypes import *
import quick2wire.syscall as syscall
import os
import errno

# From sys/eventfd.h

EFD_SEMAPHORE = 1
EFD_CLOEXEC = 0o2000000
EFD_NONBLOCK = 0o4000

_libc = CDLL(None, use_errno=True)

eventfd_t = c_uint64

eventfd = syscall.lookup(c_int, "eventfd", (c_uint, c_int))


class Semaphore(syscall.SelfClosing):
    """A Semaphore implemented with eventfd that can be added to a Selector."""
    
    def __init__(self, count=0, blocking=True):
        """Creates a Semaphore with an initial count.
        
        Arguments:
        count -- the initial count.
        blocking -- if False calls to wait() do not block if the Semaphore
                    has a count of zero. (default = True)
        """
        self._initial_count = count
        self._flags = EFD_SEMAPHORE|((not blocking)*EFD_NONBLOCK)
コード例 #4
0
from ctypes import *
import quick2wire.syscall as syscall
import os
import errno

# From sys/eventfd.h

EFD_SEMAPHORE = 1
EFD_CLOEXEC = 0o2000000
EFD_NONBLOCK = 0o4000

_libc = CDLL(None, use_errno=True)

eventfd_t = c_uint64

eventfd = syscall.lookup(c_int, "eventfd", (c_uint, c_int))


class Semaphore(syscall.SelfClosing):
    """A Semaphore implemented with eventfd that can be added to a Selector."""
    
    def __init__(self, count=0, blocking=True):
        """Creates a Semaphore with an initial count.
        
        Arguments:
        count -- the initial count.
        blocking -- if False calls to wait() do not block if the Semaphore
                    has a count of zero. (default = True)
        """
        self._fd = eventfd(count, EFD_SEMAPHORE|((not blocking)*EFD_NONBLOCK))