diff options
author | Benoit Germain <bnt period germain arrobase gmail period com> | 2014-09-18 16:49:31 +0200 |
---|---|---|
committer | Benoit Germain <bnt period germain arrobase gmail period com> | 2014-09-18 16:49:31 +0200 |
commit | 2f7fbc306431a02a6f247148ebbda17b4c2d98f7 (patch) | |
tree | bb3a912def9f28a86a8d5d6291d3bd6334bed744 | |
parent | 0326aa6636b1dce2b2fc4c9db53b023534ca0512 (diff) | |
download | lanes-2f7fbc306431a02a6f247148ebbda17b4c2d98f7.tar.gz lanes-2f7fbc306431a02a6f247148ebbda17b4c2d98f7.tar.bz2 lanes-2f7fbc306431a02a6f247148ebbda17b4c2d98f7.zip |
New API lanes.sleep (bumped version to 3.9.7)
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | docs/index.html | 10 | ||||
-rw-r--r-- | src/lanes.c | 2 | ||||
-rw-r--r-- | src/lanes.lua | 25 |
4 files changed, 35 insertions, 6 deletions
@@ -1,5 +1,9 @@ | |||
1 | CHANGES: | 1 | CHANGES: |
2 | 2 | ||
3 | CHANGE 115: BGe 18-sep-14 | ||
4 | * bumped version to 3.9.7 | ||
5 | * new function lanes.sleep() | ||
6 | |||
3 | CHANGE 114: BGe 8-Jul-14 | 7 | CHANGE 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 | ||
55 | char const* VERSION = "3.9.6"; | 55 | char 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 |
333 | local timer = function() error "timers are not active" end | 333 | local timer = function() error "timers are not active" end |
334 | local timer_lane = nil | ||
335 | local timers = timer | 334 | local timers = timer |
335 | local timer_lane = nil | ||
336 | |||
337 | -- timer_gateway should always exist, even when the settings disable the timers | ||
338 | local timer_gateway = assert( core.timer_gateway) | ||
339 | |||
340 | ----- | ||
341 | -- <void> = sleep( [seconds_]) | ||
342 | -- | ||
343 | -- PUBLIC LANES API | ||
344 | local 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") | ||
351 | end | ||
352 | |||
336 | 353 | ||
337 | if settings.with_timers ~= false then | 354 | if settings.with_timers ~= false then |
338 | 355 | ||
339 | local 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 | |||
351 | local TGW_QUERY, TGW_REPLY = "(timer query)", "(timer reply)" | 367 | local TGW_QUERY, TGW_REPLY = "(timer query)", "(timer reply)" |
352 | local first_time_key= "first time" | 368 | local first_time_key= "first time" |
353 | 369 | ||
354 | local first_time= timer_gateway:get(first_time_key) == nil | 370 | local first_time = timer_gateway:get( first_time_key) == nil |
355 | timer_gateway:set(first_time_key,true) | 371 | timer_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 |