diff options
Diffstat (limited to 'callback.go')
-rw-r--r-- | callback.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/callback.go b/callback.go new file mode 100644 index 0000000..f2d7210 --- /dev/null +++ b/callback.go @@ -0,0 +1,30 @@ +package pam + +import "sync" + +var cb struct { + sync.Mutex + m map[int]interface{} + c int +} + +func cbAdd(v interface{}) int { + cb.Lock() + defer cb.Unlock() + if cb.m == nil { + cb.m = make(map[int]interface{}) + } + cb.c++ + cb.m[cb.c] = v + return cb.c +} + +func cbGet(c int) interface{} { + cb.Lock() + defer cb.Unlock() + v := cb.m[c] + if v == nil { + panic("Callback pointer not found") + } + return v +} |