Skip to content

Commit

Permalink
libflux: add flux_watcher_set_priority()
Browse files Browse the repository at this point in the history
Problem: there is no way to influence the priority of a reactor
watcher.

Add flux_watcher_set_priority() which calls libev's ev_set_priority()
if the watcher supports it (no-op if not).

Implement support for set_priority() in the check watcher.
  • Loading branch information
garlick committed Sep 24, 2024
1 parent 7efc1a0 commit 1932ce5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/common/libflux/reactor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions src/common/libflux/reactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1932ce5

Please sign in to comment.