Download this file
| 1 | package release |
| 2 | |
| 3 | import "sync" |
| 4 | |
| 5 | var ( |
| 6 | sharedMu sync.Mutex |
| 7 | sharedRatchets = map[string]*DigestRatchet{} |
| 8 | ) |
| 9 | |
| 10 | // SharedDigestRatchet is the process's one ratchet for marks written under |
| 11 | // own (Astra I2 #1): every pass, materialization, held stage and static read |
| 12 | // in this process gets the same object, so a channel remembered after a mark |
| 13 | // could not be persisted stays remembered. require, once on, stays on. |
| 14 | func SharedDigestRatchet(own string, also []string, require bool) *DigestRatchet { |
| 15 | sharedMu.Lock() |
| 16 | defer sharedMu.Unlock() |
| 17 | r, ok := sharedRatchets[own] |
| 18 | if !ok { |
| 19 | r = NewDigestRatchet(own, also, require) |
| 20 | sharedRatchets[own] = r |
| 21 | return r |
| 22 | } |
| 23 | if require { |
| 24 | r.require.Store(true) // atomic: Admit may be reading it right now (Astra I3 #7) |
| 25 | } |
| 26 | return r |
| 27 | } |
| 28 | |