48#include "xtc_export.h"
55typedef struct xtc_lockmgr xtc_lockmgr_t;
56typedef uint64_t xtc_locker_t;
58typedef enum xtc_lock_mode {
71typedef enum xtc_lock_victim_policy {
72 XTC_LOCK_VICTIM_DEFAULT = 0,
73 XTC_LOCK_VICTIM_RANDOM = 1,
74 XTC_LOCK_VICTIM_OLDEST = 2,
75 XTC_LOCK_VICTIM_YOUNGEST = 3,
76 XTC_LOCK_VICTIM_MIN_LOCKS = 4,
77 XTC_LOCK_VICTIM_MAX_LOCKS = 5,
78 XTC_LOCK_VICTIM_MIN_WRITE = 6,
79 XTC_LOCK_VICTIM_MAX_WRITE = 7,
80 XTC_LOCK_VICTIM_EXPIRE = 8,
81 XTC_LOCK_VICTIM_CUSTOM = 9
82} xtc_lock_victim_policy_t;
91typedef int (*xtc_lock_victim_pick_fn)(
const uint64_t *candidate_lockers,
95typedef enum xtc_lock_detect_mode {
96 XTC_LOCK_DETECT_PERIODIC = 0,
97 XTC_LOCK_DETECT_ON_BLOCK = 1,
98 XTC_LOCK_DETECT_NONE = 2
99} xtc_lock_detect_mode_t;
101typedef struct xtc_lockmgr_opts {
103 int64_t detect_interval_ns;
104 xtc_lock_victim_policy_t victim;
105 xtc_lock_detect_mode_t detect_mode;
109 xtc_lock_victim_pick_fn victim_pick_fn;
110 void *victim_pick_user;
115 const uint8_t *conflicts;
119#define XTC_LOCKMGR_OPTS_DEFAULT { \
120 .n_partitions = 64, \
121 .detect_interval_ns = 100LL * 1000 * 1000, \
122 .victim = XTC_LOCK_VICTIM_DEFAULT, \
123 .detect_mode = XTC_LOCK_DETECT_PERIODIC, \
124 .victim_pick_fn = NULL, \
125 .victim_pick_user = NULL, \
131typedef enum xtc_lock_op {
134 XTC_LOCK_OP_PUT_ALL = 2,
135 XTC_LOCK_OP_UPGRADE = 3,
136 XTC_LOCK_OP_DOWNGRADE = 4
139typedef struct xtc_lock_req {
141 xtc_lock_mode_t mode;
147typedef struct xtc_lockmgr_stat {
154 uint64_t n_deadlocks_found;
181XTC_API
void xtc_lockmgr_destroy(xtc_lockmgr_t *mgr);
183XTC_API
int xtc_lockmgr_id(xtc_lockmgr_t *mgr, xtc_locker_t *out);
184XTC_API
int xtc_lockmgr_id_free(xtc_lockmgr_t *mgr, xtc_locker_t l);
189XTC_API
int xtc_lockmgr_id_set_timeout(xtc_lockmgr_t *mgr, xtc_locker_t l,
204XTC_API
int xtc_lock_get(xtc_lockmgr_t *mgr, xtc_locker_t locker,
205 const void *obj,
size_t obj_size,
206 xtc_lock_mode_t mode, int64_t timeout_ns);
208XTC_API
int xtc_lock_put(xtc_lockmgr_t *mgr, xtc_locker_t locker,
209 const void *obj,
size_t obj_size);
211XTC_API
int xtc_lock_release_all(xtc_lockmgr_t *mgr, xtc_locker_t locker);
226XTC_API
int xtc_lock_upgrade(xtc_lockmgr_t *mgr, xtc_locker_t locker,
227 const void *obj,
size_t obj_size,
228 xtc_lock_mode_t new_mode);
229XTC_API
int xtc_lock_downgrade(xtc_lockmgr_t *mgr, xtc_locker_t locker,
230 const void *obj,
size_t obj_size,
231 xtc_lock_mode_t new_mode);
257XTC_API
int xtc_lock_vec(xtc_lockmgr_t *mgr, xtc_locker_t locker,
260XTC_API
int xtc_lockmgr_check_deadlocks(xtc_lockmgr_t *mgr,
int *n_aborted);
264XTC_API
int xtc_lockmgr_failchk(xtc_lockmgr_t *mgr, xtc_locker_t locker);
267XTC_API
int xtc_lockmgr_n_held(
const xtc_lockmgr_t *mgr);
268XTC_API
int xtc_lockmgr_n_waiting(
const xtc_lockmgr_t *mgr);