1/* @ajax/mesh-jobs-lid: the leadership id of the job table (jobs.rs `lid_term`, `lid_next`,
2 * `lease_base`). A lid is the fleet term in its high 24 bits and a count below, so a later
3 * leadership's -- even of the same term (a restarted coordinator, a leader that stepped down and
4 * leads again) -- is always larger, from neither the wall clock nor the start time (review
5 * finding 10). Freestanding. */
6#ifndef MESH_JOBS_LID_H
7#define MESH_JOBS_LID_H
89#include <stdbool.h>
10#include <stdint.h>
1112static inline uint64_t mj_lid_term(uint64_t lid) { return lid >> 40; }
1314/* The lid of a leader of fleet term `term` that knows leaderships up to `seen` (persisted): above
15 * every one of them. False when `seen` is of a later term (this member's view of the fleet is
16 * behind; it must not lead yet) or the term doesn't fit 24 bits. */
17static inline bool mj_lid_next(uint64_t term, uint64_t seen, uint64_t *out) {
18 if (mj_lid_term(seen) > term || term >= (uint64_t)1 << 24) return false;
19 uint64_t a = term << 40, b = seen + 1;
20 *out = a > b ? a : b;
21 return true;
22}
2324/* The first lease id of leadership `lid`: its term and count above 32 bits of lease numbers, so
25 * leases of two leaderships never share an id. */
26static inline uint64_t mj_lease_base(uint64_t lid) { return (mj_lid_term(lid) & 0xffffffu) << 40 | (lid & 0xffu) << 32; }
2728#endif