diff options
Diffstat (limited to '')
-rw-r--r-- | tests/fifo.lua | 42 |
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 | ||
7 | local lanes = require "lanes".configure{shutdown_timeout=3,with_timers=true} | 7 | local lanes = require "lanes".configure{shutdown_timeout=3,with_timers=true} |
8 | 8 | ||
9 | local linda = lanes.linda( "atom") | 9 | local atomic_linda = lanes.linda( "atom") |
10 | local atomic_inc= lanes.genatomic( linda, "FIFO_n") | 10 | local atomic_inc= lanes.genatomic( atomic_linda, "FIFO_n") |
11 | |||
12 | local fifo_linda = lanes.linda( "fifo") | ||
11 | 13 | ||
12 | assert( atomic_inc()==1) | 14 | assert( atomic_inc()==1) |
13 | assert( atomic_inc()==2) | 15 | assert( atomic_inc()==2) |
14 | 16 | ||
15 | local function FIFO() | 17 | local 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 | } |
28 | end | 31 | end |
29 | 32 | ||
@@ -36,11 +39,38 @@ A:send( 1,2,3,4,5) | |||
36 | print "Sending to B.." | 39 | print "Sending to B.." |
37 | B:send( 'a','b','c') | 40 | B:send( 'a','b','c') |
38 | 41 | ||
42 | print "Dumping linda stats.. [1]" -- count everything | ||
43 | for key,count in pairs(fifo_linda:count()) do | ||
44 | print("channel " .. key .. " contains " .. count .. " entries.") | ||
45 | -- print(i, key_count[1], key_count[2]) | ||
46 | end | ||
47 | print "Dumping linda stats.. [2]" -- query count for known channels one at a time | ||
48 | print("channel " .. A.channel .. " contains " .. fifo_linda:count(A.channel) .. " entries.") | ||
49 | print("channel " .. B.channel .. " contains " .. fifo_linda:count(B.channel) .. " entries.") | ||
50 | print "Dumping linda stats.. [3]" -- query counts for a predefined list of keys | ||
51 | for 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]) | ||
54 | end | ||
55 | print "Dumping linda stats.. [4]" -- count everything | ||
56 | for 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 | ||
61 | end | ||
62 | |||
39 | print "Reading A.." | 63 | print "Reading A.." |
40 | print( A:receive( 1.0)) | 64 | print( A:receive( 1.0)) |
65 | print( A:receive( 1.0)) | ||
66 | print( A:receive( 1.0)) | ||
67 | print( A:receive( 1.0)) | ||
68 | print( A:receive( 1.0)) | ||
41 | 69 | ||
42 | print "Reading B.." | 70 | print "Reading B.." |
43 | print( B:receive( 2.0)) | 71 | print( B:receive( 2.0)) |
72 | print( B:receive( 2.0)) | ||
73 | print( 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' |