aboutsummaryrefslogtreecommitdiffstats
path: root/sched.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-07-27 03:53:19 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-07-27 03:53:19 +0000
commit8ce804e1c170fd3453ed44cdf87b432ca62a5f5d (patch)
treea888911cd363f6eb762ac97ff84601c76ecd59a8 /sched.c
parent1c6679d139e95613dac651bdb8700017e7a425d6 (diff)
Merge / correct MM's patches
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@1227 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'sched.c')
-rwxr-xr-xsched.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/sched.c b/sched.c
index f3841e399..6744a7f99 100755
--- a/sched.c
+++ b/sched.c
@@ -180,13 +180,36 @@ static void schedule(struct sched_context *con, struct sched *s)
static inline int sched_settime(struct timeval *tv, int when)
{
- if (gettimeofday(tv, NULL) < 0) {
- /* This shouldn't ever happen, but let's be sure */
- ast_log(LOG_NOTICE, "gettimeofday() failed!\n");
- return -1;
+ struct timeval tv_tmp;
+ long error_sec, error_usec;
+
+ if (gettimeofday(&tv_tmp, NULL) < 0) {
+ /* This shouldn't ever happen, but let's be sure */
+ ast_log(LOG_NOTICE, "gettimeofday() failed!\n");
+ return -1;
+ }
+ /*ast_log(LOG_DEBUG, "TV -> %lu,%lu\n", tv->tv_sec, tv->tv_usec);*/
+ if (((unsigned long)(tv->tv_sec) > 0)&&((unsigned long)(tv->tv_usec) > 0)) {
+ if ((unsigned long)(tv_tmp.tv_usec) < (unsigned long)(tv->tv_usec)) {
+ tv_tmp.tv_usec += 1000000;
+ tv_tmp.tv_sec -= 1;
+ }
+ error_sec = (unsigned long)(tv_tmp.tv_sec) - (unsigned long)(tv->tv_sec);
+ error_usec = (unsigned long)(tv_tmp.tv_usec) - (unsigned long)(tv->tv_usec);
+ } else {
+ /*ast_log(LOG_DEBUG, "Initializing error\n");*/
+ error_sec = 0;
+ error_usec = 0;
+ }
+ /*ast_log(LOG_DEBUG, "ERROR -> %lu,%lu\n", error_sec, error_usec);*/
+ if (error_sec * 1000 + error_usec / 1000 < when) {
+ tv->tv_sec = tv_tmp.tv_sec + (when/1000 - error_sec);
+ tv->tv_usec = tv_tmp.tv_usec + ((when % 1000) * 1000 - error_usec);
+ } else {
+ ast_log(LOG_NOTICE, "Request to schedule in the past?!?!\n");
+ tv->tv_sec = tv_tmp.tv_sec;
+ tv->tv_usec = tv_tmp.tv_usec;
}
- tv->tv_sec += when/1000;
- tv->tv_usec += (when % 1000) * 1000;
if (tv->tv_usec > 1000000) {
tv->tv_sec++;
tv->tv_usec-= 1000000;
@@ -210,6 +233,8 @@ int ast_sched_add(struct sched_context *con, int when, ast_sched_cb callback, vo
tmp->callback = callback;
tmp->data = data;
tmp->resched = when;
+ tmp->when.tv_sec = 0;
+ tmp->when.tv_usec = 0;
if (sched_settime(&tmp->when, when)) {
sched_release(con, tmp);
return -1;