Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Commit

Permalink
go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
huandu committed Nov 17, 2015
1 parent 0c5ec31 commit dfa7373
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 43 deletions.
4 changes: 2 additions & 2 deletions info.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ func getg() *g
// GoroutineId return id of current goroutine.
// It's guaranteed to be unique globally during app's life time.
func GoroutineId() int64 {
gp := getg()
return gp.goid
gp := getg()
return gp.goid
}
72 changes: 36 additions & 36 deletions info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,43 @@
package goroutine

import (
"testing"
"time"
"fmt"
"math/rand"
"fmt"
"math/rand"
"testing"
"time"
)

func TestGoroutineIdConsistency(t *testing.T) {
cnt := 10
exit := make(chan error)

for i := 0; i < cnt; i++ {
go func(n int) {
id1 := GoroutineId()
time.Sleep(time.Duration(rand.Int63n(100)) * time.Millisecond)
id2 := GoroutineId()

if id1 != id2 {
exit <- fmt.Errorf("Inconsistent goroutine id. [old:%v] [new:%v]", id1, id2)
return
}

exit <- nil
}(i)
}

failed := false

for i := 0; i < cnt; i++ {
err := <-exit

if err != nil {
t.Logf("Found error. [err:%v]", err)
failed = true
}
}

if failed {
t.Fatalf("Test failed.")
}
cnt := 10
exit := make(chan error)

for i := 0; i < cnt; i++ {
go func(n int) {
id1 := GoroutineId()
time.Sleep(time.Duration(rand.Int63n(100)) * time.Millisecond)
id2 := GoroutineId()

if id1 != id2 {
exit <- fmt.Errorf("Inconsistent goroutine id. [old:%v] [new:%v]", id1, id2)
return
}

exit <- nil
}(i)
}

failed := false

for i := 0; i < cnt; i++ {
err := <-exit

if err != nil {
t.Logf("Found error. [err:%v]", err)
failed = true
}
}

if failed {
t.Fatalf("Test failed.")
}
}
10 changes: 5 additions & 5 deletions opaque.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ package goroutine

import "unsafe"

const ptrSize = 4 << (^uintptr(0) >> 63) // unsafe.Sizeof(uintptr(0)) but an ideal const
const regSize = 4 << (^uintreg(0) >> 63) // unsafe.Sizeof(uintreg(0)) but an ideal const
const ptrSize = 4 << (^uintptr(0) >> 63) // unsafe.Sizeof(uintptr(0)) but an ideal const
const regSize = 4 << (^uintreg(0) >> 63) // unsafe.Sizeof(uintreg(0)) but an ideal const

type mcache struct {}
type typeAlg struct {}
type traceBuf struct {}
type mcache struct{}
type typeAlg struct{}
type traceBuf struct{}

type gcMarkWorkerMode int

Expand Down
1 change: 1 addition & 0 deletions runtime2.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ type guintptr uintptr

func (gp guintptr) ptr() *g { return (*g)(unsafe.Pointer(gp)) }
func (gp *guintptr) set(g *g) { *gp = guintptr(unsafe.Pointer(g)) }

// func (gp *guintptr) cas(old, new guintptr) bool {
// return casuintptr((*uintptr)(unsafe.Pointer(gp)), uintptr(old), uintptr(new))
// }
Expand Down

0 comments on commit dfa7373

Please sign in to comment.