You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
526 B

  1. package pam
  2. import "sync"
  3. var cb struct {
  4. sync.Mutex
  5. m map[int]interface{}
  6. c int
  7. }
  8. func init() {
  9. cb.m = make(map[int]interface{})
  10. }
  11. func cbAdd(v interface{}) int {
  12. cb.Lock()
  13. defer cb.Unlock()
  14. cb.c++
  15. cb.m[cb.c] = v
  16. return cb.c
  17. }
  18. func cbGet(c int) interface{} {
  19. cb.Lock()
  20. defer cb.Unlock()
  21. if v, ok := cb.m[c]; ok {
  22. return v
  23. }
  24. panic("Callback pointer not found")
  25. }
  26. func cbDelete(c int) {
  27. cb.Lock()
  28. defer cb.Unlock()
  29. if _, ok := cb.m[c]; !ok {
  30. panic("Callback pointer not found")
  31. }
  32. delete(cb.m, c)
  33. }