lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Poking a bit more in lanes I found some more bugs, and made a few
patches.

First small fix so that lanes_h:cancel() behave as it is described in
documentation (return a boolean value) [1]

Second patch fixes problem that timers got blocked sometimes.
It was possible for secs variable to get negative value. [2]

And third patch fix the function prepare_timeout(ts, abs_secs).
It would sometimes set ts->tv_nsec field to 1000000000 which
is illegal. [3]

Now it function much more stable with my test program.

By and HAPPY NEW YEAR to all
Martin


[1]
diff -r 7e1bd437cd34 -r 556d52394b9c src/lanes.lua
--- a/src/lanes.lua	Wed Dec 29 22:05:16 2010 +0100
+++ b/src/lanes.lua	Wed Dec 29 22:05:16 2010 +0100
@@ -312,9 +312,9 @@
     local proxy= {
         _ud= ud,
         
-        -- void= me:cancel()
+        -- true|false= me:cancel()
         --
-        cancel= function(me, time, force) thread_cancel(me._ud, time, force) end,
+        cancel= function(me, time, force) return thread_cancel(me._ud, time, force) end,
         
         -- [...] | [nil,err,stack_tbl]= me:join( [wait_secs=-1] )
         --

[2]
diff -r 556d52394b9c -r 5d70a0ec04b8 src/lanes.lua
--- a/src/lanes.lua	Wed Dec 29 22:05:16 2010 +0100
+++ b/src/lanes.lua	Wed Dec 29 22:05:17 2010 +0100
@@ -512,7 +512,11 @@
 
             -- Sleep until next timer to wake up, or a set/clear command
             --
-            local secs= next_wakeup and (next_wakeup - now_secs()) or nil
+            local secs
+            if next_wakeup then
+                secs =  next_wakeup - now_secs()
+                if secs < 0 then secs = 0 end
+            end
             local linda= timer_gateway:receive( secs, TGW_KEY )
 
             if linda then

[3]
diff -r 5d70a0ec04b8 -r d0c292a4f3af src/threading.c
--- a/src/threading.c	Wed Dec 29 22:05:17 2010 +0100
+++ b/src/threading.c	Wed Dec 29 23:46:44 2010 +0100
@@ -178,6 +178,10 @@
 
     ts->tv_sec= floor( abs_secs );
     ts->tv_nsec= ((long)((abs_secs - ts->tv_sec) * 1000.0 +0.5)) * 1000000UL;   // 1ms = 1000000ns
+    if (ts->tv_nsec == 1000000000UL) {
+            ts->tv_nsec = 0;
+            ts->tv_sec = ts->tv_sec + 1;
+    }
 }
 #endif