The open source OpenXR runtime
0
fork

Configure Feed

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

ipc/server: Factor out start_server_thread function.

+58 -56
+58 -56
src/xrt/ipc/server/ipc_server_process.c
··· 445 445 return 0; 446 446 } 447 447 448 + static void 449 + start_client_listener_thread(struct ipc_server *vs, int fd) 450 + { 451 + volatile struct ipc_client_state *ics = NULL; 452 + int32_t cs_index = -1; 453 + 454 + os_mutex_lock(&vs->global_state_lock); 455 + 456 + // find the next free thread in our array (server_thread_index is -1) 457 + // and have it handle this connection 458 + for (uint32_t i = 0; i < IPC_MAX_CLIENTS; i++) { 459 + volatile struct ipc_client_state *_cs = &vs->threads[i].ics; 460 + if (_cs->server_thread_index < 0) { 461 + ics = _cs; 462 + cs_index = i; 463 + break; 464 + } 465 + } 466 + if (ics == NULL) { 467 + close(fd); 468 + 469 + // Unlock when we are done. 470 + os_mutex_unlock(&vs->global_state_lock); 471 + 472 + U_LOG_E("Max client count reached!"); 473 + return; 474 + } 475 + 476 + struct ipc_thread *it = &vs->threads[cs_index]; 477 + if (it->state != IPC_THREAD_READY && it->state != IPC_THREAD_STOPPING) { 478 + // we should not get here 479 + close(fd); 480 + 481 + // Unlock when we are done. 482 + os_mutex_unlock(&vs->global_state_lock); 483 + 484 + U_LOG_E("Client state management error!"); 485 + return; 486 + } 487 + 488 + if (it->state != IPC_THREAD_READY) { 489 + os_thread_join(&it->thread); 490 + os_thread_destroy(&it->thread); 491 + it->state = IPC_THREAD_READY; 492 + } 493 + 494 + it->state = IPC_THREAD_STARTING; 495 + ics->imc.socket_fd = fd; 496 + ics->server = vs; 497 + ics->server_thread_index = cs_index; 498 + ics->io_active = true; 499 + os_thread_start(&it->thread, ipc_server_client_thread, (void *)ics); 500 + 501 + // Unlock when we are done. 502 + os_mutex_unlock(&vs->global_state_lock); 503 + } 504 + 448 505 static int 449 506 init_all(struct ipc_server *s) 450 507 { ··· 544 601 U_LOG_E("accept '%i'", ret); 545 602 vs->running = false; 546 603 } 547 - 548 - volatile struct ipc_client_state *ics = NULL; 549 - int32_t cs_index = -1; 550 - 551 - // The return is the new fd; 552 - int fd = ret; 553 - 554 - os_mutex_lock(&vs->global_state_lock); 555 - 556 - // find the next free thread in our array (server_thread_index is -1) 557 - // and have it handle this connection 558 - for (uint32_t i = 0; i < IPC_MAX_CLIENTS; i++) { 559 - volatile struct ipc_client_state *_cs = &vs->threads[i].ics; 560 - if (_cs->server_thread_index < 0) { 561 - ics = _cs; 562 - cs_index = i; 563 - break; 564 - } 565 - } 566 - if (ics == NULL) { 567 - close(fd); 568 - 569 - // Unlock when we are done. 570 - os_mutex_unlock(&vs->global_state_lock); 571 - 572 - U_LOG_E("Max client count reached!"); 573 - return; 574 - } 575 - 576 - struct ipc_thread *it = &vs->threads[cs_index]; 577 - if (it->state != IPC_THREAD_READY && it->state != IPC_THREAD_STOPPING) { 578 - // we should not get here 579 - close(fd); 580 - 581 - // Unlock when we are done. 582 - os_mutex_unlock(&vs->global_state_lock); 583 - 584 - U_LOG_E("Client state management error!"); 585 - return; 586 - } 587 - 588 - if (it->state != IPC_THREAD_READY) { 589 - os_thread_join(&it->thread); 590 - os_thread_destroy(&it->thread); 591 - it->state = IPC_THREAD_READY; 592 - } 593 - 594 - it->state = IPC_THREAD_STARTING; 595 - ics->imc.socket_fd = fd; 596 - ics->server = vs; 597 - ics->server_thread_index = cs_index; 598 - ics->io_active = true; 599 - os_thread_start(&it->thread, ipc_server_client_thread, (void *)ics); 600 - 601 - // Unlock when we are done. 602 - os_mutex_unlock(&vs->global_state_lock); 604 + start_client_listener_thread(vs, ret); 603 605 } 604 606 605 607 #define NUM_POLL_EVENTS 8