The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ipc: allow runtime exit on no client connections

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2462>

authored by

Bones and committed by
Marge Bot
fd228f1e 67545a9a

+21
+6
src/xrt/ipc/server/ipc_server.h
··· 368 368 // Should we exit when a client disconnects. 369 369 bool exit_on_disconnect; 370 370 371 + // Should we exit when no clients are connected. 372 + bool exit_when_idle; 373 + 371 374 enum u_logging_level log_level; 372 375 373 376 struct ipc_thread threads[IPC_MAX_CLIENTS]; ··· 381 384 { 382 385 int active_client_index; 383 386 int last_active_client_index; 387 + 388 + // Counter for total number of connected clients 389 + uint32_t connected_client_count; 384 390 385 391 struct os_mutex lock; 386 392 } global_state;
+8
src/xrt/ipc/server/ipc_server_per_client_thread.c
··· 51 51 ics->server_thread_index = -1; 52 52 memset((void *)&ics->client_state, 0, sizeof(struct ipc_app_state)); 53 53 54 + // Decrement the connected client counter 55 + ics->server->global_state.connected_client_count--; 56 + 54 57 os_mutex_unlock(&ics->server->global_state.lock); 55 58 56 59 ··· 114 117 115 118 // Should we stop the server when a client disconnects? 116 119 if (ics->server->exit_on_disconnect) { 120 + ics->server->running = false; 121 + } 122 + 123 + // Should we stop the server when all clients disconnect? 124 + if (ics->server->exit_when_idle && ics->server->global_state.connected_client_count == 0) { 117 125 ics->server->running = false; 118 126 } 119 127
+7
src/xrt/ipc/server/ipc_server_process.c
··· 56 56 */ 57 57 58 58 DEBUG_GET_ONCE_BOOL_OPTION(exit_on_disconnect, "IPC_EXIT_ON_DISCONNECT", false) 59 + DEBUG_GET_ONCE_BOOL_OPTION(exit_when_idle, "IPC_EXIT_ON_IDLE", false) 59 60 DEBUG_GET_ONCE_LOG_OPTION(ipc_log, "IPC_LOG", U_LOGGING_INFO) 60 61 61 62 ··· 453 454 454 455 s->global_state.active_client_index = -1; // we start off with no active client. 455 456 s->global_state.last_active_client_index = -1; 457 + s->global_state.connected_client_count = 0; // No clients connected initially 456 458 s->current_slot_index = 0; 457 459 458 460 for (uint32_t i = 0; i < IPC_MAX_CLIENTS; i++) { ··· 490 492 // Yes we should be running. 491 493 s->running = true; 492 494 s->exit_on_disconnect = debug_get_bool_option_exit_on_disconnect(); 495 + s->exit_when_idle = debug_get_bool_option_exit_when_idle(); 493 496 494 497 xret = xrt_instance_create(NULL, &s->xinst); 495 498 if (xret != XRT_SUCCESS) { ··· 539 542 u_var_add_root(s, "IPC Server", false); 540 543 u_var_add_log_level(s, &s->log_level, "Log level"); 541 544 u_var_add_bool(s, &s->exit_on_disconnect, "exit_on_disconnect"); 545 + u_var_add_bool(s, &s->exit_when_idle, "exit_when_idle"); 542 546 u_var_add_bool(s, (bool *)&s->running, "running"); 543 547 544 548 return 0; ··· 912 916 int32_t cs_index = -1; 913 917 914 918 os_mutex_lock(&vs->global_state.lock); 919 + 920 + // Increment the connected client counter 921 + vs->global_state.connected_client_count++; 915 922 916 923 // find the next free thread in our array (server_thread_index is -1) 917 924 // and have it handle this connection