diff --git a/src/common/libflux/reactor.c b/src/common/libflux/reactor.c index 6af4c57d406d..b9cd516fa4ff 100644 --- a/src/common/libflux/reactor.c +++ b/src/common/libflux/reactor.c @@ -199,6 +199,14 @@ struct flux_watcher_ops * flux_watcher_get_ops (flux_watcher_t *w) return NULL; } +void flux_watcher_set_priority (flux_watcher_t *w, int priority) +{ + if (w) { + if (w->ops->set_priority) + w->ops->set_priority (w, priority); + } +} + void flux_watcher_start (flux_watcher_t *w) { if (w) { @@ -558,6 +566,11 @@ flux_watcher_t *flux_prepare_watcher_create (flux_reactor_t *r, /* Check */ +static void check_set_priority (flux_watcher_t *w, int priority) +{ + ev_set_priority ((ev_check *)w->data, priority); +} + static void check_start (flux_watcher_t *w) { ev_check_start (w->r->loop, (ev_check *)w->data); @@ -576,6 +589,7 @@ static void check_cb (struct ev_loop *loop, ev_check *cw, int revents) } static struct flux_watcher_ops check_watcher = { + .set_priority = check_set_priority, .start = check_start, .stop = check_stop, .destroy = NULL, diff --git a/src/common/libflux/reactor.h b/src/common/libflux/reactor.h index c22c27f90830..69e9ebfef37f 100644 --- a/src/common/libflux/reactor.h +++ b/src/common/libflux/reactor.h @@ -72,6 +72,14 @@ typedef struct flux_watcher flux_watcher_t; typedef void (*flux_watcher_f)(flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg); +/* Set the watcher priority. The range is [-2:2] (default 0). + * Higher priority watchers run first. + * This is a no-op if the underlying watcher doesn't support it. + * If the priority is out of range, the max or min value is set. + * Currently only the check watcher supports it. + */ +void flux_watcher_set_priority (flux_watcher_t *w, int priority); + void flux_watcher_start (flux_watcher_t *w); void flux_watcher_stop (flux_watcher_t *w); void flux_watcher_destroy (flux_watcher_t *w); @@ -160,6 +168,7 @@ void flux_stat_watcher_get_rstat (flux_watcher_t *w, */ struct flux_watcher_ops { + void (*set_priority) (flux_watcher_t *w, int priority); void (*start) (flux_watcher_t *w); void (*stop) (flux_watcher_t *w); void (*destroy) (flux_watcher_t *w);