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:2845–2885  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2843}
2844
2845bool cbm_daemon_runtime_service_free(cbm_daemon_runtime_service_t *service) {
2846 if (!service ||
2847 cbm_daemon_runtime_service_state(service) != CBM_DAEMON_RUNTIME_SERVICE_EXITED) {
2848 return false;
2849 }
2850 if (service->accept_thread_started && !service->accept_thread_joined) {
2851 if (cbm_thread_join(&service->accept_thread) != 0) {
2852 return false;
2853 }
2854 service->accept_thread_joined = true;
2855 }
2856 for (size_t i = 0; i < service->worker_capacity; i++) {
2857 cbm_daemon_runtime_worker_t *worker = &service->workers[i];
2858 if (worker->thread_started) {
2859 if (!atomic_load_explicit(&worker->done, memory_order_acquire) ||
2860 cbm_thread_join(&worker->thread) != 0) {
2861 return false;
2862 }
2863 runtime_worker_reset_after_join(worker);
2864 }
2865 }
2866 cbm_daemon_ipc_listener_close(service->listener);
2867 service->listener = NULL;
2868 if (!runtime_participant_guard_release_complete(&service->owned_participant_guard,
2869 service->shutdown_timeout_ms)) {
2870 /* Preserve the service allocation so the caller can retry or force
2871 * process exit without dropping the only live cleanup handle. */
2872 return false;
2873 }
2874 cbm_daemon_coordinator_free(service->coordinator);
2875 (void)runtime_process_image_reference_release(&service->active_image);
2876 runtime_verified_peer_images_release(service);
2877 free(service->conflict_log_path);
2878 for (size_t i = 0; i < service->worker_mutexes_initialized; i++) {
2879 cbm_mutex_destroy(&service->workers[i].send_mutex);
2880 }
2881 free(service->workers);
2882 cbm_mutex_destroy(&service->mutex);
2883 free(service);
2884 return true;
2885}
2886
2887bool cbm_daemon_runtime_request_activation_shutdown(
2888 const cbm_daemon_ipc_endpoint_t *endpoint, const cbm_daemon_build_identity_t *identity,

Tested by 5

cli_scope_host_childFunction · 0.68