Skip to content

Commit

Permalink
sharedlibraries: Replace atomic.Int32 with regular uint16
Browse files Browse the repository at this point in the history
No need to use atomic operations, as we're protected with a mutex
  • Loading branch information
guyarb committed Dec 4, 2024
1 parent b53f725 commit 1579436
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pkg/network/usm/sharedlibraries/ebpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
"strings"
"sync"

"go.uber.org/atomic"

manager "github.com/DataDog/ebpf-manager"
"golang.org/x/sys/unix"

Expand Down Expand Up @@ -95,7 +93,7 @@ type EbpfProgram struct {

// refcount is the number of times the program has been initialized. It is used to
// stop the program only when the refcount reaches 0.
refcount atomic.Int32
refcount uint16

// initMutex is a mutex to protect the initialization variables and the libset map
wg sync.WaitGroup
Expand Down Expand Up @@ -147,7 +145,7 @@ func GetEBPFProgram(cfg *ddebpf.Config) *EbpfProgram {
}
}

progSingleton.refcount.Inc()
progSingleton.refcount++

return progSingleton
}
Expand Down Expand Up @@ -447,10 +445,13 @@ func (e *EbpfProgram) Stop() {
singletonMutex.Lock()
defer singletonMutex.Unlock()

if e.refcount.Dec() != 0 {
if e.refcount.Load() < 0 {
e.refcount.Swap(0)
}
if e.refcount == 0 {
log.Warn("shared libraries monitor stopping with a refcount of 0")
return
}
e.refcount--
if e.refcount > 0 {
// Still in use
return
}

Expand Down

0 comments on commit 1579436

Please sign in to comment.