carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package fencerelease
2
3import "sync/atomic"
4
5type token struct {
6 host, incarnation, op, rollback, target string
7 gen uint64
8 live *atomic.Bool
9}
10
11type Token = token
12
13// New is inside hostops' import boundary. The recovery grant calls it only
14// after checking the record, sequence, freeze and exact claim observation.
15func New(host, incarnation string, gen uint64, op, rollback, target string) Token {
16 live := new(atomic.Bool)
17 live.Store(true)
18 return token{host: host, incarnation: incarnation, gen: gen, op: op, rollback: rollback, target: target, live: live}
19}
20func (t token) Consume(host, incarnation string, gen uint64, op, rollback, target string) bool {
21 return t.live != nil && t.host == host && t.incarnation == incarnation && t.gen == gen && t.op == op && t.rollback == rollback && t.target == target && t.live.CompareAndSwap(true, false)
22}
23func (t token) Revoke() {
24 if t.live != nil {
25 t.live.Store(false)
26 }
27}
28