Commit a46ed8ca authored by Denis Bilenko's avatar Denis Bilenko

core: all watchers (except for child) now accept 'priority' argument to contrustructor

parent 8849ab1c
......@@ -405,26 +405,26 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]:
return value
return backend
def io(self, int fd, int events, ref=True):
return io(self, fd, events, ref)
def io(self, int fd, int events, ref=True, priority=None):
return io(self, fd, events, ref, priority)
def timer(self, double after, double repeat=0.0, ref=True):
return timer(self, after, repeat, ref)
def timer(self, double after, double repeat=0.0, ref=True, priority=None):
return timer(self, after, repeat, ref, priority)
def signal(self, int signum, ref=True):
return signal(self, signum, ref)
def signal(self, int signum, ref=True, priority=None):
return signal(self, signum, ref, priority)
def idle(self, ref=True):
return idle(self, ref)
def idle(self, ref=True, priority=None):
return idle(self, ref, priority)
def prepare(self, ref=True):
return prepare(self, ref)
def prepare(self, ref=True, priority=None):
return prepare(self, ref, priority)
def fork(self, ref=True):
return fork(self, ref)
def fork(self, ref=True, priority=None):
return fork(self, ref, priority)
def async(self, ref=True):
return async(self, ref)
def async(self, ref=True, priority=None):
return async(self, ref, priority)
#if EV_CHILD_ENABLE
......@@ -435,14 +435,14 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]:
#endif
def stat(self, bytes path, float interval=0.0, ref=True):
return stat(self, path, interval, ref)
def stat(self, bytes path, float interval=0.0, ref=True, priority=None):
return stat(self, path, interval, ref, priority)
def callback(self):
return callback(self)
def callback(self, priority=None):
return callback(self, priority)
def run_callback(self, func, *args):
cdef callback result = callback(self)
def run_callback(self, func, *args, priority=None):
cdef callback result = callback(self, priority)
result.start(func, *args)
return result
......@@ -617,13 +617,16 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]:
#define INIT(TYPE, ARGS_INITIALIZERS, ARGS) \
def __init__(self, loop loop ARGS_INITIALIZERS, ref=True): \
def __init__(self, loop loop ARGS_INITIALIZERS, ref=True, priority=None): \
libev.ev_##TYPE##_init(&self._watcher, <void *>gevent_callback_##TYPE ARGS) \
self.loop = loop \
if ref: \
self._flags = 0 \
else: \
self._flags = 4
self._flags = 4 \
if priority is not None: \
libev.ev_set_priority(&self._watcher, priority)
cdef public class watcher [object PyGeventWatcherObject, type PyGeventWatcher_Type]:
"""Abstract base class for all the watchers"""
......@@ -670,7 +673,7 @@ cdef public class io(watcher) [object PyGeventIOObject, type PyGeventIO_Type]:
#ifdef _WIN32
def __init__(self, loop loop, long fd, int events, ref=True):
def __init__(self, loop loop, long fd, int events, ref=True, priority=None):
if events & ~(libev.EV__IOFDSET | libev.EV_READ | libev.EV_WRITE):
raise ValueError('illegal event mask: %r' % events)
cdef int vfd = libev.vfd_open(fd)
......@@ -681,10 +684,12 @@ cdef public class io(watcher) [object PyGeventIOObject, type PyGeventIO_Type]:
self._flags = 0
else:
self._flags = 4
if priority is not None:
libev.ev_set_priority(&self._watcher, priority)
#else
def __init__(self, loop loop, int fd, int events, ref=True):
def __init__(self, loop loop, int fd, int events, ref=True, priority=None):
if fd < 0:
raise ValueError('fd must be non-negative: %r' % fd)
if events & ~(libev.EV__IOFDSET | libev.EV_READ | libev.EV_WRITE):
......@@ -695,6 +700,8 @@ cdef public class io(watcher) [object PyGeventIOObject, type PyGeventIO_Type]:
self._flags = 0
else:
self._flags = 4
if priority is not None:
libev.ev_set_priority(&self._watcher, priority)
#endif
......@@ -756,7 +763,7 @@ cdef public class timer(watcher) [object PyGeventTimerObject, type PyGeventTimer
PENDING
def __init__(self, loop loop, double after=0.0, double repeat=0.0, ref=True):
def __init__(self, loop loop, double after=0.0, double repeat=0.0, ref=True, priority=None):
if repeat < 0.0:
raise ValueError("repeat must be positive or zero: %r" % repeat)
libev.ev_timer_init(&self._watcher, <void *>gevent_callback_timer, after, repeat)
......@@ -765,6 +772,8 @@ cdef public class timer(watcher) [object PyGeventTimerObject, type PyGeventTimer
self._flags = 0
else:
self._flags = 4
if priority is not None:
libev.ev_set_priority(&self._watcher, priority)
property at:
......@@ -787,7 +796,7 @@ cdef public class signal(watcher) [object PyGeventSignalObject, type PyGeventSig
WATCHER(signal)
def __init__(self, loop loop, int signalnum, ref=True):
def __init__(self, loop loop, int signalnum, ref=True, priority=None):
if signalnum < 1 or signalnum >= signalmodule.NSIG:
raise ValueError('illegal signal number: %r' % signalnum)
# still possible to crash on one of libev's asserts:
......@@ -801,6 +810,8 @@ cdef public class signal(watcher) [object PyGeventSignalObject, type PyGeventSig
self._flags = 0
else:
self._flags = 4
if priority is not None:
libev.ev_set_priority(&self._watcher, priority)
cdef public class idle(watcher) [object PyGeventIdleObject, type PyGeventIdle_Type]:
......@@ -890,7 +901,7 @@ cdef public class stat(watcher) [object PyGeventStatObject, type PyGeventStat_Ty
WATCHER(stat)
cdef readonly bytes path
def __init__(self, loop loop, bytes path, float interval=0.0, ref=True):
def __init__(self, loop loop, bytes path, float interval=0.0, ref=True, priority=None):
self.path = path
libev.ev_stat_init(&self._watcher, <void *>gevent_callback_stat, <char*>self.path, interval)
self.loop = loop
......@@ -898,6 +909,8 @@ cdef public class stat(watcher) [object PyGeventStatObject, type PyGeventStat_Ty
self._flags = 0
else:
self._flags = 4
if priority is not None:
libev.ev_set_priority(&self._watcher, priority)
property attr:
......
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