The open source OpenXR runtime
0
fork

Configure Feed

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

ipc: Share per client thread shutdown code [NFC]

The two paths was already identical, so just make it one.

+57 -58
+57 -58
src/xrt/ipc/server/ipc_server_per_client_thread.c
··· 1 - // Copyright 2020-2021, Collabora, Ltd. 1 + // Copyright 2020-2023, Collabora, Ltd. 2 2 // SPDX-License-Identifier: BSL-1.0 3 3 /*! 4 4 * @file ··· 26 26 #include <sys/epoll.h> 27 27 #include <sys/socket.h> 28 28 29 + #endif // XRT_OS_WINDOWS 30 + 29 31 30 32 /* 31 33 * ··· 33 35 * 34 36 */ 35 37 38 + static void 39 + common_shutdown(volatile struct ipc_client_state *ics) 40 + { 41 + /* 42 + * Remove the thread from the server. 43 + */ 44 + 45 + // Multiple threads might be looking at these fields. 46 + os_mutex_lock(&ics->server->global_state.lock); 47 + 48 + ipc_message_channel_close((struct ipc_message_channel *)&ics->imc); 49 + 50 + ics->server->threads[ics->server_thread_index].state = IPC_THREAD_STOPPING; 51 + ics->server_thread_index = -1; 52 + memset((void *)&ics->client_state, 0, sizeof(struct ipc_app_state)); 53 + 54 + os_mutex_unlock(&ics->server->global_state.lock); 55 + 56 + 57 + /* 58 + * Clean up various resources. 59 + */ 60 + 61 + // If the session hasn't been stopped, destroy the compositor. 62 + ipc_server_client_destroy_compositor(ics); 63 + 64 + // Make sure undestroyed spaces are unreferenced 65 + for (uint32_t i = 0; i < IPC_MAX_CLIENT_SPACES; i++) { 66 + // Cast away volatile. 67 + xrt_space_reference((struct xrt_space **)&ics->xspcs[i], NULL); 68 + } 69 + 70 + // Should we stop the server when a client disconnects? 71 + if (ics->server->exit_on_disconnect) { 72 + ics->server->running = false; 73 + } 74 + 75 + ipc_server_deactivate_session(ics); 76 + } 77 + 78 + 79 + /* 80 + * 81 + * Client loop and per platform helpers. 82 + * 83 + */ 84 + 85 + #ifndef XRT_OS_WINDOWS // Linux & Android 86 + 36 87 static int 37 88 setup_epoll(volatile struct ipc_client_state *ics) 38 89 { ··· 59 110 return epoll_fd; 60 111 } 61 112 62 - 63 - /* 64 - * 65 - * Client loop. 66 - * 67 - */ 68 - 69 113 static void 70 114 client_loop(volatile struct ipc_client_state *ics) 71 115 { ··· 132 176 close(epoll_fd); 133 177 epoll_fd = -1; 134 178 135 - // Multiple threads might be looking at these fields. 136 - os_mutex_lock(&ics->server->global_state.lock); 137 - 138 - ipc_message_channel_close((struct ipc_message_channel *)&ics->imc); 139 - 140 - ics->server->threads[ics->server_thread_index].state = IPC_THREAD_STOPPING; 141 - ics->server_thread_index = -1; 142 - memset((void *)&ics->client_state, 0, sizeof(struct ipc_app_state)); 143 - 144 - os_mutex_unlock(&ics->server->global_state.lock); 145 - 146 - ipc_server_client_destroy_compositor(ics); 147 - 148 - // Make sure undestroyed spaces are unreferenced 149 - for (uint32_t i = 0; i < IPC_MAX_CLIENT_SPACES; i++) { 150 - // Cast away volatile. 151 - xrt_space_reference((struct xrt_space **)&ics->xspcs[i], NULL); 152 - } 153 - 154 - // Should we stop the server when a client disconnects? 155 - if (ics->server->exit_on_disconnect) { 156 - ics->server->running = false; 157 - } 158 - 159 - ipc_server_deactivate_session(ics); 179 + // Following code is same for all platforms. 180 + common_shutdown(ics); 160 181 } 161 182 162 183 #else // XRT_OS_WINDOWS ··· 199 220 } 200 221 } 201 222 202 - // Multiple threads might be looking at these fields. 203 - os_mutex_lock(&ics->server->global_state.lock); 204 - 205 - ipc_message_channel_close((struct ipc_message_channel *)&ics->imc); 206 - 207 - ics->server->threads[ics->server_thread_index].state = IPC_THREAD_STOPPING; 208 - ics->server_thread_index = -1; 209 - memset((void *)&ics->client_state, 0, sizeof(struct ipc_app_state)); 210 - 211 - os_mutex_unlock(&ics->server->global_state.lock); 212 - 213 - ipc_server_client_destroy_compositor(ics); 214 - 215 - // Make sure undestroyed spaces are unreferenced 216 - for (uint32_t i = 0; i < IPC_MAX_CLIENT_SPACES; i++) { 217 - // Cast away volatile. 218 - xrt_space_reference((struct xrt_space **)&ics->xspcs[i], NULL); 219 - } 220 - 221 - // Should we stop the server when a client disconnects? 222 - if (ics->server->exit_on_disconnect) { 223 - ics->server->running = false; 224 - } 225 - 226 - ipc_server_deactivate_session(ics); 223 + // Following code is same for all platforms. 224 + common_shutdown(ics); 227 225 } 228 226 229 227 #endif // XRT_OS_WINDOWS 228 + 230 229 231 230 /* 232 231 *