1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-13 05:50:27 +00:00
mycorrhiza/hyphae/count.go

38 lines
753 B
Go
Raw Normal View History

package hyphae
import (
"sync"
)
// Its value is number of all existing hyphae. Hypha mutators are expected to manipulate the value. It is concurrent-safe.
var count = struct {
value int
sync.Mutex
}{}
2021-02-20 14:03:54 +00:00
// Set the value of hyphae count to zero. Use when reloading hyphae.
func ResetCount() {
2021-02-20 14:03:54 +00:00
count.Lock()
count.value = 0
count.Unlock()
}
2021-02-20 14:03:54 +00:00
// Increment the value of the hyphae counter. Use when creating new hyphae or loading hyphae from disk.
func IncrementCount() {
count.Lock()
count.value++
count.Unlock()
}
2021-02-20 14:03:54 +00:00
// Decrement the value of the hyphae counter. Use when deleting existing hyphae.
func DecrementCount() {
count.Lock()
count.value--
count.Unlock()
}
// Count how many hyphae there are.
func Count() int {
return count.value
}