Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Don't use Go 1.10's sync.Map
Browse files Browse the repository at this point in the history
  • Loading branch information
jviide committed May 14, 2018
1 parent 22ba160 commit 56ecb64
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,31 @@ const (
)

var (
registry sync.Map
registry map[*C.struct_nfq_q_handle]*NFQ
lock sync.RWMutex
)

func init() {
registry = make(map[*C.struct_nfq_q_handle]*NFQ)
}

func register(qh *C.struct_nfq_q_handle, nfq *NFQ) {
registry.Store(qh, nfq)
lock.Lock()
registry[qh] = nfq
lock.Unlock()
}

func unregister(qh *C.struct_nfq_q_handle) {
registry.Delete(qh)
lock.Lock()
delete(registry, qh)
lock.Unlock()
}

func get(qh *C.struct_nfq_q_handle) *NFQ {
if nfq, ok := registry.Load(qh); ok {
return nfq.(*NFQ)
}
return nil
lock.RLock()
nfq := registry[qh]
lock.RUnlock()
return nfq
}

// Packet ...
Expand Down

0 comments on commit 56ecb64

Please sign in to comment.