mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-12 13:30:26 +00:00
32 lines
560 B
Go
32 lines
560 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
|
|
}{}
|
|
|
|
// Increment the value of hyphae count.
|
|
func IncrementCount() {
|
|
count.Lock()
|
|
count.value++
|
|
count.Unlock()
|
|
}
|
|
|
|
// Decrement the value of hyphae count.
|
|
func DecrementCount() {
|
|
count.Lock()
|
|
count.value--
|
|
count.Unlock()
|
|
}
|
|
|
|
// Count how many hyphae there are.
|
|
func Count() int {
|
|
// it is concurrent-safe to not lock here, right?
|
|
return count.value
|
|
}
|