47#include "xtc_export.h"
54typedef struct xtc_lockmgr xtc_lockmgr_t;
55typedef uint64_t xtc_locker_t;
57typedef enum xtc_lock_mode {
70typedef enum xtc_lock_victim_policy {
71 XTC_LOCK_VICTIM_DEFAULT = 0,
72 XTC_LOCK_VICTIM_RANDOM = 1,
73 XTC_LOCK_VICTIM_OLDEST = 2,
74 XTC_LOCK_VICTIM_YOUNGEST = 3,
75 XTC_LOCK_VICTIM_MIN_LOCKS = 4,
76 XTC_LOCK_VICTIM_MAX_LOCKS = 5,
77 XTC_LOCK_VICTIM_MIN_WRITE = 6,
78 XTC_LOCK_VICTIM_MAX_WRITE = 7,
79 XTC_LOCK_VICTIM_EXPIRE = 8,
80 XTC_LOCK_VICTIM_CUSTOM = 9
81} xtc_lock_victim_policy_t;
90typedef int (*xtc_lock_victim_pick_fn)(
const uint64_t *candidate_lockers,
94typedef enum xtc_lock_detect_mode {
95 XTC_LOCK_DETECT_PERIODIC = 0,
96 XTC_LOCK_DETECT_ON_BLOCK = 1,
97 XTC_LOCK_DETECT_NONE = 2
98} xtc_lock_detect_mode_t;
100typedef struct xtc_lockmgr_opts {
102 int64_t detect_interval_ns;
103 xtc_lock_victim_policy_t victim;
104 xtc_lock_detect_mode_t detect_mode;
108 xtc_lock_victim_pick_fn victim_pick_fn;
109 void *victim_pick_user;
114 const uint8_t *conflicts;
118#define XTC_LOCKMGR_OPTS_DEFAULT { \
119 .n_partitions = 64, \
120 .detect_interval_ns = 100LL * 1000 * 1000, \
121 .victim = XTC_LOCK_VICTIM_DEFAULT, \
122 .detect_mode = XTC_LOCK_DETECT_PERIODIC, \
123 .victim_pick_fn = NULL, \
124 .victim_pick_user = NULL, \
130typedef enum xtc_lock_op {
133 XTC_LOCK_OP_PUT_ALL = 2,
134 XTC_LOCK_OP_UPGRADE = 3,
135 XTC_LOCK_OP_DOWNGRADE = 4
138typedef struct xtc_lock_req {
140 xtc_lock_mode_t mode;
146typedef struct xtc_lockmgr_stat {
153 uint64_t n_deadlocks_found;
180XTC_API
void xtc_lockmgr_destroy(xtc_lockmgr_t *mgr);
182XTC_API
int xtc_lockmgr_id(xtc_lockmgr_t *mgr, xtc_locker_t *out);
183XTC_API
int xtc_lockmgr_id_free(xtc_lockmgr_t *mgr, xtc_locker_t l);
188XTC_API
int xtc_lockmgr_id_set_timeout(xtc_lockmgr_t *mgr, xtc_locker_t l,
193XTC_API
int xtc_lock_get(xtc_lockmgr_t *mgr, xtc_locker_t locker,
194 const void *obj,
size_t obj_size,
195 xtc_lock_mode_t mode, int64_t timeout_ns);
197XTC_API
int xtc_lock_put(xtc_lockmgr_t *mgr, xtc_locker_t locker,
198 const void *obj,
size_t obj_size);
200XTC_API
int xtc_lock_release_all(xtc_lockmgr_t *mgr, xtc_locker_t locker);
206XTC_API
int xtc_lock_upgrade(xtc_lockmgr_t *mgr, xtc_locker_t locker,
207 const void *obj,
size_t obj_size,
208 xtc_lock_mode_t new_mode);
209XTC_API
int xtc_lock_downgrade(xtc_lockmgr_t *mgr, xtc_locker_t locker,
210 const void *obj,
size_t obj_size,
211 xtc_lock_mode_t new_mode);
218XTC_API
int xtc_lock_vec(xtc_lockmgr_t *mgr, xtc_locker_t locker,
221XTC_API
int xtc_lockmgr_check_deadlocks(xtc_lockmgr_t *mgr,
int *n_aborted);
225XTC_API
int xtc_lockmgr_failchk(xtc_lockmgr_t *mgr, xtc_locker_t locker);
228XTC_API
int xtc_lockmgr_n_held(
const xtc_lockmgr_t *mgr);
229XTC_API
int xtc_lockmgr_n_waiting(
const xtc_lockmgr_t *mgr);