Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Unified Diff: filter/count/count.go

Issue 1306373002: filter/count: Fix alignment on 32-bit systems. (Closed) Base URL: https://github.com/luci/gae@master
Patch Set: Moar user-friendly. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | filter/count/count_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: filter/count/count.go
diff --git a/filter/count/count.go b/filter/count/count.go
index a5478868128be9bcbb3d29e476ffe816e4f14bf6..2a7b2dd0da85d9eacaaa50d2238c5d2fbf629f36 100644
--- a/filter/count/count.go
+++ b/filter/count/count.go
@@ -9,19 +9,44 @@
package count
import (
+ "fmt"
"sync/atomic"
)
+type counter struct {
+ value int32
+}
+
+func (c *counter) increment() {
+ atomic.AddInt32(&c.value, 1)
+}
+
+func (c *counter) get() int {
+ return int(atomic.LoadInt32(&c.value))
+}
+
// Entry is a success/fail pair for a single API method. It's returned
// by the Counter interface.
type Entry struct {
- Successes int64
- Errors int64
+ successes counter
+ errors counter
+}
+
+func (e *Entry) String() string {
+ return fmt.Sprintf("{Successes:%d, Errors:%d}", e.Successes(), e.Errors())
}
// Total is a convenience function for getting the total number of calls to
// this API. It's Successes+Errors.
-func (e Entry) Total() int64 { return e.Successes + e.Errors }
+func (e *Entry) Total() int64 { return int64(e.Successes()) + int64(e.Errors()) }
+
+func (e *Entry) Successes() int {
+ return e.successes.get()
+}
+
+func (e *Entry) Errors() int {
+ return e.errors.get()
+}
func (e *Entry) up(errs ...error) error {
err := error(nil)
@@ -29,9 +54,9 @@ func (e *Entry) up(errs ...error) error {
err = errs[0]
}
if err == nil {
- atomic.AddInt64(&e.Successes, 1)
+ e.successes.increment()
} else {
- atomic.AddInt64(&e.Errors, 1)
+ e.errors.increment()
}
return err
}
« no previous file with comments | « no previous file | filter/count/count_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698