Skip to content

Commit

Permalink
Merge pull request #382 from openziti/add-atomic-value-compare-and-swap
Browse files Browse the repository at this point in the history
Add AtomicValue.StoreAndSwap
  • Loading branch information
plorenz authored Sep 26, 2023
2 parents ab11c7f + a5a03ad commit e1021d9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
5 changes: 5 additions & 0 deletions concurrenz/atomic_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@ func (self *AtomicValue[T]) Load() T {
if val := (*atomic.Value)(self).Load(); val != nil {
result = val.(T)
}

return result
}

func (self *AtomicValue[T]) CompareAndSwap(old, new T) bool {
return (*atomic.Value)(self).CompareAndSwap(old, new)
}
21 changes: 21 additions & 0 deletions concurrenz/atomic_value_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package concurrenz

import (
"github.com/stretchr/testify/require"
"testing"
)

func TestAtomicValue_CompareAndSwap(t *testing.T) {
v := &AtomicValue[string]{}

req := require.New(t)
req.Equal("", v.Load())
v.Store("hello")
req.Equal("hello", v.Load())
req.Equal(false, v.CompareAndSwap("world", "foo"))
req.Equal("hello", v.Load())
req.Equal(true, v.CompareAndSwap("hello", "world"))
req.Equal("world", v.Load())
v.Store("foo")
req.Equal("foo", v.Load())
}
5 changes: 3 additions & 2 deletions concurrenz/wait_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import (
)

// WaitGroup provides a facility to wait for an arbitrarily size collection of notification channels to be completed
// The methods are multi-thread safe, but notifiers added after WaitForDone has been called are not guaranteed
// to be waited for
//
// The methods are multi-thread safe, but notifiers added after WaitForDone has been called are not guaranteed
// to be waited for
type WaitGroup interface {
// AddNotifier adds a notifier to the wait group
AddNotifier(ch <-chan struct{})
Expand Down
1 change: 0 additions & 1 deletion info/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package info
import "time"

// Return the current time in milliseconds.
//
func NowInMilliseconds() int64 {
return time.Now().UnixNano() / 1000000
}
3 changes: 2 additions & 1 deletion term/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func PromptPassword(prompt string, allowEmpty bool) (string, error) {
}

// Prompt will output the given prompt and return the line entered by the user.
// The line will be trimmed of white-space.
//
// The line will be trimmed of white-space.
func Prompt(prompt string) (string, error) {
fmt.Print(prompt)

Expand Down
2 changes: 1 addition & 1 deletion tlz/cipher.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func GetMinTlsVersion() uint16 {
return tls.VersionTLS12
}

//Note: This will only affect TLS1.2 and lower, TLS1.3 has a separate smaller cipher set managed by Go.
// Note: This will only affect TLS1.2 and lower, TLS1.3 has a separate smaller cipher set managed by Go.
func GetCipherSuites() []uint16 {
once.Do(setDefaultCipherSuites)
return defaultCipherSuites
Expand Down

0 comments on commit e1021d9

Please sign in to comment.