-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
55 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package torrent | ||
|
||
import "sync/atomic" | ||
|
||
type counterName int | ||
|
||
// stats | ||
const ( | ||
counterBytesDownloaded counterName = iota | ||
counterBytesUploaded | ||
counterBytesWasted | ||
counterSeededFor // time.Duration | ||
) | ||
|
||
// counters provides concurrent-safe access over set of integers. | ||
type counters [4]int64 | ||
|
||
func newCounters(dl, ul, waste, seed int64) counters { | ||
var c counters | ||
c.Incr(counterBytesDownloaded, dl) | ||
c.Incr(counterBytesUploaded, ul) | ||
c.Incr(counterBytesWasted, waste) | ||
c.Incr(counterSeededFor, seed) | ||
return c | ||
} | ||
|
||
func (c *counters) Incr(name counterName, value int64) { | ||
atomic.AddInt64(&c[name], value) | ||
} | ||
|
||
func (c *counters) Read(name counterName) int64 { | ||
return atomic.LoadInt64(&c[name]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters