fsmonitor--daemon: prepare for adding health thread
Refactor daemon thread startup to make it easier to start a third thread class to monitor the health of the daemon. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
39664e9309
commit
802aa31840
@ -1174,6 +1174,8 @@ static int fsmonitor_run_daemon_1(struct fsmonitor_daemon_state *state)
|
|||||||
*/
|
*/
|
||||||
.uds_disallow_chdir = 0
|
.uds_disallow_chdir = 0
|
||||||
};
|
};
|
||||||
|
int listener_started = 0;
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start the IPC thread pool before the we've started the file
|
* Start the IPC thread pool before the we've started the file
|
||||||
@ -1194,15 +1196,20 @@ static int fsmonitor_run_daemon_1(struct fsmonitor_daemon_state *state)
|
|||||||
if (pthread_create(&state->listener_thread, NULL,
|
if (pthread_create(&state->listener_thread, NULL,
|
||||||
fsm_listen__thread_proc, state) < 0) {
|
fsm_listen__thread_proc, state) < 0) {
|
||||||
ipc_server_stop_async(state->ipc_server_data);
|
ipc_server_stop_async(state->ipc_server_data);
|
||||||
ipc_server_await(state->ipc_server_data);
|
err = error(_("could not start fsmonitor listener thread"));
|
||||||
|
goto cleanup;
|
||||||
return error(_("could not start fsmonitor listener thread"));
|
|
||||||
}
|
}
|
||||||
|
listener_started = 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The daemon is now fully functional in background threads.
|
* The daemon is now fully functional in background threads.
|
||||||
|
* Our primary thread should now just wait while the threads
|
||||||
|
* do all the work.
|
||||||
|
*/
|
||||||
|
cleanup:
|
||||||
|
/*
|
||||||
* Wait for the IPC thread pool to shutdown (whether by client
|
* Wait for the IPC thread pool to shutdown (whether by client
|
||||||
* request or from filesystem activity).
|
* request, from filesystem activity, or an error).
|
||||||
*/
|
*/
|
||||||
ipc_server_await(state->ipc_server_data);
|
ipc_server_await(state->ipc_server_data);
|
||||||
|
|
||||||
@ -1211,10 +1218,16 @@ static int fsmonitor_run_daemon_1(struct fsmonitor_daemon_state *state)
|
|||||||
* event from the IPC thread pool, but it doesn't hurt to tell
|
* event from the IPC thread pool, but it doesn't hurt to tell
|
||||||
* it again. And wait for it to shutdown.
|
* it again. And wait for it to shutdown.
|
||||||
*/
|
*/
|
||||||
fsm_listen__stop_async(state);
|
if (listener_started) {
|
||||||
pthread_join(state->listener_thread, NULL);
|
fsm_listen__stop_async(state);
|
||||||
|
pthread_join(state->listener_thread, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
return state->error_code;
|
if (err)
|
||||||
|
return err;
|
||||||
|
if (state->error_code)
|
||||||
|
return state->error_code;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fsmonitor_run_daemon(void)
|
static int fsmonitor_run_daemon(void)
|
||||||
|
Reference in New Issue
Block a user