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

Source from the content-addressed store, hash-verified

2456}
2457
2458bool cbm_daemon_runtime_service_free(cbm_daemon_runtime_service_t *service) {
2459 if (!service ||
2460 cbm_daemon_runtime_service_state(service) != CBM_DAEMON_RUNTIME_SERVICE_EXITED) {
2461 return false;
2462 }
2463 if (service->accept_thread_started && !service->accept_thread_joined) {
2464 if (cbm_thread_join(&service->accept_thread) != 0) {
2465 return false;
2466 }
2467 service->accept_thread_joined = true;
2468 }
2469 for (size_t i = 0; i < service->worker_capacity; i++) {
2470 cbm_daemon_runtime_worker_t *worker = &service->workers[i];
2471 if (worker->thread_started) {
2472 if (!atomic_load_explicit(&worker->done, memory_order_acquire) ||
2473 cbm_thread_join(&worker->thread) != 0) {
2474 return false;
2475 }
2476 runtime_worker_reset_after_join(worker);
2477 }
2478 }
2479 cbm_daemon_ipc_listener_close(service->listener);
2480 service->listener = NULL;
2481 if (!runtime_participant_guard_release_complete(&service->owned_participant_guard,
2482 service->shutdown_timeout_ms)) {
2483 /* Preserve the service allocation so the caller can retry or force
2484 * process exit without dropping the only live cleanup handle. */
2485 return false;
2486 }
2487 cbm_daemon_coordinator_free(service->coordinator);
2488 (void)runtime_process_image_reference_release(&service->active_image);
2489 free(service->conflict_log_path);
2490 for (size_t i = 0; i < service->worker_mutexes_initialized; i++) {
2491 cbm_mutex_destroy(&service->workers[i].send_mutex);
2492 }
2493 free(service->workers);
2494 cbm_mutex_destroy(&service->mutex);
2495 free(service);
2496 return true;
2497}
2498
2499bool cbm_daemon_runtime_request_activation_shutdown(
2500 const cbm_daemon_ipc_endpoint_t *endpoint, const cbm_daemon_build_identity_t *identity,

Tested by 3