Skip to content

Commit 00e6a16

Browse files
TommyXRElOceanografo
authored andcommitted
Add lock wrapper for Channels (JuliaLang#39312)
Added lock(f, c::Channel) utility function
1 parent 9ccb695 commit 00e6a16

File tree

4 files changed

+5
-1
lines changed

4 files changed

+5
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ New library functions
3636
* Two argument methods `findmax(f, domain)`, `argmax(f, domain)` and the corresponding `min` versions ([#27613]).
3737
* `isunordered(x)` returns true if `x` is value that is normally unordered, such as `NaN` or `missing`.
3838
* New macro `Base.@invokelatest f(args...; kwargs...)` provides a convenient way to call `Base.invokelatest(f, args...; kwargs...)` ([#37971])
39+
* New macro `Base.@invoke f(arg1::T1, arg2::T2; kwargs...)` provides an easier syntax to call `invoke(f, Tuple{T1,T2}; kwargs...)` ([#38438])
40+
* Two arguments method `lock(f, lck)` now accepts a `Channel` as the second argument. ([#39312])
3941
* New functor `Returns(value)`, which returns `value` for any arguments ([#39794])
4042
* New macro `Base.@invoke f(arg1::T1, arg2::T2; kwargs...)` provides an easier syntax to call `invoke(f, Tuple{T1,T2}, arg1, arg2; kwargs...)` ([#38438])
4143

base/channels.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ n_avail(c::Channel) = isbuffered(c) ? length(c.data) : length(c.cond_put.waitq)
422422
isempty(c::Channel) = isbuffered(c) ? isempty(c.data) : isempty(c.cond_put.waitq)
423423

424424
lock(c::Channel) = lock(c.cond_take)
425+
lock(f, c::Channel) = lock(f, c.cond_take)
425426
unlock(c::Channel) = unlock(c.cond_take)
426427
trylock(c::Channel) = trylock(c.cond_take)
427428

base/condition.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ trylock(c::GenericCondition) = trylock(c.lock)
7676
islocked(c::GenericCondition) = islocked(c.lock)
7777

7878
lock(f, c::GenericCondition) = lock(f, c.lock)
79-
unlock(f, c::GenericCondition) = unlock(f, c.lock)
8079

8180
# have waiter wait for c
8281
function _wait2(c::GenericCondition, waiter::Task)

base/weakkeydict.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ empty(d::WeakKeyDict, ::Type{K}, ::Type{V}) where {K, V} = WeakKeyDict{K, V}()
8484
IteratorSize(::Type{<:WeakKeyDict}) = SizeUnknown()
8585

8686
islocked(wkh::WeakKeyDict) = islocked(wkh.lock)
87+
lock(wkh::WeakKeyDict) = lock(wkh.lock)
88+
unlock(wkh::WeakKeyDict) = unlock(wkh.lock)
8789
lock(f, wkh::WeakKeyDict) = lock(f, wkh.lock)
8890
trylock(f, wkh::WeakKeyDict) = trylock(f, wkh.lock)
8991

0 commit comments

Comments
 (0)