aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2012-06-24 15:12:32 +0200
committerBenoit Germain <bnt.germain@gmail.com>2012-06-24 15:12:32 +0200
commit14acdd61de1e3679cb731713c6e5aba274fa8869 (patch)
treebce1234e0a956abbd8fb5b1f383fe7e10b2881ed
parentfc20e54ac64569ad53118084a2b0615f84eed5b1 (diff)
downloadlanes-14acdd61de1e3679cb731713c6e5aba274fa8869.tar.gz
lanes-14acdd61de1e3679cb731713c6e5aba274fa8869.tar.bz2
lanes-14acdd61de1e3679cb731713c6e5aba274fa8869.zip
fix issue #25
* lanes.timer() accepts a first_secs=nil to stop a timer * timer lane catches errors and prints them * fixed some typos in manual
-rw-r--r--CHANGES5
-rw-r--r--docs/index.html8
-rw-r--r--src/lanes.c2
-rw-r--r--src/lanes.lua67
4 files changed, 47 insertions, 35 deletions
diff --git a/CHANGES b/CHANGES
index f2b1ba2..52b0349 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,11 @@
1 1
2CHANGES: 2CHANGES:
3 3
4CHANGE 39: BGe 23-Jun-2012
5 * lanes.timer() accepts a first_secs=nil to stop a timer
6 * timer lane catches errors and prints them
7 * fixed some typos in manual
8
4CHANGE 38: BGe 11-Jun-2012 9CHANGE 38: BGe 11-Jun-2012
5 * linda:receive() batched mode now accepts a max_count optional argument 10 * linda:receive() batched mode now accepts a max_count optional argument
6 11
diff --git a/docs/index.html b/docs/index.html
index 1ae1855..52ba852 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -56,7 +56,7 @@
56 56
57<p><br/><font size="-1"><i>Copyright &copy; 2007-12 Asko Kauppi, Benoit Germain. All rights reserved.</i> 57<p><br/><font size="-1"><i>Copyright &copy; 2007-12 Asko Kauppi, Benoit Germain. All rights reserved.</i>
58 <br>Lua Lanes is published under the same <A HREF="http://en.wikipedia.org/wiki/MIT_License">MIT license</A> as Lua 5.1. 58 <br>Lua Lanes is published under the same <A HREF="http://en.wikipedia.org/wiki/MIT_License">MIT license</A> as Lua 5.1.
59 </p><p>This document was revised on 17-Feb-11, and applies to version 3.1.3 59 </p><p>This document was revised on 23-Jun-12, and applies to version 3.1.4
60</font></p> 60</font></p>
61 61
62</center> 62</center>
@@ -509,7 +509,7 @@ It is also possible to manually test for cancel requests with <tt>cancel_test()<
509<table border=1 bgcolor="#E0E0FF" cellpadding=10><tr><td> 509<table border=1 bgcolor="#E0E0FF" cellpadding=10><tr><td>
510 <code>set_finalizer( finalizer_func )</code> 510 <code>set_finalizer( finalizer_func )</code>
511 <br/><br/> 511 <br/><br/>
512 <code>void= finalizer_func( [error] )</code> 512 <code>void= finalizer_func( [err, stack_tbl] )</code>
513</table> 513</table>
514 514
515<p>The <tt>error</tt> call is used for throwing exceptions in Lua. What Lua 515<p>The <tt>error</tt> call is used for throwing exceptions in Lua. What Lua
@@ -734,7 +734,7 @@ events to a common Linda, but... :).</font>
734</table> 734</table>
735 735
736<p> 736<p>
737 Timers are implemented as a lane. They can be disabled by passing <tt>"NO_TIMERS"</tt> 737 Timers are implemented as a lane. They can be disabled by setting <tt>"with_timers"</tt> to <tt>nil</tt> or <tt>false</tt>
738 to <tt>lanes.configure()</tt>. 738 to <tt>lanes.configure()</tt>.
739 </p> 739 </p>
740<p> 740<p>
@@ -748,7 +748,7 @@ Once a timer expires, the <tt>key</tt> is set with the current time
748The key can be waited upon using the regular Linda <tt>:receive()</tt> 748The key can be waited upon using the regular Linda <tt>:receive()</tt>
749method. 749method.
750</p><p> 750</p><p>
751A timer can be stopped simply by <tt>first_secs=0</tt> and no period. 751A timer can be stopped simply with <tt>first_secs=0|nil</tt> and no period.
752</p><p> 752</p><p>
753 753
754<table border=1 bgcolor="#FFFFE0" width=500><tr><td> 754<table border=1 bgcolor="#FFFFE0" width=500><tr><td>
diff --git a/src/lanes.c b/src/lanes.c
index 931af98..b1c4018 100644
--- a/src/lanes.c
+++ b/src/lanes.c
@@ -51,7 +51,7 @@
51 * ... 51 * ...
52 */ 52 */
53 53
54char const* VERSION = "3.1.3"; 54char const* VERSION = "3.1.4";
55 55
56/* 56/*
57=============================================================================== 57===============================================================================
diff --git a/src/lanes.lua b/src/lanes.lua
index dffd017..5aeeaf4 100644
--- a/src/lanes.lua
+++ b/src/lanes.lua
@@ -92,10 +92,10 @@ local error= assert( error )
92 92
93lanes.ABOUT= 93lanes.ABOUT=
94{ 94{
95 author= "Asko Kauppi <akauppi@gmail.com>", 95 author= "Asko Kauppi <akauppi@gmail.com>, Benoit Germain <bnt.germain@gmail.com>",
96 description= "Running multiple Lua states in parallel", 96 description= "Running multiple Lua states in parallel",
97 license= "MIT/X11", 97 license= "MIT/X11",
98 copyright= "Copyright (c) 2007-10, Asko Kauppi", 98 copyright= "Copyright (c) 2007-10, Asko Kauppi; (c) 2011-12, Benoit Germain",
99 version= _version, 99 version= _version,
100} 100}
101 101
@@ -315,7 +315,6 @@ if first_time then
315 -- set_timer( linda_h, key [,wakeup_at_secs [,period_secs]] ) 315 -- set_timer( linda_h, key [,wakeup_at_secs [,period_secs]] )
316 -- 316 --
317 local function set_timer( linda, key, wakeup_at, period ) 317 local function set_timer( linda, key, wakeup_at, period )
318
319 assert( wakeup_at==nil or wakeup_at>0.0 ) 318 assert( wakeup_at==nil or wakeup_at>0.0 )
320 assert( period==nil or period>0.0 ) 319 assert( period==nil or period>0.0 )
321 320
@@ -429,32 +428,40 @@ if first_time then
429 -- We let the timer lane be a "free running" thread; no handle to it 428 -- We let the timer lane be a "free running" thread; no handle to it
430 -- remains. 429 -- remains.
431 -- 430 --
432 gen( "*", { priority=max_prio}, function() -- "*" instead of "io,package" for LuaJIT compatibility... 431 local timer_body = function()
433 set_debug_threadname( "LanesTimer") 432 local timer_gateway_batched = timer_gateway.batched
434 while true do 433 set_debug_threadname( "LanesTimer")
435 local next_wakeup= check_timers() 434 set_finalizer( function( err, stk)
436 435 if err and type( err) ~= "userdata" then
437 -- Sleep until next timer to wake up, or a set/clear command 436 WR( "LanesTimer error: "..tostring(err))
438 -- 437 --elseif type( err) == "userdata" then
439 local secs 438 -- WR( "LanesTimer after cancel" )
440 if next_wakeup then 439 --else
441 secs = next_wakeup - now_secs() 440 -- WR("LanesTimer finalized")
442 if secs < 0 then secs = 0 end 441 end
443 end 442 end)
444 local linda= timer_gateway:receive( secs, TGW_KEY ) 443 while true do
445 444 local next_wakeup= check_timers()
446 if linda then 445
447 local key= timer_gateway:receive( 0.0, TGW_KEY ) 446 -- Sleep until next timer to wake up, or a set/clear command
448 local wakeup_at= timer_gateway:receive( 0.0, TGW_KEY ) 447 --
449 local period= timer_gateway:receive( 0.0, TGW_KEY ) 448 local secs
450 assert( key and wakeup_at and period ) 449 if next_wakeup then
451 450 secs = next_wakeup - now_secs()
452 set_timer( linda, key, wakeup_at, period>0 and period or nil ) 451 if secs < 0 then secs = 0 end
453 --elseif secs == nil then -- got no value while block-waiting? 452 end
454 -- WR( "timer lane: no linda, aborted?") 453 local linda = timer_gateway:receive( secs, TGW_KEY)
455 end 454
456 end 455 if linda then
457 end )() 456 local key, wakeup_at, period = timer_gateway:receive( 0, timer_gateway_batched, TGW_KEY, 3)
457 assert( key)
458 set_timer( linda, key, wakeup_at, period and period > 0 and period or nil)
459 --elseif secs == nil then -- got no value while block-waiting?
460 -- WR( "timer lane: no linda, aborted?")
461 end
462 end
463 end
464 gen( "*", { priority=max_prio}, timer_body)() -- "*" instead of "io,package" for LuaJIT compatibility...
458end 465end
459 466
460----- 467-----
@@ -479,7 +486,7 @@ timer = function( linda, key, a, period )
479 end 486 end
480 487
481 local wakeup_at= type(a)=="table" and wakeup_conv(a) -- given point of time 488 local wakeup_at= type(a)=="table" and wakeup_conv(a) -- given point of time
482 or now_secs()+a 489 or (a and now_secs()+a or nil)
483 -- queue to timer 490 -- queue to timer
484 -- 491 --
485 timer_gateway:send( TGW_KEY, linda, key, wakeup_at, period ) 492 timer_gateway:send( TGW_KEY, linda, key, wakeup_at, period )