diff options
Diffstat (limited to 'src/runtime/synctest.go')
| -rw-r--r-- | src/runtime/synctest.go | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/runtime/synctest.go b/src/runtime/synctest.go index 08a0e5d444..16af1209b4 100644 --- a/src/runtime/synctest.go +++ b/src/runtime/synctest.go @@ -363,6 +363,13 @@ type specialBubble struct { bubbleid uint64 } +// Keep these in sync with internal/synctest. +const ( + bubbleAssocUnbubbled = iota // not associated with any bubble + bubbleAssocCurrentBubble // associated with the current bubble + bubbleAssocOtherBubble // associated with a different bubble +) + // getOrSetBubbleSpecial checks the special record for p's bubble membership. // // If add is true and p is not associated with any bubble, @@ -371,10 +378,12 @@ type specialBubble struct { // It returns ok==true if p is associated with bubbleid // (including if a new association was added), // and ok==false if not. -func getOrSetBubbleSpecial(p unsafe.Pointer, bubbleid uint64, add bool) (ok bool) { +func getOrSetBubbleSpecial(p unsafe.Pointer, bubbleid uint64, add bool) (assoc int) { span := spanOfHeap(uintptr(p)) if span == nil { - throw("getOrSetBubbleSpecial on invalid pointer") + // This is probably a package var. + // We can't attach a special to it, so always consider it unbubbled. + return bubbleAssocUnbubbled } // Ensure that the span is swept. @@ -393,7 +402,11 @@ func getOrSetBubbleSpecial(p unsafe.Pointer, bubbleid uint64, add bool) (ok bool // p is already associated with a bubble. // Return true iff it's the same bubble. s := (*specialBubble)((unsafe.Pointer)(*iter)) - ok = s.bubbleid == bubbleid + if s.bubbleid == bubbleid { + assoc = bubbleAssocCurrentBubble + } else { + assoc = bubbleAssocOtherBubble + } } else if add { // p is not associated with a bubble, // and we've been asked to add an association. @@ -404,23 +417,23 @@ func getOrSetBubbleSpecial(p unsafe.Pointer, bubbleid uint64, add bool) (ok bool s.special.next = *iter *iter = (*special)(unsafe.Pointer(s)) spanHasSpecials(span) - ok = true + assoc = bubbleAssocCurrentBubble } else { // p is not associated with a bubble. - ok = false + assoc = bubbleAssocUnbubbled } unlock(&span.speciallock) releasem(mp) - return ok + return assoc } // synctest_associate associates p with the current bubble. // It returns false if p is already associated with a different bubble. // //go:linkname synctest_associate internal/synctest.associate -func synctest_associate(p unsafe.Pointer) (ok bool) { +func synctest_associate(p unsafe.Pointer) int { return getOrSetBubbleSpecial(p, getg().bubble.id, true) } @@ -435,5 +448,5 @@ func synctest_disassociate(p unsafe.Pointer) { // //go:linkname synctest_isAssociated internal/synctest.isAssociated func synctest_isAssociated(p unsafe.Pointer) bool { - return getOrSetBubbleSpecial(p, getg().bubble.id, false) + return getOrSetBubbleSpecial(p, getg().bubble.id, false) == bubbleAssocCurrentBubble } |
