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

Unified Diff: client/internal/logdog/butler/bundler/counter.go

Issue 1412063008: logdog: Add bundler library. (Closed) Base URL: https://github.com/luci/luci-go@logdog-review-streamserver
Patch Set: Updated from comments. Created 5 years, 1 month 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
Index: client/internal/logdog/butler/bundler/counter.go
diff --git a/client/internal/logdog/butler/bundler/counter.go b/client/internal/logdog/butler/bundler/counter.go
new file mode 100644
index 0000000000000000000000000000000000000000..48ad25767bb944455648fcf25755430aab4e0880
--- /dev/null
+++ b/client/internal/logdog/butler/bundler/counter.go
@@ -0,0 +1,24 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package bundler
+
+import (
+ "sync/atomic"
+)
+
+// counter is a goroutine-safe monotonically-increasing counter.
+type counter struct {
+ // current is the current counter value.
+ //
+ // It must be the first field in the struct to ensure it's 64-bit aligned
+ // for atomic operations.
+ current int64
+}
+
+func (c *counter) next() int64 {
+ // AddInt64 returns the value + 1, so subtract one to get its previous value
+ // (current counter value).
+ return atomic.AddInt64(&c.current, 1) - 1
+}
« no previous file with comments | « client/internal/logdog/butler/bundler/bundler_test.go ('k') | client/internal/logdog/butler/bundler/data.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698