diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-04-18 10:52:08 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-04-18 16:12:00 -0300 |
commit | 9979e9eac94584f3644e1b8bdff3674d0909ce73 (patch) | |
tree | ca01cb264f98ab8d7b0ab736f2c91f161d824228 | |
parent | d59034ea935e03c9b53875b7e157055b40dc9986 (diff) | |
download | rneovim-9979e9eac94584f3644e1b8bdff3674d0909ce73.tar.gz rneovim-9979e9eac94584f3644e1b8bdff3674d0909ce73.tar.bz2 rneovim-9979e9eac94584f3644e1b8bdff3674d0909ce73.zip |
Stop job prepare watcher when there are no jobs
No need to check for job status when no jobs are running
-rw-r--r-- | src/os/job.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/os/job.c b/src/os/job.c index e440ae33c4..94b6f5a203 100644 --- a/src/os/job.c +++ b/src/os/job.c @@ -53,6 +53,7 @@ struct job { }; static Job *table[MAX_RUNNING_JOBS] = {NULL}; +static uint32_t job_count = 0; static uv_prepare_t job_prepare; // Some helpers shared in this module @@ -71,7 +72,6 @@ void job_init() { uv_disable_stdio_inheritance(); uv_prepare_init(uv_default_loop(), &job_prepare); - uv_prepare_start(&job_prepare, job_prepare_cb); } void job_teardown() @@ -195,6 +195,12 @@ int job_start(char **argv, // Save the job to the table table[i] = job; + // Start polling job status if this is the first + if (job_count == 0) { + uv_prepare_start(&job_prepare, job_prepare_cb); + } + job_count++; + return job->id; } @@ -234,13 +240,22 @@ void job_exit_event(Event event) { Job *job = event.data.job; + // Free the slot now, 'exit_cb' may want to start another job to replace + // this one + table[job->id - 1] = NULL; + // Invoke the exit callback job->exit_cb(job, job->data); // Free the job resources - table[job->id - 1] = NULL; shell_free_argv(job->proc_opts.args); free_job(job); + + // Stop polling job status if this was the last + job_count--; + if (job_count == 0) { + uv_prepare_stop(&job_prepare); + } } int job_id(Job *job) |