Skip to content

Commit

Permalink
Revert _trylock to the simple case to recover uncontended throughput
Browse files Browse the repository at this point in the history
  • Loading branch information
andrebsguedes committed Dec 12, 2024
1 parent 5fe5d5f commit 4dc6406
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions base/lock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,14 @@ function trylock end
return _trylock(rl, ct)
end
@noinline function _trylock(rl::ReentrantLock, ct::Task)
state = @atomic :monotonic rl.havelock
while true
if state & LOCKED_BIT != 0
return false
end

GC.disable_finalizers()
result = (@atomicreplace :acquire :monotonic rl.havelock state => state | LOCKED_BIT)
if result.success
rl.reentrancy_cnt = 0x0000_0001
@atomic :release rl.locked_by = ct
return true
else
state = result.old
end
GC.enable_finalizers()
GC.disable_finalizers()
if (@atomicreplace :acquire rl.havelock 0x0 => LOCKED_BIT).success
rl.reentrancy_cnt = 0x0000_0001
@atomic :release rl.locked_by = ct
return true
end
GC.enable_finalizers()
return false
end

"""
Expand Down

0 comments on commit 4dc6406

Please sign in to comment.