File: gen_sym.go

package info (click to toggle)
golang-github-jtolds-gls 4.2.1-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 92 kB
  • sloc: makefile: 2
file content (21 lines) | stat: -rw-r--r-- 380 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package gls

import (
	"sync"
)

var (
	keyMtx     sync.Mutex
	keyCounter uint64
)

// ContextKey is a throwaway value you can use as a key to a ContextManager
type ContextKey struct{ id uint64 }

// GenSym will return a brand new, never-before-used ContextKey
func GenSym() ContextKey {
	keyMtx.Lock()
	defer keyMtx.Unlock()
	keyCounter += 1
	return ContextKey{id: keyCounter}
}