The open source OpenXR runtime
0
fork

Configure Feed

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

ipc: Re-order process handle functions [NFC]

+81 -82
+81 -82
src/xrt/ipc/server/ipc_server_process.c
··· 388 388 } 389 389 } 390 390 391 - void 392 - ipc_server_handle_failure(struct ipc_server *vs) 393 - { 394 - // Right now handled just the same as a graceful shutdown. 395 - vs->running = false; 396 - } 397 - 398 - void 399 - ipc_server_handle_shutdown_signal(struct ipc_server *vs) 400 - { 401 - vs->running = false; 402 - } 403 - 404 - void 405 - ipc_server_handle_client_connected(struct ipc_server *vs, xrt_ipc_handle_t ipc_handle) 406 - { 407 - volatile struct ipc_client_state *ics = NULL; 408 - int32_t cs_index = -1; 409 - 410 - os_mutex_lock(&vs->global_state.lock); 411 - 412 - // find the next free thread in our array (server_thread_index is -1) 413 - // and have it handle this connection 414 - for (uint32_t i = 0; i < IPC_MAX_CLIENTS; i++) { 415 - volatile struct ipc_client_state *_cs = &vs->threads[i].ics; 416 - if (_cs->server_thread_index < 0) { 417 - ics = _cs; 418 - cs_index = i; 419 - break; 420 - } 421 - } 422 - if (ics == NULL) { 423 - xrt_ipc_handle_close(ipc_handle); 424 - 425 - // Unlock when we are done. 426 - os_mutex_unlock(&vs->global_state.lock); 427 - 428 - U_LOG_E("Max client count reached!"); 429 - return; 430 - } 431 - 432 - struct ipc_thread *it = &vs->threads[cs_index]; 433 - if (it->state != IPC_THREAD_READY && it->state != IPC_THREAD_STOPPING) { 434 - // we should not get here 435 - xrt_ipc_handle_close(ipc_handle); 436 - 437 - // Unlock when we are done. 438 - os_mutex_unlock(&vs->global_state.lock); 439 - 440 - U_LOG_E("Client state management error!"); 441 - return; 442 - } 443 - 444 - if (it->state != IPC_THREAD_READY) { 445 - os_thread_join(&it->thread); 446 - os_thread_destroy(&it->thread); 447 - it->state = IPC_THREAD_READY; 448 - } 449 - 450 - it->state = IPC_THREAD_STARTING; 451 - 452 - // Allocate a new ID, avoid zero. 453 - //! @todo validate ID. 454 - uint32_t id = ++vs->id_generator; 455 - 456 - // Reset everything. 457 - U_ZERO((struct ipc_client_state *)ics); 458 - 459 - // Set state. 460 - ics->client_state.id = id; 461 - ics->imc.ipc_handle = ipc_handle; 462 - ics->server = vs; 463 - ics->server_thread_index = cs_index; 464 - ics->io_active = true; 465 - 466 - os_thread_start(&it->thread, ipc_server_client_thread, (void *)ics); 467 - 468 - // Unlock when we are done. 469 - os_mutex_unlock(&vs->global_state.lock); 470 - } 471 - 472 391 static int 473 392 init_all(struct ipc_server *s, enum u_logging_level log_level) 474 393 { ··· 809 728 * 810 729 */ 811 730 812 - 813 731 xrt_result_t 814 732 ipc_server_get_client_app_state(struct ipc_server *s, uint32_t client_id, struct ipc_app_state *out_ias) 815 733 { ··· 898 816 update_server_state_locked(s); 899 817 900 818 os_mutex_unlock(&s->global_state.lock); 819 + } 820 + 821 + void 822 + ipc_server_handle_failure(struct ipc_server *vs) 823 + { 824 + // Right now handled just the same as a graceful shutdown. 825 + vs->running = false; 826 + } 827 + 828 + void 829 + ipc_server_handle_shutdown_signal(struct ipc_server *vs) 830 + { 831 + vs->running = false; 832 + } 833 + 834 + void 835 + ipc_server_handle_client_connected(struct ipc_server *vs, xrt_ipc_handle_t ipc_handle) 836 + { 837 + volatile struct ipc_client_state *ics = NULL; 838 + int32_t cs_index = -1; 839 + 840 + os_mutex_lock(&vs->global_state.lock); 841 + 842 + // find the next free thread in our array (server_thread_index is -1) 843 + // and have it handle this connection 844 + for (uint32_t i = 0; i < IPC_MAX_CLIENTS; i++) { 845 + volatile struct ipc_client_state *_cs = &vs->threads[i].ics; 846 + if (_cs->server_thread_index < 0) { 847 + ics = _cs; 848 + cs_index = i; 849 + break; 850 + } 851 + } 852 + if (ics == NULL) { 853 + xrt_ipc_handle_close(ipc_handle); 854 + 855 + // Unlock when we are done. 856 + os_mutex_unlock(&vs->global_state.lock); 857 + 858 + U_LOG_E("Max client count reached!"); 859 + return; 860 + } 861 + 862 + struct ipc_thread *it = &vs->threads[cs_index]; 863 + if (it->state != IPC_THREAD_READY && it->state != IPC_THREAD_STOPPING) { 864 + // we should not get here 865 + xrt_ipc_handle_close(ipc_handle); 866 + 867 + // Unlock when we are done. 868 + os_mutex_unlock(&vs->global_state.lock); 869 + 870 + U_LOG_E("Client state management error!"); 871 + return; 872 + } 873 + 874 + if (it->state != IPC_THREAD_READY) { 875 + os_thread_join(&it->thread); 876 + os_thread_destroy(&it->thread); 877 + it->state = IPC_THREAD_READY; 878 + } 879 + 880 + it->state = IPC_THREAD_STARTING; 881 + 882 + // Allocate a new ID, avoid zero. 883 + //! @todo validate ID. 884 + uint32_t id = ++vs->id_generator; 885 + 886 + // Reset everything. 887 + U_ZERO((struct ipc_client_state *)ics); 888 + 889 + // Set state. 890 + ics->client_state.id = id; 891 + ics->imc.ipc_handle = ipc_handle; 892 + ics->server = vs; 893 + ics->server_thread_index = cs_index; 894 + ics->io_active = true; 895 + 896 + os_thread_start(&it->thread, ipc_server_client_thread, (void *)ics); 897 + 898 + // Unlock when we are done. 899 + os_mutex_unlock(&vs->global_state.lock); 901 900 } 902 901 903 902 #ifndef XRT_OS_ANDROID