.
This commit is contained in:
parent
5656565440
commit
16930ed9c1
1 changed files with 111 additions and 0 deletions
111
counter.go
Normal file
111
counter.go
Normal file
|
@ -0,0 +1,111 @@
|
|||
// counter
|
||||
package main
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Counter struct {
|
||||
mu sync.Mutex
|
||||
user int
|
||||
log int
|
||||
rem int
|
||||
err int
|
||||
dup int
|
||||
wg []int
|
||||
}
|
||||
|
||||
func NewCounter() *Counter {
|
||||
return &Counter{
|
||||
user: 0,
|
||||
log: 0,
|
||||
err: 0,
|
||||
rem: 0,
|
||||
dup: 0,
|
||||
wg: make([]int, opts.Concurrent),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Counter) AddUser() {
|
||||
c.mu.Lock()
|
||||
c.user++
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
func (c *Counter) AddDuplicate() {
|
||||
c.mu.Lock()
|
||||
c.dup++
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
func (c *Counter) AddLog(add int) {
|
||||
c.mu.Lock()
|
||||
c.log += add
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
func (c *Counter) AddRem(add int) {
|
||||
c.mu.Lock()
|
||||
c.rem += add
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
func (c *Counter) AddWG(id int) {
|
||||
c.mu.Lock()
|
||||
c.wg[id]++
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
func (c *Counter) AddErr() {
|
||||
c.mu.Lock()
|
||||
c.err++
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
func (c *Counter) RemWG(id int) {
|
||||
c.mu.Lock()
|
||||
c.wg[id]--
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
func (c *Counter) ValUser() (ret int) {
|
||||
c.mu.Lock()
|
||||
ret = c.user
|
||||
c.mu.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Counter) ValDup() (ret int) {
|
||||
c.mu.Lock()
|
||||
ret = c.dup
|
||||
c.mu.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Counter) ValLog() (ret int) {
|
||||
c.mu.Lock()
|
||||
ret = c.log
|
||||
c.mu.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Counter) ValErr() (ret int) {
|
||||
c.mu.Lock()
|
||||
ret = c.err
|
||||
c.mu.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Counter) ValRem() (ret int) {
|
||||
c.mu.Lock()
|
||||
ret = c.rem
|
||||
c.mu.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Counter) ValWG(id int) (ret int) {
|
||||
c.mu.Lock()
|
||||
ret = c.wg[id]
|
||||
c.mu.Unlock()
|
||||
return
|
||||
}
|
Loading…
Add table
Reference in a new issue