diff options
Diffstat (limited to 'identity/identity.go')
-rw-r--r-- | identity/identity.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/identity/identity.go b/identity/identity.go index 7e03120b4..ac3558d16 100644 --- a/identity/identity.go +++ b/identity/identity.go @@ -4,6 +4,7 @@ import ( "path/filepath" "strings" "sync" + "sync/atomic" ) // NewIdentityManager creates a new Manager starting at id. @@ -139,3 +140,18 @@ func (im *identityManager) Search(id Identity) Provider { defer im.Unlock() return im.ids.search(0, id.GetIdentity()) } + +// Incrementer increments and returns the value. +// Typically used for IDs. +type Incrementer interface { + Incr() int +} + +// IncrementByOne implements Incrementer adding 1 every time Incr is called. +type IncrementByOne struct { + counter uint64 +} + +func (c *IncrementByOne) Incr() int { + return int(atomic.AddUint64(&c.counter, uint64(1))) +} |