modificati i nomi delle funzioni del Counter

This commit is contained in:
Miki 2015-11-27 10:32:58 +01:00
parent 16930ed9c1
commit 4c160678b3
3 changed files with 25 additions and 25 deletions

View file

@ -28,84 +28,84 @@ func NewCounter() *Counter {
func (c *Counter) AddUser() { func (c *Counter) AddUser() {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock()
c.user++ c.user++
c.mu.Unlock()
} }
func (c *Counter) AddDuplicate() { func (c *Counter) AddDuplicate() {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock()
c.dup++ c.dup++
c.mu.Unlock()
} }
func (c *Counter) AddLog(add int) { func (c *Counter) AddLog(add int) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock()
c.log += add c.log += add
c.mu.Unlock()
} }
func (c *Counter) AddRem(add int) { func (c *Counter) AddRem(add int) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock()
c.rem += add c.rem += add
c.mu.Unlock()
} }
func (c *Counter) AddWG(id int) { func (c *Counter) AddWG(id int) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock()
c.wg[id]++ c.wg[id]++
c.mu.Unlock()
} }
func (c *Counter) AddErr() { func (c *Counter) AddErr() {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock()
c.err++ c.err++
c.mu.Unlock()
} }
func (c *Counter) RemWG(id int) { func (c *Counter) DelWG(id int) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock()
c.wg[id]-- c.wg[id]--
c.mu.Unlock()
} }
func (c *Counter) ValUser() (ret int) { func (c *Counter) GetUser() (ret int) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock()
ret = c.user ret = c.user
c.mu.Unlock()
return return
} }
func (c *Counter) ValDup() (ret int) { func (c *Counter) GetDup() (ret int) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock()
ret = c.dup ret = c.dup
c.mu.Unlock()
return return
} }
func (c *Counter) ValLog() (ret int) { func (c *Counter) GetLog() (ret int) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock()
ret = c.log ret = c.log
c.mu.Unlock()
return return
} }
func (c *Counter) ValErr() (ret int) { func (c *Counter) GetErr() (ret int) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock()
ret = c.err ret = c.err
c.mu.Unlock()
return return
} }
func (c *Counter) ValRem() (ret int) { func (c *Counter) GetRem() (ret int) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock()
ret = c.rem ret = c.rem
c.mu.Unlock()
return return
} }
func (c *Counter) ValWG(id int) (ret int) { func (c *Counter) GetWG(id int) (ret int) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock()
ret = c.wg[id] ret = c.wg[id]
c.mu.Unlock()
return return
} }

View file

@ -89,10 +89,10 @@ func main() {
fmt.Println("Waiting WG") fmt.Println("Waiting WG")
for i := 0; i < opts.Concurrent; i++ { for i := 0; i < opts.Concurrent; i++ {
fmt.Printf("ID (%d): %d\n", i, count.ValWG(i)) fmt.Printf("ID (%d): %d\n", i, count.GetWG(i))
} }
wg.Wait() wg.Wait()
fmt.Printf("Stop %v - user: %d - login: %d - errors: %d - rem: %d - duplicate: %d\n\r", time.Since(start), count.ValUser(), count.ValLog(), count.ValErr(), count.ValRem(), count.ValDup()) fmt.Printf("Stop %v - user: %d - login: %d - errors: %d - rem: %d - duplicate: %d\n\r", time.Since(start), count.GetUser(), count.GetLog(), count.GetErr(), count.GetRem(), count.GetDup())
log.Printf("Stop %v - user: %d - login: %d - errors: %d - rem: %d - duplicate: %d\n\r", time.Since(start), count.ValUser(), count.ValLog(), count.ValErr(), count.ValRem(), count.ValDup()) log.Printf("Stop %v - user: %d - login: %d - errors: %d - rem: %d - duplicate: %d\n\r", time.Since(start), count.GetUser(), count.GetLog(), count.GetErr(), count.GetRem(), count.GetDup())
} }

View file

@ -27,7 +27,7 @@ func remover(id int) {
fmt.Printf("SADD (%d): %s\n", id, rem.user) fmt.Printf("SADD (%d): %s\n", id, rem.user)
} }
conn.Send("sadd", "llindex", rem.user) conn.Send("sadd", "llindex", rem.user)
if count.ValErr() >= opts.MaxError { if count.GetErr() >= opts.MaxError {
exit() exit()
} }
} }
@ -38,6 +38,6 @@ func remover(id int) {
fmt.Printf("LREM (%d): %s - %d - %+v\n", id, rem.user, len(rem.logins), time.Since(start)) fmt.Printf("LREM (%d): %s - %d - %+v\n", id, rem.user, len(rem.logins), time.Since(start))
} }
wg.Done() wg.Done()
count.RemWG(id) count.DelWG(id)
} }
} }