Avoid spinning in a loop
This also helps reduce a lot of noice in strace.
This commit is contained in:
parent
eee873e373
commit
53b717c454
20
ponymap.c
20
ponymap.c
|
@ -312,6 +312,7 @@ struct generator
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool generator_step (struct app_context *ctx);
|
static bool generator_step (struct app_context *ctx);
|
||||||
|
static void on_generator_step_requested (struct app_context *ctx);
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
|
@ -345,6 +346,7 @@ struct app_context
|
||||||
struct target *running_tail; ///< The tail link of `running_targets'
|
struct target *running_tail; ///< The tail link of `running_targets'
|
||||||
|
|
||||||
struct poller poller; ///< Manages polled descriptors
|
struct poller poller; ///< Manages polled descriptors
|
||||||
|
struct poller_idle step_event; ///< Idle event to make more units
|
||||||
bool quitting; ///< User requested quitting
|
bool quitting; ///< User requested quitting
|
||||||
bool polling; ///< The event loop is running
|
bool polling; ///< The event loop is running
|
||||||
};
|
};
|
||||||
|
@ -369,6 +371,10 @@ app_context_init (struct app_context *self)
|
||||||
poller_init (&self->poller);
|
poller_init (&self->poller);
|
||||||
self->quitting = false;
|
self->quitting = false;
|
||||||
self->polling = false;
|
self->polling = false;
|
||||||
|
|
||||||
|
poller_idle_init (&self->step_event, &self->poller);
|
||||||
|
self->step_event.dispatcher = (poller_idle_fn) on_generator_step_requested;
|
||||||
|
self->step_event.user_data = self;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -538,9 +544,9 @@ unit_abort (struct unit *u)
|
||||||
// We're no longer running
|
// We're no longer running
|
||||||
LIST_UNLINK (u->target->running_units, u);
|
LIST_UNLINK (u->target->running_units, u);
|
||||||
|
|
||||||
// We might have made it possible to launch new units
|
// We might have made it possible to launch new units; we cannot run
|
||||||
while (generator_step (u->target->ctx))
|
// the generator right now, though, as we could spin in a long loop
|
||||||
;
|
poller_idle_set (&u->target->ctx->step_event);
|
||||||
|
|
||||||
if (u->success)
|
if (u->success)
|
||||||
{
|
{
|
||||||
|
@ -1607,6 +1613,14 @@ generator_step (struct app_context *ctx)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_generator_step_requested (struct app_context *ctx)
|
||||||
|
{
|
||||||
|
poller_idle_reset (&ctx->step_event);
|
||||||
|
while (generator_step (ctx))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
// --- Signals -----------------------------------------------------------------
|
// --- Signals -----------------------------------------------------------------
|
||||||
|
|
||||||
static int g_signal_pipe[2]; ///< A pipe used to signal... signals
|
static int g_signal_pipe[2]; ///< A pipe used to signal... signals
|
||||||
|
|
Loading…
Reference in New Issue