Skip to content

Commit

Permalink
Using same mutex for condition variable
Browse files Browse the repository at this point in the history
Signed-off-by: pmahindrakar-oss <[email protected]>
  • Loading branch information
pmahindrakar-oss committed May 23, 2024
1 parent e7714c7 commit e30846e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions flyteidl/clients/go/admin/cache/token_cache_inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func (t *TokenCacheInMemoryProvider) GetToken() (*oauth2.Token, error) {
}

func (t *TokenCacheInMemoryProvider) PurgeIfEquals(existing *oauth2.Token) (bool, error) {
return t.token.CompareAndSwap(existing, nil), nil
// Add an empty token since we can't mark it nil using Compare and swap
return t.token.CompareAndSwap(existing, &oauth2.Token{}), nil
}

func (t *TokenCacheInMemoryProvider) Lock() {
Expand All @@ -55,9 +56,10 @@ func (t *TokenCacheInMemoryProvider) CondBroadcast() {
}

func NewTokenCacheInMemoryProvider() *TokenCacheInMemoryProvider {
condMutex := &sync.Mutex{}
return &TokenCacheInMemoryProvider{
mu: &sync.Mutex{},
mu: condMutex,
token: atomic.Value{},
cond: sync.NewCond(&sync.Mutex{}),
cond: sync.NewCond(condMutex),
}
}

0 comments on commit e30846e

Please sign in to comment.