aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Germain <bnt period germain arrobase gmail period com>2014-09-18 16:49:31 +0200
committerBenoit Germain <bnt period germain arrobase gmail period com>2014-09-18 16:49:31 +0200
commit2f7fbc306431a02a6f247148ebbda17b4c2d98f7 (patch)
treebb3a912def9f28a86a8d5d6291d3bd6334bed744
parent0326aa6636b1dce2b2fc4c9db53b023534ca0512 (diff)
downloadlanes-2f7fbc306431a02a6f247148ebbda17b4c2d98f7.tar.gz
lanes-2f7fbc306431a02a6f247148ebbda17b4c2d98f7.tar.bz2
lanes-2f7fbc306431a02a6f247148ebbda17b4c2d98f7.zip
New API lanes.sleep (bumped version to 3.9.7)
-rw-r--r--CHANGES4
-rw-r--r--docs/index.html10
-rw-r--r--src/lanes.c2
-rw-r--r--src/lanes.lua25
4 files changed, 35 insertions, 6 deletions
diff --git a/CHANGES b/CHANGES
index bba16d3..7c03916 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,9 @@
1CHANGES: 1CHANGES:
2 2
3CHANGE 115: BGe 18-sep-14
4 * bumped version to 3.9.7
5 * new function lanes.sleep()
6
3CHANGE 114: BGe 8-Jul-14 7CHANGE 114: BGe 8-Jul-14
4 * Postponed _G scan for function lookup database to after on_state_create invocation 8 * Postponed _G scan for function lookup database to after on_state_create invocation
5 * Fixed a crash when USE_DEBUG_SPEW == 1 9 * Fixed a crash when USE_DEBUG_SPEW == 1
diff --git a/docs/index.html b/docs/index.html
index bfd26bb..e8dc94b 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -70,7 +70,7 @@
70 </p> 70 </p>
71 71
72 <p> 72 <p>
73 This document was revised on 17-Jun-14, and applies to version <tt>3.9.6</tt>. 73 This document was revised on 18-Sep-14, and applies to version <tt>3.9.7</tt>.
74 </p> 74 </p>
75 </font> 75 </font>
76 </center> 76 </center>
@@ -1291,6 +1291,14 @@ events to a common Linda, but... :).</font>
1291 The full list of active timers can be obtained. Obviously, this is a snapshot, and non-repeating timers might no longer exist by the time the results are inspected. 1291 The full list of active timers can be obtained. Obviously, this is a snapshot, and non-repeating timers might no longer exist by the time the results are inspected.
1292</p> 1292</p>
1293 1293
1294<table border="1" bgcolor="#E0E0FF" cellpadding="10" style="width:50%"><tr><td><pre>
1295 void = lanes.sleep( [seconds|false])
1296</pre></td></tr></table>
1297
1298<p>
1299 (Since version 3.9.7) A very simple way of sleeping when nothing else is available. Is implemented by attempting to read some data in an unused channel of the internal linda used for timers (this linda exists even when timers aren't enabled).
1300 Default duration is null, which should only cause a thread context switch.
1301</p>
1294 1302
1295<!-- locks +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 1303<!-- locks +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
1296<hr/> 1304<hr/>
diff --git a/src/lanes.c b/src/lanes.c
index 1d60700..7f641c3 100644
--- a/src/lanes.c
+++ b/src/lanes.c
@@ -52,7 +52,7 @@
52 * ... 52 * ...
53 */ 53 */
54 54
55char const* VERSION = "3.9.6"; 55char const* VERSION = "3.9.7";
56 56
57/* 57/*
58=============================================================================== 58===============================================================================
diff --git a/src/lanes.lua b/src/lanes.lua
index 57aa0fe..210f325 100644
--- a/src/lanes.lua
+++ b/src/lanes.lua
@@ -331,12 +331,28 @@ end -- gen()
331 331
332-- PUBLIC LANES API 332-- PUBLIC LANES API
333local timer = function() error "timers are not active" end 333local timer = function() error "timers are not active" end
334local timer_lane = nil
335local timers = timer 334local timers = timer
335local timer_lane = nil
336
337-- timer_gateway should always exist, even when the settings disable the timers
338local timer_gateway = assert( core.timer_gateway)
339
340-----
341-- <void> = sleep( [seconds_])
342--
343-- PUBLIC LANES API
344local sleep = function( seconds_)
345 seconds_ = seconds_ or 0.0 -- this causes false and nil to be a valid input, equivalent to 0.0, but that's ok
346 if type( seconds_) ~= "number" then
347 error( "invalid duration " .. string_format( "%q", tostring(seconds_)))
348 end
349 -- receive data on a channel no-one ever sends anything, thus blocking for the specified duration
350 return timer_gateway:receive( seconds_, "ac100de1-a696-4619-b2f0-a26de9d58ab8")
351end
352
336 353
337if settings.with_timers ~= false then 354if settings.with_timers ~= false then
338 355
339local timer_gateway = assert( core.timer_gateway)
340-- 356--
341-- On first 'require "lanes"', a timer lane is spawned that will maintain 357-- On first 'require "lanes"', a timer lane is spawned that will maintain
342-- timer tables and sleep in between the timer events. All interaction with 358-- timer tables and sleep in between the timer events. All interaction with
@@ -351,8 +367,8 @@ local TGW_KEY= "(timer control)" -- the key does not matter, a 'weird' key ma
351local TGW_QUERY, TGW_REPLY = "(timer query)", "(timer reply)" 367local TGW_QUERY, TGW_REPLY = "(timer query)", "(timer reply)"
352local first_time_key= "first time" 368local first_time_key= "first time"
353 369
354local first_time= timer_gateway:get(first_time_key) == nil 370local first_time = timer_gateway:get( first_time_key) == nil
355timer_gateway:set(first_time_key,true) 371timer_gateway:set( first_time_key, true)
356 372
357-- 373--
358-- Timer lane; initialize only on the first 'require "lanes"' instance (which naturally 374-- Timer lane; initialize only on the first 'require "lanes"' instance (which naturally
@@ -703,6 +719,7 @@ end
703 lanes.timer = timer 719 lanes.timer = timer
704 lanes.timer_lane = timer_lane 720 lanes.timer_lane = timer_lane
705 lanes.timers = timers 721 lanes.timers = timers
722 lanes.sleep = sleep
706 lanes.genlock = genlock 723 lanes.genlock = genlock
707 lanes.now_secs = core.now_secs 724 lanes.now_secs = core.now_secs
708 lanes.genatomic = genatomic 725 lanes.genatomic = genatomic