Skip to content

Commit

Permalink
adding atomics for better utilizations
Browse files Browse the repository at this point in the history
  • Loading branch information
ranlavanet committed Apr 7, 2024
1 parent 586a6e0 commit 3c02f81
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions protocol/lavasession/consumer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ type ConsumerSessionsWithProvider struct {
// whether we already reported this provider this epoch, we can only report one conflict per provider per epoch
conflictFoundAndReported uint32 // 0 == not reported, 1 == reported
stakeSize sdk.Coin // the stake size the provider staked

// blocked provider recovery status if 0 currently not used, if 1 a session has tried resume communication with this provider
// if the provider is not blocked at all this field is irrelevant
blockedAndUsedWithChanceForRecoveryStatus uint32
}

func NewConsumerSessionWithProvider(publicLavaAddress string, pairingEndpoints []*Endpoint, maxCu uint64, epoch uint64, stakeSize sdk.Coin) *ConsumerSessionsWithProvider {
Expand All @@ -138,6 +142,14 @@ func NewConsumerSessionWithProvider(publicLavaAddress string, pairingEndpoints [
}
}

func (cswp *ConsumerSessionsWithProvider) atomicReadBlockedStatus() uint32 {
return atomic.LoadUint32(&cswp.blockedAndUsedWithChanceForRecoveryStatus)
}

func (cswp *ConsumerSessionsWithProvider) atomicWriteBlockedStatus(status uint32) {
atomic.StoreUint32(&cswp.blockedAndUsedWithChanceForRecoveryStatus, status) // we can only set conflict to "reported".
}

func (cswp *ConsumerSessionsWithProvider) atomicReadConflictReported() bool {
return atomic.LoadUint32(&cswp.conflictFoundAndReported) == 1
}
Expand Down

0 comments on commit 3c02f81

Please sign in to comment.