Repository navigation
Expand file tree
/
Copy pathproject_lock.h
More file actions
51 lines (40 loc) · 2.5 KB
/
Copy pathproject_lock.h
File metadata and controls
51 lines (40 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* project_lock.h — Shared daemon/local-CLI project mutation leases. */
#ifndef CBM_DAEMON_PROJECT_LOCK_H
#define CBM_DAEMON_PROJECT_LOCK_H
#include "daemon/ipc.h"
#include "foundation/lock_registry.h"
#include <stdint.h>
typedef struct cbm_project_lock_manager cbm_project_lock_manager_t;
typedef struct cbm_project_lock_lease cbm_project_lock_lease_t;
/* A CLI attempt validates several native lock files before it can publish a
* lease. Windows path/ACL validation can exceed a 100ms scheduling slice. */
static inline uint64_t cbm_project_lock_cli_attempt_deadline(uint64_t now_ms) {
#ifdef _WIN32
const uint64_t timeout_ms = 5000U;
#else
const uint64_t timeout_ms = 100U;
#endif
return now_ms > UINT64_MAX - timeout_ms ? UINT64_MAX : now_ms + timeout_ms;
}
/* Each manager is an independent process-local registry over the endpoint's
* owner-only runtime directory. Separate CBM processes therefore coordinate
* through the same native lock files without sharing memory. */
cbm_project_lock_manager_t *cbm_project_lock_manager_new(const cbm_daemon_ipc_endpoint_t *endpoint);
/* Normal projects hold SH(project-set) + EX(project). "*" holds
* EX(project-set), blocking every named project. Project lock keys are ASCII
* case-folded to cover filename aliases on case-insensitive filesystems. */
cbm_private_file_lock_status_t cbm_project_lock_acquire(cbm_project_lock_manager_t *manager,
const char *project, uint64_t deadline_ms,
const cbm_lock_cancel_token_t *cancel_token,
cbm_project_lock_lease_t **lease_out);
/* One fair, nonblocking attempt for UI/watcher paths. */
cbm_private_file_lock_status_t cbm_project_lock_try_acquire(cbm_project_lock_manager_t *manager,
const char *project,
cbm_project_lock_lease_t **lease_out);
cbm_private_file_lock_status_t cbm_project_lock_lease_release(cbm_project_lock_lease_t **lease_io);
cbm_private_file_lock_status_t cbm_project_lock_request_cancel(cbm_project_lock_manager_t *manager,
cbm_lock_cancel_token_t *token);
/* Refuses teardown while any lease/cleanup state remains. */
cbm_private_file_lock_status_t cbm_project_lock_manager_free(
cbm_project_lock_manager_t **manager_io);
#endif /* CBM_DAEMON_PROJECT_LOCK_H */