From 053f7cff3c95acb915e6babfd306971f11bb7986 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Sat, 5 Nov 2011 17:31:02 +0100 Subject: * process exit change: close everything at GC when main state closes, not when atexit() handlers are processed * Lua 5.2-style module: * module() is no longer used to implement lanes.lua * a global "lanes" variable is no longer created when the module is required * the Lanes module table is returned instead * Lanes must be initialized before used: * the first occurence of 'require "lanes"' produces a minimal interface that only contains a configure() function * the remainder of the interface is made available once this function is called * subsequent calls to configure() do nothing * configure() controls the number of keeper states and the startup of timers * LuaJIT 2 compatibility * non-Lua functions are no longer copied by creating a C closure from a C pointer, but through 2-way lookup tables * this means that if a lane function body pulls non-Lua functions, the lane generator description must contain the list of libraries and modules that exports them * introduces a change in configuration .globals management: contents are copied *after* std libs are loaded * new .required configuration entry to list modules that must be require()'ed before lane body is transferred * lane:cancel() wakes up waiting lindas like what is done at lane shutdown --- tests/appendud.lua | 3 ++- tests/atexit.lua | 3 ++- tests/atomic.lua | 3 ++- tests/basic.lua | 3 ++- tests/cyclic.lua | 3 ++- tests/ehynes.lua | 3 ++- tests/errhangtest.lua | 3 ++- tests/error.lua | 3 ++- tests/fibonacci.lua | 24 +++++++++++++++++++++--- tests/fifo.lua | 11 ++++++++--- tests/finalizer.lua | 3 ++- tests/func_is_string.lua | 3 ++- tests/hangtest.lua | 3 ++- tests/irayo_closure.lua | 5 +++-- tests/irayo_recursive.lua | 3 ++- tests/keeper.lua | 3 ++- tests/launchtest.lua | 3 ++- tests/linda_perf.lua | 3 ++- tests/objects.lua | 3 ++- tests/perftest.lua | 3 ++- tests/protectproxy.lua | 3 ++- tests/recursive.lua | 4 +++- tests/require.lua | 3 ++- tests/timer.lua | 3 ++- 24 files changed, 75 insertions(+), 29 deletions(-) (limited to 'tests') diff --git a/tests/appendud.lua b/tests/appendud.lua index eb1f768..e275a98 100644 --- a/tests/appendud.lua +++ b/tests/appendud.lua @@ -6,7 +6,8 @@ -- -- Needs Lanes >= 2.0.3 -- -require "lanes" +local lanes = require "lanes" +lanes.configure( 1) local _tab = { beginupdate = function (this) print('tab.beginupdate') end; diff --git a/tests/atexit.lua b/tests/atexit.lua index fb4f34a..09fbafd 100644 --- a/tests/atexit.lua +++ b/tests/atexit.lua @@ -1,4 +1,5 @@ -require "lanes" +local lanes = require "lanes" +lanes.configure( 1) -- create a free-running lane diff --git a/tests/atomic.lua b/tests/atomic.lua index a027453..f1c9428 100644 --- a/tests/atomic.lua +++ b/tests/atomic.lua @@ -4,7 +4,8 @@ -- Test program for Lua Lanes -- -require "lanes" +local lanes = require "lanes" +lanes.configure( 1) local linda= lanes.linda() local key= "$" diff --git a/tests/basic.lua b/tests/basic.lua index 853a8de..8b07697 100644 --- a/tests/basic.lua +++ b/tests/basic.lua @@ -7,7 +7,8 @@ -- - ... -- -require "lanes" +local lanes = require "lanes" +lanes.configure( 1) require "assert" -- assert.fails() local lanes_gen= assert( lanes.gen ) diff --git a/tests/cyclic.lua b/tests/cyclic.lua index 06452bd..15abc9c 100644 --- a/tests/cyclic.lua +++ b/tests/cyclic.lua @@ -4,7 +4,8 @@ -- Test program for Lua Lanes -- -require "lanes" +local lanes = require "lanes" +lanes.configure( 1) local table_concat= assert(table.concat) diff --git a/tests/ehynes.lua b/tests/ehynes.lua index 4cc370e..b529f98 100644 --- a/tests/ehynes.lua +++ b/tests/ehynes.lua @@ -1,7 +1,8 @@ -- -- Test from -- -require 'lanes' +local lanes = require "lanes" +lanes.configure( 1) local function PRINT_FMT( fmt, ... ) io.stderr:write( string.format(fmt,...).."\n" ) diff --git a/tests/errhangtest.lua b/tests/errhangtest.lua index ddc1bfb..7127326 100644 --- a/tests/errhangtest.lua +++ b/tests/errhangtest.lua @@ -1,4 +1,5 @@ -lanes = require('lanes') +local lanes = require "lanes" +lanes.configure( 1) local linda = lanes.linda() diff --git a/tests/error.lua b/tests/error.lua index 4922846..aee4221 100644 --- a/tests/error.lua +++ b/tests/error.lua @@ -4,7 +4,8 @@ -- Note: this code is supposed to end in errors; not included in 'make test' -- -require "lanes" +local lanes = require "lanes" +lanes.configure( 1) local function lane() diff --git a/tests/fibonacci.lua b/tests/fibonacci.lua index 667a3e9..2e0cd62 100644 --- a/tests/fibonacci.lua +++ b/tests/fibonacci.lua @@ -12,7 +12,8 @@ -- Need to say it's 'local' so it can be an upvalue -- -local lanes= require "lanes" +local lanes = require "lanes" +lanes.configure( 1, "NO_TIMERS") local function WR(str) io.stderr:write( str.."\n" ) @@ -38,7 +39,9 @@ local function fib( n ) else -- Splits into two; this task remains waiting for the results -- - local gen_f= lanes.gen( "io,math,debug", fib ) + -- note that lanes is pulled in as upvalue, so we need package library to require internals properly + -- (because lua51-lanes is always required internally if possible, which is necessary in that case) + local gen_f= lanes.gen( "package,string,io,math,debug", fib ) local n1=floor(n/2) +1 local n2=floor(n/2) -1 + n%2 @@ -64,7 +67,22 @@ end -- -- Right answers from: -- -local right= { 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073, 4807526976, 7778742049, 12586269025, 20365011074, 32951280099, 53316291173, 86267571272, 139583862445, 225851433717, 365435296162, 591286729879, 956722026041, 1548008755920, 2504730781961, 4052739537881, 6557470319842, 10610209857723, 17167680177565, 27777890035288, 44945570212853, 72723460248141, 117669030460994, 190392490709135, 308061521170129, 498454011879264, 806515533049393, 1304969544928657, 2111485077978050, 3416454622906707, 5527939700884757, 8944394323791464, 14472334024676220, 23416728348467684, 37889062373143900, 61305790721611580, 99194853094755490, 160500643816367070, 259695496911122560, 420196140727489660, 679891637638612200, 1100087778366101900, 1779979416004714000, 2880067194370816000, 4660046610375530000, 7540113804746346000, 12200160415121877000, 19740274219868226000, 31940434634990105000, 51680708854858334000, 83621143489848440000, 135301852344706780000, 218922995834555200000 +local right= +{ + 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, + 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, + 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, + 701408733, 1134903170, 1836311903, 2971215073, 4807526976, 7778742049, 12586269025, 20365011074, + 32951280099, 53316291173, 86267571272, 139583862445, 225851433717, 365435296162, 591286729879, + 956722026041, 1548008755920, 2504730781961, 4052739537881, 6557470319842, 10610209857723, + 17167680177565, 27777890035288, 44945570212853, 72723460248141, 117669030460994, 190392490709135, + 308061521170129, 498454011879264, 806515533049393, 1304969544928657, 2111485077978050, + 3416454622906707, 5527939700884757, 8944394323791464, 14472334024676220, 23416728348467684, + 37889062373143900, 61305790721611580, 99194853094755490, 160500643816367070, 259695496911122560, + 420196140727489660, 679891637638612200, 1100087778366101900, 1779979416004714000, + 2880067194370816000, 4660046610375530000, 7540113804746346000, 12200160415121877000, + 19740274219868226000, 31940434634990105000, 51680708854858334000, 83621143489848440000, + 135301852344706780000, 218922995834555200000 } assert( #right==99 ) diff --git a/tests/fifo.lua b/tests/fifo.lua index 898b04d..d8289c1 100644 --- a/tests/fifo.lua +++ b/tests/fifo.lua @@ -4,7 +4,8 @@ -- Sample program for Lua Lanes -- -require "lanes" +local lanes = require "lanes" +lanes.configure( 1) local linda= lanes.linda() local atomic_inc= lanes.genatomic( linda, "FIFO_n" ) @@ -18,8 +19,12 @@ local function FIFO() return { -- Giving explicit 'nil' timeout allows numbers to be used as 'my_channel' -- - send= function(...) linda:send( nil, my_channel, ... ) end, - receive= function(timeout) linda:receive( timeout, my_channel ) end + send= function(self, ...) + linda:send( nil, my_channel, ... ) + end, + receive = function(self, timeout) + linda:receive( timeout, my_channel ) + end } end diff --git a/tests/finalizer.lua b/tests/finalizer.lua index c94b36d..88f51c1 100644 --- a/tests/finalizer.lua +++ b/tests/finalizer.lua @@ -8,7 +8,8 @@ -- thing to do. -- AKa 22-Jan-2009 -- -require "lanes" +local lanes = require "lanes" +lanes.configure( 1) local FN= "finalizer-test.tmp" diff --git a/tests/func_is_string.lua b/tests/func_is_string.lua index 98ea62b..5d94f85 100644 --- a/tests/func_is_string.lua +++ b/tests/func_is_string.lua @@ -1,4 +1,5 @@ -require "lanes" +local lanes = require "lanes" +lanes.configure( 1) local options = {globals = { b = 666 }} diff --git a/tests/hangtest.lua b/tests/hangtest.lua index d0bbea4..923496a 100644 --- a/tests/hangtest.lua +++ b/tests/hangtest.lua @@ -2,7 +2,8 @@ -- Test case for hang on [1]s and :join()s. -- -require "lanes" +local lanes = require "lanes" +lanes.configure( 1) local function ret(b) return b diff --git a/tests/irayo_closure.lua b/tests/irayo_closure.lua index 3a82302..77ddbde 100644 --- a/tests/irayo_closure.lua +++ b/tests/irayo_closure.lua @@ -10,7 +10,8 @@ haven't investigated further. e.g. { globals = { data = 1, func = function() useclosurehere() end } }" ]] -require "lanes" +local lanes = require "lanes" +lanes.configure( 1) local function testrun() assert( print ) @@ -20,7 +21,7 @@ local function testrun() return true end --- When some function dereferences a global key, the asssociated global in the source state +-- When some function dereferences a global key, the associated global in the source state -- isn't sent over the target lane -- therefore, the necessary functions must either be pulled as upvalues (hence locals) -- or the globals must exist in the target lanes because the modules have been required there diff --git a/tests/irayo_recursive.lua b/tests/irayo_recursive.lua index 82e5a54..3eb14b8 100644 --- a/tests/irayo_recursive.lua +++ b/tests/irayo_recursive.lua @@ -8,7 +8,8 @@ local function recurse() print("level "..i); if i > 10 then return "finished" end - require "lanes" + local lanes = require "lanes" + lanes.configure( 1, "NO_TIMERS") local lane = lanes.gen( "*", { globals = { ["i"]= i + 1 } }, recurse ) () return lane[1] diff --git a/tests/keeper.lua b/tests/keeper.lua index 5c8c23a..7b11242 100644 --- a/tests/keeper.lua +++ b/tests/keeper.lua @@ -4,7 +4,8 @@ -- Test program for Lua Lanes -- -require "lanes" +local lanes = require "lanes" +lanes.configure( 1) local function keeper(linda) local mt= { diff --git a/tests/launchtest.lua b/tests/launchtest.lua index 5e3037f..8456091 100644 --- a/tests/launchtest.lua +++ b/tests/launchtest.lua @@ -45,7 +45,8 @@ for k,v in pairs( argtable(...) ) do end end -require "lanes" +local lanes = require "lanes" +lanes.configure( 1) local g= lanes.gen( LIBS, function(i) --io.stderr:write( i.."\t" ) diff --git a/tests/linda_perf.lua b/tests/linda_perf.lua index bad0024..12159da 100644 --- a/tests/linda_perf.lua +++ b/tests/linda_perf.lua @@ -1,4 +1,5 @@ -require "lanes" +local lanes = require "lanes" +lanes.configure( 1) -- this lane eats items in the linda one by one local eater = function( l, loop) diff --git a/tests/objects.lua b/tests/objects.lua index 8f56a5f..29e16d8 100644 --- a/tests/objects.lua +++ b/tests/objects.lua @@ -4,7 +4,8 @@ -- Tests that objects (metatables) can be passed between lanes. -- -require "lanes" +local lanes = require "lanes" +lanes.configure( 1) local linda= lanes.linda() diff --git a/tests/perftest.lua b/tests/perftest.lua index 8ce1b3c..3d9fde0 100644 --- a/tests/perftest.lua +++ b/tests/perftest.lua @@ -27,7 +27,8 @@ local MSYS= os.getenv("OSTYPE")=="msys" -require "lanes" +local lanes = require "lanes" +lanes.configure( 1) local m= require "argtable" local argtable= assert( m.argtable ) diff --git a/tests/protectproxy.lua b/tests/protectproxy.lua index 57ca831..363dbf5 100644 --- a/tests/protectproxy.lua +++ b/tests/protectproxy.lua @@ -1,4 +1,5 @@ -require "lanes" +local lanes = require "lanes" +lanes.configure( 1) local body = function( param) print ( "lane body: " .. param) diff --git a/tests/recursive.lua b/tests/recursive.lua index 49c03d3..ad32df8 100644 --- a/tests/recursive.lua +++ b/tests/recursive.lua @@ -11,7 +11,9 @@ local function func( depth ) return "done!" end - require "lanes" + local lanes = require "lanes" + -- lanes.configure() is gone after we call it... + lanes.configure( 1) local lane= lanes.gen("*", func)( depth+1 ) return lane[1] end diff --git a/tests/require.lua b/tests/require.lua index 2cfe780..96717dc 100644 --- a/tests/require.lua +++ b/tests/require.lua @@ -3,7 +3,8 @@ -- -- Test that 'require' works from sublanes -- -require 'lanes' +local lanes = require "lanes" +lanes.configure( 1) local function a_lane() -- To require 'math' we still actually need to have it initialized for diff --git a/tests/timer.lua b/tests/timer.lua index e95f326..f0027d7 100644 --- a/tests/timer.lua +++ b/tests/timer.lua @@ -8,7 +8,8 @@ io.stderr:setvbuf "no" -require "lanes" +local lanes = require "lanes" +lanes.configure( 1) local linda= lanes.linda() -- cgit v1.2.3-55-g6feb