diff --git a/engine/libtrends.go b/engine/libtrends.go index 24d872502..5ba56d130 100644 --- a/engine/libtrends.go +++ b/engine/libtrends.go @@ -92,7 +92,7 @@ type TrendWithAPIOpts struct { // Trend is the unit matched by filters type Trend struct { - *sync.RWMutex + tMux *sync.RWMutex Tenant string ID string diff --git a/engine/libtrends_test.go b/engine/libtrends_test.go index 00b1a521f..bf00c5f1c 100644 --- a/engine/libtrends_test.go +++ b/engine/libtrends_test.go @@ -32,7 +32,7 @@ func TestTrendGetTrendGrowth(t *testing.T) { t2 := now.Add(-2 * time.Second) t3 := now.Add(-3 * time.Second) trnd1 := &Trend{ - RWMutex: &sync.RWMutex{}, + tMux: new(sync.RWMutex), Tenant: "cgrates.org", ID: "TestTrendGetTrendLabel", RunTimes: []time.Time{t3, t2, t1}, @@ -59,7 +59,8 @@ func TestTrendGetTrendLabel(t *testing.T) { t2 := now.Add(-2 * time.Second) t3 := now.Add(-3 * time.Second) trnd1 := &Trend{ - RWMutex: sync.RWMutex{}, + tMux: new(sync.RWMutex), + Tenant: "cgrates.org", ID: "TestTrendGetTrendLabel", RunTimes: []time.Time{t3, t2, t1}, diff --git a/engine/trends.go b/engine/trends.go index de3d6652e..f4e6b71fc 100644 --- a/engine/trends.go +++ b/engine/trends.go @@ -91,8 +91,8 @@ func (tS *TrendS) computeTrend(tP *TrendProfile) { return } - trend.Lock() - defer trend.Unlock() + trend.tMux.Lock() + defer trend.tMux.Unlock() now := time.Now() var metrics []string