Merge / correct MM's patches

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1227 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2003-07-27 03:53:19 +00:00
parent 7a594ca15d
commit 27d3190aa2
2 changed files with 80 additions and 11 deletions

37
sched.c
View File

@@ -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;