MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_daemon_runtime_service_free

Function cbm_daemon_runtime_service_free

src/daemon/runtime.c:2699–2738  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2697}
2698
2699bool cbm_daemon_runtime_service_free(cbm_daemon_runtime_service_t *service) {
2700 if (!service ||
2701 cbm_daemon_runtime_service_state(service) != CBM_DAEMON_RUNTIME_SERVICE_EXITED) {
2702 return false;
2703 }
2704 if (service->accept_thread_started && !service->accept_thread_joined) {
2705 if (cbm_thread_join(&service->accept_thread) != 0) {
2706 return false;
2707 }
2708 service->accept_thread_joined = true;
2709 }
2710 for (size_t i = 0; i < service->worker_capacity; i++) {
2711 cbm_daemon_runtime_worker_t *worker = &service->workers[i];
2712 if (worker->thread_started) {
2713 if (!atomic_load_explicit(&worker->done, memory_order_acquire) ||
2714 cbm_thread_join(&worker->thread) != 0) {
2715 return false;
2716 }
2717 runtime_worker_reset_after_join(worker);
2718 }
2719 }
2720 cbm_daemon_ipc_listener_close(service->listener);
2721 service->listener = NULL;
2722 if (!runtime_participant_guard_release_complete(&service->owned_participant_guard,
2723 service->shutdown_timeout_ms)) {
2724 /* Preserve the service allocation so the caller can retry or force
2725 * process exit without dropping the only live cleanup handle. */
2726 return false;
2727 }
2728 cbm_daemon_coordinator_free(service->coordinator);
2729 (void)runtime_process_image_reference_release(&service->active_image);
2730 free(service->conflict_log_path);
2731 for (size_t i = 0; i < service->worker_mutexes_initialized; i++) {
2732 cbm_mutex_destroy(&service->workers[i].send_mutex);
2733 }
2734 free(service->workers);
2735 cbm_mutex_destroy(&service->mutex);
2736 free(service);
2737 return true;
2738}
2739
2740bool cbm_daemon_runtime_request_activation_shutdown(
2741 const cbm_daemon_ipc_endpoint_t *endpoint, const cbm_daemon_build_identity_t *identity,

Tested by 5

cli_scope_host_childFunction · 0.68