X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Ftracker.go;h=dfab96e55aeb5c4af7b48ed17600e964eab14762;hb=2e99e2f4c89b1c232b3d1765197db44e3cced5b8;hp=eddfbdaf0c554eaa12d5867d3b7be24d9e9335a7;hpb=d9673c002a30e08897f170adf1d66e6ca85c5c6a;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/tracker.go b/pkg/control/tracker.go index eddfbda..dfab96e 100644 --- a/pkg/control/tracker.go +++ b/pkg/control/tracker.go @@ -21,8 +21,11 @@ package control import ( "fmt" + "sync" ) +var trackerMutex = &sync.Mutex{} + /* Implements a record of ongoing transactions and helper functions to CRUD the records. */ @@ -39,6 +42,8 @@ Checks if a tranascation with similar type has been ongoing. If not then creates Returns error if there is similar transatcion ongoing. */ func (t *Tracker) TrackTransaction(key TransactionKey, xact Transaction) error { + trackerMutex.Lock() + defer trackerMutex.Unlock() if _, ok := t.transactionTable[key]; ok { // TODO: Implement merge related check here. If the key is same but the value is different. err := fmt.Errorf("transaction tracker: Similar transaction with sub id %d and type %s is ongoing", key.SubID, key.transType) @@ -54,6 +59,8 @@ Returns error in case the transaction cannot be found. */ func (t *Tracker) UpdateTransaction(SubID uint16, transType Action, xact Transaction) error { key := TransactionKey{SubID, transType} + trackerMutex.Lock() + defer trackerMutex.Unlock() if _, ok := t.transactionTable[key]; ok { // TODO: Implement merge related check here. If the key is same but the value is different. err := fmt.Errorf("transaction tracker: Similar transaction with sub id %d and type %v is ongoing", key.SubID, key.transType) @@ -69,6 +76,8 @@ Returns error in case the transaction cannot be found. */ func (t *Tracker) RetriveTransaction(subID uint16, act Action) (Transaction, error) { key := TransactionKey{subID, act} + trackerMutex.Lock() + defer trackerMutex.Unlock() var xact Transaction if xact, ok := t.transactionTable[key]; ok { return xact, nil @@ -84,6 +93,8 @@ Returns error in case the transaction cannot be found. func (t *Tracker) completeTransaction(subID uint16, act Action) (Transaction, error) { key := TransactionKey{subID, act} var emptyTransaction Transaction + trackerMutex.Lock() + defer trackerMutex.Unlock() if xact, ok := t.transactionTable[key]; ok { delete(t.transactionTable, key) return xact, nil