Skip to content

Commit

Permalink
use integers, since we're just doing it at init
Browse files Browse the repository at this point in the history
  • Loading branch information
thehowl committed Oct 22, 2024
1 parent e45cf32 commit 6f29763
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions gnovm/pkg/gnolang/uverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"reflect"
"strings"
"sync/atomic"
)

// ----------------------------------------
Expand Down Expand Up @@ -62,7 +61,7 @@ var gStringerType = &DeclaredType{
var (
uverseNode *PackageNode
uverseValue *PackageValue
uverseInit atomic.Uint32 // 0 = not init; 1 = initializing; 2 = init'd
uverseInit int
)

func init() {
Expand All @@ -76,11 +75,12 @@ const uversePkgPath = ".uverse"
// If called while initializing the UverseNode itself, it will return an empty
// PackageValue.
func Uverse() *PackageValue {
switch {
case uverseInit.CompareAndSwap(0, 1):
switch uverseInit {
case 0:
uverseInit = 1
makeUverseNode()
uverseInit.Store(2)
case uverseInit.Load() == 1:
uverseInit = 2
case 1:
return &PackageValue{}
}

Expand All @@ -91,11 +91,12 @@ func Uverse() *PackageValue {
// If called while initializing the UverseNode itself, it will return an empty
// PackageNode.
func UverseNode() *PackageNode {
switch {
case uverseInit.CompareAndSwap(0, 1):
switch uverseInit {
case 0:
uverseInit = 1
makeUverseNode()
uverseInit.Store(2)
case uverseInit.Load() == 1:
uverseInit = 2

Check warning on line 98 in gnovm/pkg/gnolang/uverse.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/uverse.go#L95-L98

Added lines #L95 - L98 were not covered by tests
case 1:
return &PackageNode{}
}

Expand Down

0 comments on commit 6f29763

Please sign in to comment.