From 32ad991eb8c590472607d61e9a831d2ca9db05c5 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Thu, 13 Feb 2014 16:09:15 +0100 Subject: more fixes/tweaks about cancelled lindas * bumped version to 3.8.5 * linda:limit() returns lanes.cancel_error on a limited linda * lanes.genlock() and lanes.genatomic() support cancelled lindas by returning lanes.cancel_error whenever appropriate * fixed a possible Lua stack overflow when calling linda:dump() * fixed cases where linda:send() and linda:receive() would not return lanes.cancel_error when they should --- tests/cancel.lua | 30 ++++++++++++++++++++++++++++++ tests/linda_perf.lua | 4 ++-- 2 files changed, 32 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/cancel.lua b/tests/cancel.lua index a5f1dab..6429487 100644 --- a/tests/cancel.lua +++ b/tests/cancel.lua @@ -2,6 +2,33 @@ local lanes = require "lanes" .configure{ with_timers = false} local linda = lanes.linda() +--#################################################################### +print "\n\n####################################################################\nbegin genlock & genatomic cancel test\n" + +-- get a lock and a atomic operator +local lock = lanes.genlock( linda, "lock", 1) +local atomic = lanes.genatomic( linda, "atomic") + +-- check that cancelled lindas give cancel_error as they should +linda:cancel() +assert( linda:get( "empty") == lanes.cancel_error) +assert( lanes.genlock( linda, "any", 1) == lanes.cancel_error) +assert( lanes.genatomic( linda, "any") == lanes.cancel_error) + +-- check that lock and atomic functions return cancel_error if the linda was cancelled +assert( lock( 1) == lanes.cancel_error) +assert( lock( -1) == lanes.cancel_error) +assert( atomic( 1) == lanes.cancel_error) + +-- reset the linda so that the other tests work +linda:cancel( "none") +linda:limit( "lock", -1) +linda:set( "lock") +linda:limit( "atomic", -1) +linda:set( "atomic") + +--#################################################################### + local laneBody = function( timeout_) set_finalizer( function( err, stk) if err == lanes.cancel_error then @@ -105,4 +132,7 @@ linda:cancel( "both") print "wait 5s" linda:receive( 5, "yeah") +--#################################################################### + print "\ndone" + diff --git a/tests/linda_perf.lua b/tests/linda_perf.lua index 1d92c8e..1a44d07 100644 --- a/tests/linda_perf.lua +++ b/tests/linda_perf.lua @@ -31,8 +31,8 @@ local batched = function( l, loop, batch) print( val) end -local lane_eater_gen = lanes.gen( "*", eater) -local lane_batched_gen = lanes.gen( "*", batched) +local lane_eater_gen = lanes.gen( "*", {priority = 3}, eater) +local lane_batched_gen = lanes.gen( "*", {priority = 3}, batched) -- main thread writes data while a lane reads it local function ziva( preloop, loop, batch) -- cgit v1.2.3-55-g6feb