aboutsummaryrefslogtreecommitdiff
path: root/tests/fifo.lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/fifo.lua42
1 files changed, 36 insertions, 6 deletions
diff --git a/tests/fifo.lua b/tests/fifo.lua
index bef60d5..498f540 100644
--- a/tests/fifo.lua
+++ b/tests/fifo.lua
@@ -6,24 +6,27 @@
6 6
7local lanes = require "lanes".configure{shutdown_timeout=3,with_timers=true} 7local lanes = require "lanes".configure{shutdown_timeout=3,with_timers=true}
8 8
9local linda = lanes.linda( "atom") 9local atomic_linda = lanes.linda( "atom")
10local atomic_inc= lanes.genatomic( linda, "FIFO_n") 10local atomic_inc= lanes.genatomic( atomic_linda, "FIFO_n")
11
12local fifo_linda = lanes.linda( "fifo")
11 13
12assert( atomic_inc()==1) 14assert( atomic_inc()==1)
13assert( atomic_inc()==2) 15assert( atomic_inc()==2)
14 16
15local function FIFO() 17local function FIFO()
16 local my_channel= "FIFO"..atomic_inc() 18 local my_channel= "FIFO_"..atomic_inc()
17 19
18 return { 20 return {
19 -- Giving explicit 'nil' timeout allows numbers to be used as 'my_channel' 21 -- Giving explicit 'nil' timeout allows numbers to be used as 'my_channel'
20 -- 22 --
21 send = function(self, ...) 23 send = function(self, ...)
22 linda:send( nil, my_channel, ...) 24 fifo_linda:send( nil, my_channel, ...)
23 end, 25 end,
24 receive = function(self, timeout) 26 receive = function(self, timeout)
25 return linda:receive( timeout, my_channel) 27 return fifo_linda:receive( timeout, my_channel)
26 end 28 end,
29 channel = my_channel
27 } 30 }
28end 31end
29 32
@@ -36,11 +39,38 @@ A:send( 1,2,3,4,5)
36print "Sending to B.." 39print "Sending to B.."
37B:send( 'a','b','c') 40B:send( 'a','b','c')
38 41
42print "Dumping linda stats.. [1]" -- count everything
43for key,count in pairs(fifo_linda:count()) do
44 print("channel " .. key .. " contains " .. count .. " entries.")
45 -- print(i, key_count[1], key_count[2])
46end
47print "Dumping linda stats.. [2]" -- query count for known channels one at a time
48print("channel " .. A.channel .. " contains " .. fifo_linda:count(A.channel) .. " entries.")
49print("channel " .. B.channel .. " contains " .. fifo_linda:count(B.channel) .. " entries.")
50print "Dumping linda stats.. [3]" -- query counts for a predefined list of keys
51for key,count in pairs(fifo_linda:count(A.channel, B.channel)) do
52 print("channel " .. key .. " contains " .. count .. " entries.")
53 -- print(i, key_count[1], key_count[2])
54end
55print "Dumping linda stats.. [4]" -- count everything
56for key,contents in pairs(fifo_linda:dump()) do
57 print("channel " .. key .. ": limit=".. contents.limit, " first=" .. contents.first, " count=" .. contents.count)
58 for k,v in pairs(contents.fifo) do
59 print("[".. k.."] = " .. v)
60 end
61end
62
39print "Reading A.." 63print "Reading A.."
40print( A:receive( 1.0)) 64print( A:receive( 1.0))
65print( A:receive( 1.0))
66print( A:receive( 1.0))
67print( A:receive( 1.0))
68print( A:receive( 1.0))
41 69
42print "Reading B.." 70print "Reading B.."
43print( B:receive( 2.0)) 71print( B:receive( 2.0))
72print( B:receive( 2.0))
73print( B:receive( 2.0))
44 74
45-- Note: A and B can be passed between threads, or used as upvalues 75-- Note: A and B can be passed between threads, or used as upvalues
46-- by multiple threads (other parts will be copied but the 'linda' 76-- by multiple threads (other parts will be copied but the 'linda'