diff options
| author | Přemysl Janouch <p.janouch@gmail.com> | 2014-09-23 23:42:35 +0200 | 
|---|---|---|
| committer | Přemysl Janouch <p.janouch@gmail.com> | 2014-09-24 00:11:44 +0200 | 
| commit | 53b717c454e9d853fb924c484ff20fb7ec602e4a (patch) | |
| tree | f162aa1f3e2a60fbcfddbe0a4e544cb8d5c4077f | |
| parent | eee873e373b44fd7fbdfdc67f043205b2d22e155 (diff) | |
| download | ponymap-53b717c454e9d853fb924c484ff20fb7ec602e4a.tar.gz ponymap-53b717c454e9d853fb924c484ff20fb7ec602e4a.tar.xz ponymap-53b717c454e9d853fb924c484ff20fb7ec602e4a.zip | |
Avoid spinning in a loop
This also helps reduce a lot of noice in strace.
| -rw-r--r-- | ponymap.c | 20 | 
1 files changed, 17 insertions, 3 deletions
| @@ -312,6 +312,7 @@ struct generator  };  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 poller poller;               ///< Manages polled descriptors +	struct poller_idle step_event;      ///< Idle event to make more units  	bool quitting;                      ///< User requested quitting  	bool polling;                       ///< The event loop is running  }; @@ -369,6 +371,10 @@ app_context_init (struct app_context *self)  	poller_init (&self->poller);  	self->quitting = 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 @@ -538,9 +544,9 @@ unit_abort (struct unit *u)  	// We're no longer running  	LIST_UNLINK (u->target->running_units, u); -	// We might have made it possible to launch new units -	while (generator_step (u->target->ctx)) -		; +	// We might have made it possible to launch new units; we cannot run +	// the generator right now, though, as we could spin in a long loop +	poller_idle_set (&u->target->ctx->step_event);  	if (u->success)  	{ @@ -1607,6 +1613,14 @@ generator_step (struct app_context *ctx)  	return false;  } +static void +on_generator_step_requested (struct app_context *ctx) +{ +	poller_idle_reset (&ctx->step_event); +	while (generator_step (ctx)) +		; +} +  // --- Signals -----------------------------------------------------------------  static int g_signal_pipe[2];            ///< A pipe used to signal... signals | 
