-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented allocation & permission refresh Implemented permissions Implemented channel binding Threa-safety improvements Optimized inbound packet demuxing Resolves #74
- Loading branch information
Showing
22 changed files
with
2,078 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package client | ||
|
||
import ( | ||
"sync/atomic" | ||
) | ||
|
||
// AtomicBool is an atomic boolean struct | ||
type AtomicBool struct { | ||
n int32 | ||
} | ||
|
||
// NewAtomicBool creates a new instance of AtomicBool | ||
func NewAtomicBool(initiallyTrue bool) *AtomicBool { | ||
var n int32 | ||
if initiallyTrue { | ||
n = 1 | ||
} | ||
return &AtomicBool{n: n} | ||
} | ||
|
||
// SetToTrue sets this value to true | ||
func (b *AtomicBool) SetToTrue() { | ||
atomic.StoreInt32(&b.n, 1) | ||
} | ||
|
||
// SetToFalse sets this value to false | ||
func (b *AtomicBool) SetToFalse() { | ||
atomic.StoreInt32(&b.n, 0) | ||
} | ||
|
||
// True returns true if it is set to true | ||
func (b *AtomicBool) True() bool { | ||
return atomic.LoadInt32(&b.n) != int32(0) | ||
} | ||
|
||
// False return true if it is set to false | ||
func (b *AtomicBool) False() bool { | ||
return atomic.LoadInt32(&b.n) == int32(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package client | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAtomicBool(t *testing.T) { | ||
b0 := NewAtomicBool(false) | ||
assert.False(t, b0.True(), "should false") | ||
assert.True(t, b0.False(), "should false") | ||
|
||
b1 := NewAtomicBool(true) | ||
assert.True(t, b1.True(), "should true") | ||
assert.False(t, b1.False(), "should true") | ||
|
||
b0.SetToTrue() | ||
assert.True(t, b0.True(), "should true") | ||
assert.False(t, b0.False(), "should true") | ||
b0.SetToFalse() | ||
assert.False(t, b0.True(), "should false") | ||
assert.True(t, b0.False(), "should false") | ||
} |
Oops, something went wrong.