@@ -321,7 +321,13 @@ func (root *semaRoot) queue(addr *uint32, s *sudog, lifo bool, syncSema bool) {
321
321
var last * sudog
322
322
pt := & root .treap
323
323
for t := * pt ; t != nil ; t = * pt {
324
- if t .elem == pAddr {
324
+ var cmp bool
325
+ if goexperiment .DeadlockGC {
326
+ cmp = uintptr (gcUnmask (pAddr )) == uintptr (gcUnmask (t .elem ))
327
+ } else {
328
+ cmp = uintptr (pAddr ) == uintptr (t .elem )
329
+ }
330
+ if cmp {
325
331
// Already have addr in list.
326
332
if lifo {
327
333
// Substitute s in t's place in treap.
@@ -367,7 +373,12 @@ func (root *semaRoot) queue(addr *uint32, s *sudog, lifo bool, syncSema bool) {
367
373
return
368
374
}
369
375
last = t
370
- if uintptr (pAddr ) < uintptr (t .elem ) {
376
+ if goexperiment .DeadlockGC {
377
+ cmp = uintptr (gcUnmask (pAddr )) < uintptr (gcUnmask (t .elem ))
378
+ } else {
379
+ cmp = uintptr (pAddr ) < uintptr (t .elem )
380
+ }
381
+ if cmp {
371
382
pt = & t .prev
372
383
} else {
373
384
pt = & t .next
@@ -413,29 +424,23 @@ func (root *semaRoot) dequeue(addr *uint32) (found *sudog, now, tailtime int64)
413
424
ps := & root .treap
414
425
s := * ps
415
426
416
- if goexperiment .DeadlockGC {
417
- // First try to find a masked address.
418
- var pAddr unsafe.Pointer = gcMask (unsafe .Pointer (addr ))
419
- for ; s != nil ; s = * ps {
420
- if s .elem == pAddr {
421
- goto Found
422
- }
423
- if uintptr (pAddr ) < uintptr (s .elem ) {
424
- ps = & s .prev
425
- } else {
426
- ps = & s .next
427
- }
428
- }
429
- // Otherwise, try to find an unmasked address.
430
- ps = & root .treap
431
- s = * ps
432
- }
433
-
434
427
for ; s != nil ; s = * ps {
435
- if s .elem == unsafe .Pointer (addr ) {
428
+ var cmp bool
429
+ if goexperiment .DeadlockGC {
430
+ cmp = gcUnmask (unsafe .Pointer (addr )) == gcUnmask (s .elem )
431
+ } else {
432
+ cmp = unsafe .Pointer (addr ) == s .elem
433
+ }
434
+ if cmp {
436
435
goto Found
437
436
}
438
- if uintptr (unsafe .Pointer (addr )) < uintptr (s .elem ) {
437
+
438
+ if goexperiment .DeadlockGC {
439
+ cmp = uintptr (gcUnmask (unsafe .Pointer (addr ))) < uintptr (gcUnmask (s .elem ))
440
+ } else {
441
+ cmp = uintptr (unsafe .Pointer (addr )) < uintptr (s .elem )
442
+ }
443
+ if cmp {
439
444
ps = & s .prev
440
445
} else {
441
446
ps = & s .next
0 commit comments