Skip to content

Commit

Permalink
review comments, thanks @ccoVeille for the thorough look
Browse files Browse the repository at this point in the history
  • Loading branch information
ldemailly committed Jul 17, 2024
1 parent 8c81506 commit 376fcdf
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion console_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ var (
Color = false
)

func IsValid(file *os.File) bool {
// Is the file (e.g os.StdErr) Stat()able so we can detect if it's a tty or not.
// If not we switch in init() to Stdout.
func isValid(file *os.File) bool {
if file == nil {
return false
}
Expand Down
8 changes: 4 additions & 4 deletions goroutine/gid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strconv"
"strings"
"sync"
"sync/atomic"
"testing"
)

Expand All @@ -21,7 +22,7 @@ func TestID(t *testing.T) {
}
n := 1000000 // for regular go
if IsTinyGo {
n = 1000 // for tinygo
n = 1000 // for tinygo, it OOMs with 1000000 and we're only self testing that we get different increasing ids.
}
var wg sync.WaitGroup
for i := 0; i < n; i++ {
Expand All @@ -45,8 +46,7 @@ var testID int64
func goid() int64 {
if IsTinyGo {
// pretty horrible test that aligns with the implementation, but at least it tests we get 1,2,3... different numbers.
testID++
return testID
return atomic.AddInt64(&testID, 1)
}
var buf [64]byte
n := runtime.Stack(buf[:], false)
Expand All @@ -58,7 +58,7 @@ func goid() int64 {
return id
}

var gotid int64
var gotid int64 // outside of the function to help avoiding compiler optimizations

func BenchmarkGID(b *testing.B) {
for n := 0; n < b.N; n++ {
Expand Down
2 changes: 1 addition & 1 deletion goroutine/gid_tinygo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (

func ID() int64 {
task := uintptr(currentTask())
lock.Lock()
lock.Lock() // explicit minimal critical section without using defer, on purpose.
if id, ok := mapping[task]; ok {
lock.Unlock()
return id
Expand Down
2 changes: 1 addition & 1 deletion logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (l *JSONEntry) Time() time.Time {

//nolint:gochecknoinits // needed
func init() {
if !IsValid(os.Stderr) { // wasm in browser case for instance
if !isValid(os.Stderr) { // wasm in browser case for instance
SetOutput(os.Stdout) // this could also be invalid too but... we tried.
}
setLevel(Info) // starting value
Expand Down

0 comments on commit 376fcdf

Please sign in to comment.