Download this file
| 1 | package fencerelease |
| 2 | |
| 3 | import "sync/atomic" |
| 4 | |
| 5 | type token struct { |
| 6 | host, incarnation, op, rollback, target string |
| 7 | gen uint64 |
| 8 | live *atomic.Bool |
| 9 | } |
| 10 | |
| 11 | type 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. |
| 15 | func 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 | } |
| 20 | func (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 | } |
| 23 | func (t token) Revoke() { |
| 24 | if t.live != nil { |
| 25 | t.live.Store(false) |
| 26 | } |
| 27 | } |
| 28 | |