From 1bff784b474261212a996ac9fc59389d53a69590 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Tue, 15 Apr 2025 18:21:41 +0200 Subject: Linda batched mode rework * linda.batched special value is removed * new function linda:receive_batched --- tests/basic.lua | 4 ++-- tests/errhangtest.lua | 9 ++++----- tests/linda_perf.lua | 8 ++++---- tests/protect_allocator.lua | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/basic.lua b/tests/basic.lua index 170e821..a9c85cc 100644 --- a/tests/basic.lua +++ b/tests/basic.lua @@ -209,7 +209,7 @@ PRINT "wait_receive_lane is cancelled" local wait_receive_batched = function() local k, v1, v2 set_finalizer(function() print("wait_receive_batched", k, v1, v2) end) - k, v1, v2 = limited:receive(limited.batched, "dummy", 2) -- infinite timeout, returns only when lane is cancelled + k, v1, v2 = limited:receive_batched("dummy", 2) -- infinite timeout, returns only when lane is cancelled end local wait_receive_batched_lane = lanes.gen("*", { name = 'auto' }, wait_receive_batched)() @@ -273,7 +273,7 @@ local b,x,y,z,w = linda:get("<->", 4) assert(b == 3 and x == "x" and y == "y" and z == "z" and w == nil) local k, x = linda:receive("<->") assert(k == "<->" and x == "x") -local k,y,z = linda:receive(linda.batched, "<->", 2) +local k,y,z = linda:receive_batched("<->", 2) assert(k == "<->" and y == "y" and z == "z") linda:set("<->") local b,x,y,z,w = linda:get("<->", 4) diff --git a/tests/errhangtest.lua b/tests/errhangtest.lua index fff0dee..5b3f0c0 100644 --- a/tests/errhangtest.lua +++ b/tests/errhangtest.lua @@ -19,7 +19,6 @@ end if true then print "\n#### reserved sentinels" print(pcall(linda.set, linda, lanes.cancel_error)) - print(pcall(linda.set, linda, linda.batched)) local _count, _val = linda:get("test") assert(_count == 0 and _val == nil) print "OK" @@ -28,13 +27,13 @@ end -- get/set a few values if true then print "\n#### set 3 -> receive batched" - assert.fails(function() linda:receive(linda.batched, "some key", -1, 1) end) - assert.fails(function() linda:receive(linda.batched, "some key", 2, 1) end) - assert.failsnot(function() linda:receive(0, linda.batched, "some key", 1, 3) end) + assert.fails(function() linda:receive_batched("some key", -1, 1) end) + assert.fails(function() linda:receive_batched("some key", 2, 1) end) + assert.failsnot(function() linda:receive_batched(0, "some key", 1, 3) end) local fun = function() print "function test ok" end print(pcall(linda.set, linda, 'test', true, nil, fun)) -- read back the contents - local k,b,n,f = linda:receive(linda.batched, 'test', 3) + local k,b,n,f = linda:receive_batched('test', 3) local _count, _val = linda:get("test") assert(_count == 0 and _val == nil) -- check they are ok diff --git a/tests/linda_perf.lua b/tests/linda_perf.lua index bba1408..107fd25 100644 --- a/tests/linda_perf.lua +++ b/tests/linda_perf.lua @@ -68,7 +68,7 @@ local gobbler = function( l, loop, batch) l:receive( "go") -- eat data in batches for i = 1, loop/batch do - l:receive( l.batched, "key", batch) + l:receive_batched("key", batch) -- print("gobbler:", batch) end print "loop is over" @@ -168,9 +168,9 @@ local function ziva2( preloop, loop, batch) local l = lanes.linda("ziva2("..preloop..":"..loop..":"..tostring(batch)..")", group_uid) group_uid = (group_uid % config.nb_user_keepers) + 1 -- prefill the linda a bit to increase fifo stress - local top, step = math.max( preloop, loop), (l.batched and batch) and batch or 1 + local top, step = math.max( preloop, loop), batch or 1 local batch_send, batch_read - if l.batched and batch then + if batch then local batch_values = {} for i = 1, batch do table.insert( batch_values, i) @@ -180,7 +180,7 @@ local function ziva2( preloop, loop, batch) l:send( "key", table_unpack( batch_values)) end batch_read = function() - l:receive( l.batched, "key", batch) + l:receive_batched("key", batch) end else -- not batched batch_send = function() diff --git a/tests/protect_allocator.lua b/tests/protect_allocator.lua index e13a57c..325726a 100644 --- a/tests/protect_allocator.lua +++ b/tests/protect_allocator.lua @@ -52,7 +52,7 @@ end -- wait for completion print "wait for completion" -linda:receive( linda.batched, "key", COUNT) +linda:receive_batched("key", COUNT) print "waiting a bit more ..." SLEEP(1) print "SUCCESS" -- cgit v1.2.3-55-g6feb