]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
dont let value dip below 0
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 19 Jan 2010 18:23:18 +0000 (18:23 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 19 Jan 2010 18:23:18 +0000 (18:23 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16409 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/switch_time.c

index c3e0dd3c12eae71afba84550c6b5c995ad9196ec..60eca8988909e25d72ce679acdc86defab483a50 100644 (file)
@@ -181,7 +181,7 @@ SWITCH_DECLARE(void) switch_time_calibrate_clock(void)
 {
        int x;
        switch_interval_time_t avg, val = 1000, want = 1000;
-       int over = 0, under = 0, good = 0, step = 50, diff = 0;
+       int over = 0, under = 0, good = 0, step = 50, diff = 0, retry = 0;
 
 #ifdef HAVE_CLOCK_GETRES
        struct timespec ts;
@@ -196,6 +196,10 @@ SWITCH_DECLARE(void) switch_time_calibrate_clock(void)
        }
 #endif
 
+ top:
+       val = 1000;
+       step = 50;
+       over = under = good = 0;
        OFFSET = 0;
        
        for (x = 0; x < 100; x++) {
@@ -221,11 +225,19 @@ SWITCH_DECLARE(void) switch_time_calibrate_clock(void)
                } else if (avg > want) {
                        if (under) {calc_step();}
                        under = good = 0;
+                       if ((val - step) < 0) {
+                               if (++retry > 2) break;
+                               goto top;
+                       }
                        val -= step;
                        over++;
                } else if (avg < want) {
                        if (over) {calc_step();}
                        over = good = 0;
+                       if ((val - step) < 0) {
+                               if (++retry > 2) break;
+                               goto top;
+                       }
                        val += step;
                        under++;
                }