Skip to content

Commit

Permalink
Use test-and-test-set pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Jan 8, 2024
1 parent cb334ca commit bf2c3eb
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/PyCall.jl
Expand Up @@ -84,15 +84,13 @@ end
const PYDECREF_LOCK = ReentrantLock()

function _pydecref_locked(po::PyObject)
if !islocked(PYDECREF_LOCK)
# If available, we lock and decref
lock(PYDECREF_LOCK) do
pydecref_(po)
end
else
# Add back to queue to be decref'd later
finalizer(_pydecref_locked, po)
end
# If available, we lock and decref
if !islocked(PYDECREF_LOCK) &&
trylock(() -> pydecref_(po), PYDECREF_LOCK) &&
return nothing

# Add back to queue to be decref'd later
finalizer(_pydecref_locked, po)
return nothing
end

Expand Down

0 comments on commit bf2c3eb

Please sign in to comment.