Created
January 20, 2015 13:12
-
-
Save fwalch/a4b19e79f4b48674d118 to your computer and use it in GitHub Desktop.
clang-format on src/nvim/os/job.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/nvim/os/job.c b/src/nvim/os/job.c | |
index 8db5e3c..1db4a0f 100644 | |
--- a/src/nvim/os/job.c | |
+++ b/src/nvim/os/job.c | |
@@ -24,15 +24,15 @@ | |
#define MAX_RUNNING_JOBS 100 | |
#define JOB_BUFFER_SIZE 0xFFFF | |
-#define close_job_stream(job, stream, type) \ | |
- do { \ | |
- if (job->stream) { \ | |
- type##stream_free(job->stream); \ | |
- job->stream = NULL; \ | |
- if (!uv_is_closing((uv_handle_t *)&job->proc_std##stream)) { \ | |
- uv_close((uv_handle_t *)&job->proc_std##stream, close_cb); \ | |
- } \ | |
- } \ | |
+#define close_job_stream(job, stream, type) \ | |
+ do { \ | |
+ if (job->stream) { \ | |
+ type##stream_free(job->stream); \ | |
+ job->stream = NULL; \ | |
+ if (!uv_is_closing((uv_handle_t *)&job->proc_std##stream)) { \ | |
+ uv_close((uv_handle_t *)&job->proc_std##stream, close_cb); \ | |
+ } \ | |
+ } \ | |
} while (0) | |
#define close_job_in(job) close_job_stream(job, in, w) | |
@@ -74,20 +74,18 @@ static uv_timer_t job_stop_timer; | |
// Some helpers shared in this module | |
#ifdef INCLUDE_GENERATED_DECLARATIONS | |
-# include "os/job.c.generated.h" | |
+#include "os/job.c.generated.h" | |
#endif | |
// Callbacks for libuv | |
/// Initializes job control resources | |
-void job_init(void) | |
-{ | |
+void job_init(void) { | |
uv_disable_stdio_inheritance(); | |
uv_timer_init(uv_default_loop(), &job_stop_timer); | |
} | |
/// Releases job control resources and terminates running jobs | |
-void job_teardown(void) | |
-{ | |
+void job_teardown(void) { | |
// Stop all jobs | |
for (int i = 0; i < MAX_RUNNING_JOBS; i++) { | |
Job *job; | |
@@ -119,15 +117,9 @@ void job_teardown(void) | |
/// @param[out] status The job id if the job started successfully, 0 if the job | |
/// table is full, -1 if the program could not be executed. | |
/// @return The job pointer if the job started successfully, NULL otherwise | |
-Job *job_start(char **argv, | |
- void *data, | |
- bool writable, | |
- rstream_cb stdout_cb, | |
- rstream_cb stderr_cb, | |
- job_exit_cb job_exit_cb, | |
- size_t maxmem, | |
- int *status) | |
-{ | |
+Job *job_start(char **argv, void *data, bool writable, rstream_cb stdout_cb, | |
+ rstream_cb stderr_cb, job_exit_cb job_exit_cb, size_t maxmem, | |
+ int *status) { | |
int i; | |
Job *job; | |
@@ -249,12 +241,11 @@ Job *job_start(char **argv, | |
/// | |
/// @param id The job id | |
/// @return the Job instance | |
-Job *job_find(int id) | |
-{ | |
+Job *job_find(int id) { | |
Job *job; | |
- if (id <= 0 || id > MAX_RUNNING_JOBS || !(job = table[id - 1]) | |
- || job->stopped_time) { | |
+ if (id <= 0 || id > MAX_RUNNING_JOBS || !(job = table[id - 1]) || | |
+ job->stopped_time) { | |
return NULL; | |
} | |
@@ -265,8 +256,7 @@ Job *job_find(int id) | |
/// it's guaranteed to succeed(SIGKILL will eventually be sent) | |
/// | |
/// @param job The Job instance | |
-void job_stop(Job *job) | |
-{ | |
+void job_stop(Job *job) { | |
if (job->stopped_time) { | |
return; | |
} | |
@@ -294,8 +284,7 @@ void job_stop(Job *job) | |
/// still running and the `timeout` has expired. Note that this is | |
/// indistinguishable from the process returning -1 by itself. Which | |
/// is possible on some OS. | |
-int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL | |
-{ | |
+int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL { | |
// The default status is -1, which represents a timeout | |
int status = -1; | |
@@ -303,9 +292,9 @@ int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL | |
// chance to get the status. | |
job->refcount++; | |
event_poll_until(ms, | |
- // Until... | |
- got_int || // interrupted by the user | |
- job->refcount == 1); // job exited | |
+ // Until... | |
+ got_int || // interrupted by the user | |
+ job->refcount == 1); // job exited | |
// we'll assume that a user frantically hitting interrupt doesn't like | |
// the current job. Signal that it has to be killed. | |
@@ -342,10 +331,7 @@ int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL | |
/// closed. | |
/// | |
/// @param job The job instance | |
-void job_close_in(Job *job) FUNC_ATTR_NONNULL_ALL | |
-{ | |
- close_job_in(job); | |
-} | |
+void job_close_in(Job *job) FUNC_ATTR_NONNULL_ALL { close_job_in(job); } | |
/// All writes that complete after calling this function will be reported | |
/// to `cb`. | |
@@ -357,8 +343,7 @@ void job_close_in(Job *job) FUNC_ATTR_NONNULL_ALL | |
/// @param job The job instance | |
/// @param cb The function that will be called on write completion or | |
/// failure. It will be called with the job as the `data` argument. | |
-void job_write_cb(Job *job, wstream_cb cb) FUNC_ATTR_NONNULL_ALL | |
-{ | |
+void job_write_cb(Job *job, wstream_cb cb) FUNC_ATTR_NONNULL_ALL { | |
wstream_set_write_cb(job->in, cb, job); | |
} | |
@@ -369,8 +354,7 @@ void job_write_cb(Job *job, wstream_cb cb) FUNC_ATTR_NONNULL_ALL | |
/// @param buffer The buffer which contains the data to be written | |
/// @return true if the write request was successfully sent, false if writing | |
/// to the job stream failed (possibly because the OS buffer is full) | |
-bool job_write(Job *job, WBuffer *buffer) | |
-{ | |
+bool job_write(Job *job, WBuffer *buffer) { | |
return wstream_write(job->in, buffer); | |
} | |
@@ -378,22 +362,15 @@ bool job_write(Job *job, WBuffer *buffer) | |
/// | |
/// @param job A pointer to the job | |
/// @return The job id | |
-int job_id(Job *job) | |
-{ | |
- return job->id; | |
-} | |
+int job_id(Job *job) { return job->id; } | |
/// Get data associated with a job | |
/// | |
/// @param job A pointer to the job | |
/// @return The job data | |
-void *job_data(Job *job) | |
-{ | |
- return job->data; | |
-} | |
+void *job_data(Job *job) { return job->data; } | |
-static void job_exit_callback(Job *job) | |
-{ | |
+static void job_exit_callback(Job *job) { | |
// Free the slot now, 'exit_cb' may want to start another job to replace | |
// this one | |
table[job->id - 1] = NULL; | |
@@ -412,8 +389,7 @@ static void job_exit_callback(Job *job) | |
/// Iterates the table, sending SIGTERM to stopped jobs and SIGKILL to those | |
/// that didn't die from SIGTERM after a while(exit_timeout is 0). | |
-static void job_stop_timer_cb(uv_timer_t *handle) | |
-{ | |
+static void job_stop_timer_cb(uv_timer_t *handle) { | |
Job *job; | |
uint64_t now = os_hrtime(); | |
@@ -436,8 +412,7 @@ static void job_stop_timer_cb(uv_timer_t *handle) | |
} | |
// Wraps the call to std{out,err}_cb and emits a JobExit event if necessary. | |
-static void read_cb(RStream *rstream, void *data, bool eof) | |
-{ | |
+static void read_cb(RStream *rstream, void *data, bool eof) { | |
Job *job = data; | |
if (rstream == job->out) { | |
@@ -454,16 +429,14 @@ static void read_cb(RStream *rstream, void *data, bool eof) | |
} | |
// Emits a JobExit event if both rstreams are closed | |
-static void exit_cb(uv_process_t *proc, int64_t status, int term_signal) | |
-{ | |
+static void exit_cb(uv_process_t *proc, int64_t status, int term_signal) { | |
Job *job = handle_get_job((uv_handle_t *)proc); | |
job->status = (int)status; | |
uv_close((uv_handle_t *)&job->proc, close_cb); | |
} | |
-static void close_cb(uv_handle_t *handle) | |
-{ | |
+static void close_cb(uv_handle_t *handle) { | |
Job *job = handle_get_job(handle); | |
if (handle == (uv_handle_t *)&job->proc) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment