From 39ab92f7b1c86cf4790353cb3123d43d6738e951 Mon Sep 17 00:00:00 2001 From: Alexey Stukalov Date: Fri, 11 Sep 2015 13:39:31 +0200 Subject: [PATCH] add navailable/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 cff41f09549aa..742514a64daf4 100644 --- a/base/multi.jl +++ b/base/multi.jl @@ -517,15 +517,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) @@ -777,6 +768,15 @@ function call_on_owner(f, rr::RemoteRef, args...) end end +for f in (:isready, :navailable, :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 021fb2ed23a54..3ec50a7d19c33 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 navailable(rr) == 0 +@test capacity(rr) > 0 a = rand(5,5) put!(rr, a) +@test isready(rr) +@test navailable(rr) == 1 @test rr[2,3] == a[2,3] @test rr[] == a +take!(rr) +@test !isready(rr) +@test navailable(rr) == 0 rr=RemoteRef(workers()[1]) @test typeof(rr) == RemoteRef{Channel{Any}} +@test !isready(rr) +@test navailable(rr) == 0 +@test capacity(rr) > 0 a = rand(5,5) put!(rr, a) +@test isready(rr) +@test navailable(rr) == 1 @test rr[1,5] == a[1,5] @test rr[] == a +take!(rr) +@test !isready(rr) +@test navailable(rr) == 0 dims = (20,20,20)