Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@lock export from Base, closes #36441 #39588

Merged
merged 8 commits into from
Apr 30, 2021
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -85,6 +85,7 @@ Standard library changes
@test isequal(complex(one(T)) / complex(T(Inf), T(-Inf)), complex(zero(T), zero(T))) broken=(T == Float64)
```
([#39322])
* `@lock` and `@lock_nofail` are now exported from Base ([#39588]).

#### Package Manager

1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
@@ -675,6 +675,7 @@ export
istaskstarted,
istaskfailed,
lock,
@lock,
notify,
ReentrantLock,
schedule,
14 changes: 14 additions & 0 deletions base/lock.jl
Original file line number Diff line number Diff line change
@@ -201,6 +201,13 @@ function trylock(f, l::AbstractLock)
return false
end

"""
@lock l expr

Macro version for `lock(f, l::AbstractLock)`, but with `expr` instead of `f` function.
This is similar to using [`lock`](@ref) with a `do` block, but avoids creating a closure
and thus can improve the performance.
"""
macro lock(l, expr)
quote
temp = $(esc(l))
@@ -213,6 +220,13 @@ macro lock(l, expr)
end
end

"""
@lock_nofail l expr

Equivalent to `@lock l expr` for cases in which we can guarantee that the function
will not throw any error. In this case, avoiding try-catch can improve the performance.
See [`@lock`](@ref).
"""
macro lock_nofail(l, expr)
quote
temp = $(esc(l))