mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-10-30 19:56:16 +00:00
34 lines
575 B
Go
34 lines
575 B
Go
package hypha
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
type count struct {
|
|
value uint
|
|
sync.Mutex
|
|
}
|
|
|
|
// Count is a global variable. Its value is number of all existing hyphae. Hypha mutators are expected to manipulate the value. It is concurrent-safe.
|
|
var Count = count{}
|
|
|
|
// Increment the value of Count.
|
|
func (c *count) Increment() {
|
|
c.Lock()
|
|
c.value++
|
|
c.Unlock()
|
|
}
|
|
|
|
// Decrement the value of Count.
|
|
func (c *count) Decrement() {
|
|
c.Lock()
|
|
c.value--
|
|
c.Unlock()
|
|
}
|
|
|
|
// Get value of Count.
|
|
func (c *count) Value() uint {
|
|
// it is concurrent-safe to not lock here, right?
|
|
return c.value
|
|
}
|