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

Source from the content-addressed store, hash-verified

2487}
2488
2489bool cbm_daemon_runtime_service_free(cbm_daemon_runtime_service_t *service) {
2490 if (!service ||
2491 cbm_daemon_runtime_service_state(service) != CBM_DAEMON_RUNTIME_SERVICE_EXITED) {
2492 return false;
2493 }
2494 if (service->accept_thread_started && !service->accept_thread_joined) {
2495 if (cbm_thread_join(&service->accept_thread) != 0) {
2496 return false;
2497 }
2498 service->accept_thread_joined = true;
2499 }
2500 for (size_t i = 0; i < service->worker_capacity; i++) {
2501 cbm_daemon_runtime_worker_t *worker = &service->workers[i];
2502 if (worker->thread_started) {
2503 if (!atomic_load_explicit(&worker->done, memory_order_acquire) ||
2504 cbm_thread_join(&worker->thread) != 0) {
2505 return false;
2506 }
2507 runtime_worker_reset_after_join(worker);
2508 }
2509 }
2510 cbm_daemon_ipc_listener_close(service->listener);
2511 service->listener = NULL;
2512 if (!runtime_participant_guard_release_complete(&service->owned_participant_guard,
2513 service->shutdown_timeout_ms)) {
2514 /* Preserve the service allocation so the caller can retry or force
2515 * process exit without dropping the only live cleanup handle. */
2516 return false;
2517 }
2518 cbm_daemon_coordinator_free(service->coordinator);
2519 (void)runtime_process_image_reference_release(&service->active_image);
2520 free(service->conflict_log_path);
2521 for (size_t i = 0; i < service->worker_mutexes_initialized; i++) {
2522 cbm_mutex_destroy(&service->workers[i].send_mutex);
2523 }
2524 free(service->workers);
2525 cbm_mutex_destroy(&service->mutex);
2526 free(service);
2527 return true;
2528}
2529
2530bool cbm_daemon_runtime_request_activation_shutdown(
2531 const cbm_daemon_ipc_endpoint_t *endpoint, const cbm_daemon_build_identity_t *identity,

Tested by 3