summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sandglass.c8
-rw-r--r--src/sandglass.h3
2 files changed, 8 insertions, 3 deletions
diff --git a/src/sandglass.c b/src/sandglass.c
index 3399b73..c63e2a0 100644
--- a/src/sandglass.c
+++ b/src/sandglass.c
@@ -186,7 +186,7 @@ sandglass_elapse(sandglass_t *sandglass)
sandglass->grains -= oldgrains;
/* Magical correction for timespec-based grains */
if (sandglass->grains < 0)
- sandglass->grains += 2000000000L;
+ sandglass->grains += sandglass->adjustment;
sandglass->grains /= sandglass->loops;
return 0;
@@ -226,7 +226,8 @@ sandglass_real_gettime(sandglass_t *sandglass)
if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
return -1;
}
- sandglass->grains = sandglass_timespec_grains(&ts);
+ sandglass->grains = sandglass_timespec_grains(&ts);
+ sandglass->adjustment = 2000000000L;
break;
default:
@@ -249,7 +250,8 @@ sandglass_real_gettime(sandglass_t *sandglass)
return -1;
} else
return -1;
- sandglass->grains = sandglass_timespec_grains(&ts);
+ sandglass->grains = sandglass_timespec_grains(&ts);
+ sandglass->adjustment = 2000000000L;
break;
case SANDGLASS_SYSTEM:
diff --git a/src/sandglass.h b/src/sandglass.h
index 3cd14ba..7073fb9 100644
--- a/src/sandglass.h
+++ b/src/sandglass.h
@@ -99,6 +99,9 @@ struct sandglass_t
* Internal fields
*/
+ /* Adjustment to be added for negative (i.e. overflowed) grains counts */
+ long adjustment;
+
/* For SANDGLASS_TICKS looping support */
unsigned int i, loops;
};