diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-03-22 15:36:45 +0100 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-03-22 15:36:45 +0100 |
commit | bfb1277b3496018b7ee12eca2fb900ebbe651b49 (patch) | |
tree | 7909c38e5fc0c25ee0477c0b842e19adf0cd2874 /tests | |
parent | f0170ce8f1a90337637d387b87280f121d0578fe (diff) | |
download | lanes-bfb1277b3496018b7ee12eca2fb900ebbe651b49.tar.gz lanes-bfb1277b3496018b7ee12eca2fb900ebbe651b49.tar.bz2 lanes-bfb1277b3496018b7ee12eca2fb900ebbe651b49.zip |
C++ migration: STACK_GROW is no longer a macro, sanitized and fixed warnings in keeper.cpp
Diffstat (limited to 'tests')
-rw-r--r-- | tests/fifo.lua | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/tests/fifo.lua b/tests/fifo.lua index bef60d5..8bd1fc2 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,31 @@ 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 | |||
39 | print "Reading A.." | 56 | print "Reading A.." |
40 | print( A:receive( 1.0)) | 57 | print( A:receive( 1.0)) |
58 | print( A:receive( 1.0)) | ||
59 | print( A:receive( 1.0)) | ||
60 | print( A:receive( 1.0)) | ||
61 | print( A:receive( 1.0)) | ||
41 | 62 | ||
42 | print "Reading B.." | 63 | print "Reading B.." |
43 | print( B:receive( 2.0)) | 64 | print( B:receive( 2.0)) |
65 | print( B:receive( 2.0)) | ||
66 | print( B:receive( 2.0)) | ||
44 | 67 | ||
45 | -- Note: A and B can be passed between threads, or used as upvalues | 68 | -- 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' | 69 | -- by multiple threads (other parts will be copied but the 'linda' |