| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package bundler |
| 6 |
| 7 import ( |
| 8 "sync/atomic" |
| 9 ) |
| 10 |
| 11 // counter is a goroutine-safe monotonically-increasing counter. |
| 12 type counter struct { |
| 13 // current is the current counter value. |
| 14 // |
| 15 // It must be the first field in the struct to ensure it's 64-bit aligne
d |
| 16 // for atomic operations. |
| 17 current int64 |
| 18 } |
| 19 |
| 20 func (c *counter) next() int64 { |
| 21 // AddInt64 returns the value + 1, so subtract one to get its previous v
alue |
| 22 // (current counter value). |
| 23 return atomic.AddInt64(&c.current, 1) - 1 |
| 24 } |
| OLD | NEW |