go-by-test/counter/counter.go

19 lines
216 B
Go
Raw Normal View History

2024-09-21 15:51:58 +00:00
package counter
import "sync"
2024-09-21 15:51:58 +00:00
type Counter struct {
count int
mutex sync.Mutex
2024-09-21 15:51:58 +00:00
}
func (c *Counter) Inc() {
c.mutex.Lock()
defer c.mutex.Unlock()
2024-09-21 15:51:58 +00:00
c.count++
}
func (c *Counter) Value() int {
return c.count
}