Skip to content

Commit

Permalink
Re-adds syncchronization, needed for the finalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
scottopell committed Oct 23, 2023
1 parent bf48376 commit 04f36b5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions comp/dogstatsd/server/intern.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package server

import (
"runtime"
"sync"
"unsafe"

"github.com/DataDog/datadog-agent/pkg/config/utils"
Expand Down Expand Up @@ -41,6 +42,7 @@ func (v *StringValue) Get() string {
// stringInterner interns strings while allowing them to be cleaned up by the GC.
// It can handle both string and []byte types without allocation.
type stringInterner struct {
mu sync.Mutex
tlmEnabled bool
valMap map[string]uintptr
}
Expand All @@ -66,6 +68,9 @@ func newStringInterner() *stringInterner {
//
//go:nocheckptr
func (s *stringInterner) LoadOrStore(k []byte) *StringValue {
s.mu.Lock()
defer s.mu.Unlock()

var v *StringValue
// the compiler will optimize the following map lookup to not alloc a string
if addr, ok := s.valMap[string(k)]; ok {
Expand All @@ -86,6 +91,8 @@ func (s *stringInterner) LoadOrStore(k []byte) *StringValue {
}

func (s *stringInterner) finalize(v *StringValue) {
s.mu.Lock()
defer s.mu.Unlock()
if v.resurrected {
// We lost the race. Somebody resurrected it while we
// were about to finalize it. Try again next round.
Expand Down

0 comments on commit 04f36b5

Please sign in to comment.