X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=inline;f=pkg%2Fcontrol%2Ftracker.go;h=9b984a38799c48b36f338efb18a99a1b1c151879;hb=f1d0eb6a82e11f14f60e3636d526299ced0173ea;hp=eddfbdaf0c554eaa12d5867d3b7be24d9e9335a7;hpb=1455c85dea3fba44cdcba8a92864be730691a6ec;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/tracker.go b/pkg/control/tracker.go index eddfbda..9b984a3 100644 --- a/pkg/control/tracker.go +++ b/pkg/control/tracker.go @@ -21,6 +21,7 @@ package control import ( "fmt" + "sync" ) /* @@ -28,6 +29,7 @@ Implements a record of ongoing transactions and helper functions to CRUD the rec */ type Tracker struct { transactionTable map[TransactionKey]Transaction + mutex sync.Mutex } func (t *Tracker) Init() { @@ -39,6 +41,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 { + t.mutex.Lock() + defer t.mutex.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 +58,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} + t.mutex.Lock() + defer t.mutex.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 +75,8 @@ Returns error in case the transaction cannot be found. */ func (t *Tracker) RetriveTransaction(subID uint16, act Action) (Transaction, error) { key := TransactionKey{subID, act} + t.mutex.Lock() + defer t.mutex.Unlock() var xact Transaction if xact, ok := t.transactionTable[key]; ok { return xact, nil @@ -84,6 +92,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 + t.mutex.Lock() + defer t.mutex.Unlock() if xact, ok := t.transactionTable[key]; ok { delete(t.transactionTable, key) return xact, nil