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

Function project_lock_acquire_internal

src/daemon/project_lock.c:109–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107}
108
109static cbm_private_file_lock_status_t project_lock_acquire_internal(
110 cbm_project_lock_manager_t *manager, const char *project, uint64_t deadline_ms,
111 const cbm_lock_cancel_token_t *cancel_token, bool try_once,
112 cbm_project_lock_lease_t **lease_out) {
113 if (lease_out) {
114 *lease_out = NULL;
115 }
116 if (!manager || !manager->registry || !project || !project[0] || !lease_out) {
117 return CBM_PRIVATE_FILE_LOCK_UNSAFE;
118 }
119 bool wildcard = strcmp(project, "*") == 0;
120 char project_key[PROJECT_LOCK_KEY_CAP];
121 if (!wildcard && !project_lock_key(project, project_key)) {
122 return CBM_PRIVATE_FILE_LOCK_UNSAFE;
123 }
124 cbm_project_lock_lease_t *lease = calloc(1, sizeof(*lease));
125 if (!lease) {
126 return CBM_PRIVATE_FILE_LOCK_IO;
127 }
128 cbm_private_file_lock_status_t status =
129 try_once ? cbm_lock_registry_try_acquire(manager->registry, PROJECT_SET_KEY,
130 wildcard ? CBM_PRIVATE_FILE_LOCK_EX
131 : CBM_PRIVATE_FILE_LOCK_SH,
132 &lease->project_set)
133 : cbm_lock_registry_acquire(manager->registry, PROJECT_SET_KEY,
134 wildcard ? CBM_PRIVATE_FILE_LOCK_EX
135 : CBM_PRIVATE_FILE_LOCK_SH,
136 deadline_ms, cancel_token, &lease->project_set);
137 if (status != CBM_PRIVATE_FILE_LOCK_OK) {
138 return project_lock_failed_acquire(lease, status, lease_out);
139 }
140 if (!wildcard) {
141 status = try_once ? cbm_lock_registry_try_acquire(manager->registry, project_key,
142 CBM_PRIVATE_FILE_LOCK_EX, &lease->project)
143 : cbm_lock_registry_acquire(manager->registry, project_key,
144 CBM_PRIVATE_FILE_LOCK_EX, deadline_ms,
145 cancel_token, &lease->project);
146 if (status != CBM_PRIVATE_FILE_LOCK_OK) {
147 return project_lock_failed_acquire(lease, status, lease_out);
148 }
149 }
150 *lease_out = lease;
151 return CBM_PRIVATE_FILE_LOCK_OK;
152}
153
154cbm_private_file_lock_status_t cbm_project_lock_acquire(cbm_project_lock_manager_t *manager,
155 const char *project, uint64_t deadline_ms,

Callers 2

cbm_project_lock_acquireFunction · 0.85

Calls 4

project_lock_keyFunction · 0.85

Tested by

no test coverage detected