mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-12 05:20:26 +00:00
85c936d94a
'I do as the golint guides'
38 lines
797 B
Go
38 lines
797 B
Go
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
|
|
}{}
|
|
|
|
// ResetCount sets the value of hyphae count to zero. Use when reloading hyphae.
|
|
func ResetCount() {
|
|
count.Lock()
|
|
count.value = 0
|
|
count.Unlock()
|
|
}
|
|
|
|
// IncrementCount increments the value of the hyphae counter. Use when creating new hyphae or loading hyphae from disk.
|
|
func IncrementCount() {
|
|
count.Lock()
|
|
count.value++
|
|
count.Unlock()
|
|
}
|
|
|
|
// DecrementCount decrements 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
|
|
}
|