From b79fa228d638242b6cc0fda85d918344c6bd2f8e Mon Sep 17 00:00:00 2001 From: Alexey Stukalov Date: Mon, 24 Aug 2015 13:45:03 +0200 Subject: [PATCH] add n_avail/capacity(RemoteRef{Channel}) + tests --- base/multi.jl | 18 +++++++++--------- test/parallel.jl | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/base/multi.jl b/base/multi.jl index a68a039cf48e04..abccad2536ca25 100644 --- a/base/multi.jl +++ b/base/multi.jl @@ -514,15 +514,6 @@ function lookup_ref(pg, id, f) rv end -function isready(rr::RemoteRef, args...) - rid = rr2id(rr) - if rr.where == myid() - isready(lookup_ref(rid).c, args...) - else - remotecall_fetch(rr.where, id->isready(lookup_ref(rid).c, args...), rid) - end -end - del_client(id, client) = del_client(PGRP, id, client) function del_client(pg, id, client) rv = lookup_ref(id) @@ -774,6 +765,15 @@ function call_on_owner(f, rr::RemoteRef, args...) end end +for f in (:isready, :n_avail, :capacity) + f_ref = symbol(string(f, "_ref")) + @eval begin + ($f)(rv::RemoteValue, args...) = ($f)(rv.c, args...) + ($f_ref)(rid, args...) = ($f)(lookup_ref(rid).c, args...) + ($f)(rr::RemoteRef, args...) = call_on_owner(($f_ref), rr, args...) + end +end + wait_ref(rid, args...) = (wait(lookup_ref(rid).c, args...); nothing) wait(r::RemoteRef, args...) = (call_on_owner(wait_ref, r, args...); r) diff --git a/test/parallel.jl b/test/parallel.jl index 8d316ba1a83cdf..a73ba7c3cb81fa 100644 --- a/test/parallel.jl +++ b/test/parallel.jl @@ -16,17 +16,33 @@ id_other = filter(x -> x != id_me, procs())[rand(1:(nprocs()-1))] rr=RemoteRef() @test typeof(rr) == RemoteRef{Channel{Any}} +@test !isready(rr) +@test Base.n_avail(rr) == 0 +@test Base.capacity(rr) > 0 a = rand(5,5) put!(rr, a) +@test isready(rr) +@test Base.n_avail(rr) == 1 @test rr[2,3] == a[2,3] @test rr[] == a +take!(rr) +@test !isready(rr) +@test Base.n_avail(rr) == 0 rr=RemoteRef(workers()[1]) @test typeof(rr) == RemoteRef{Channel{Any}} +@test !isready(rr) +@test Base.n_avail(rr) == 0 +@test Base.capacity(rr) > 0 a = rand(5,5) put!(rr, a) +@test isready(rr) +@test Base.n_avail(rr) == 1 @test rr[1,5] == a[1,5] @test rr[] == a +take!(rr) +@test !isready(rr) +@test Base.n_avail(rr) == 0 dims = (20,20,20)