mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-09 03:18:30 +00:00
make some counter variables unsigned, use ast_tvcmp instead of a custom
SOONER macro, and some other little cleanups for things like indentation git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@37457 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
33
sched.c
33
sched.c
@@ -50,10 +50,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|||||||
#include "asterisk/linkedlists.h"
|
#include "asterisk/linkedlists.h"
|
||||||
#include "asterisk/options.h"
|
#include "asterisk/options.h"
|
||||||
|
|
||||||
/* Determine if a is sooner than b */
|
|
||||||
#define SOONER(a,b) (((b).tv_sec > (a).tv_sec) || \
|
|
||||||
(((b).tv_sec == (a).tv_sec) && ((b).tv_usec > (a).tv_usec)))
|
|
||||||
|
|
||||||
struct sched {
|
struct sched {
|
||||||
AST_LIST_ENTRY(sched) list;
|
AST_LIST_ENTRY(sched) list;
|
||||||
int id; /*!< ID number of event */
|
int id; /*!< ID number of event */
|
||||||
@@ -66,13 +62,13 @@ struct sched {
|
|||||||
|
|
||||||
struct sched_context {
|
struct sched_context {
|
||||||
ast_mutex_t lock;
|
ast_mutex_t lock;
|
||||||
int eventcnt; /*!< Number of events processed */
|
unsigned int eventcnt; /*!< Number of events processed */
|
||||||
int schedcnt; /*!< Number of outstanding schedule events */
|
unsigned int schedcnt; /*!< Number of outstanding schedule events */
|
||||||
AST_LIST_HEAD_NOLOCK(, sched) schedq; /*!< Schedule entry and main queue */
|
AST_LIST_HEAD_NOLOCK(, sched) schedq; /*!< Schedule entry and main queue */
|
||||||
|
|
||||||
#ifdef SCHED_MAX_CACHE
|
#ifdef SCHED_MAX_CACHE
|
||||||
AST_LIST_HEAD_NOLOCK(, sched) schedc; /*!< Cache of unused schedule structures and how many */
|
AST_LIST_HEAD_NOLOCK(, sched) schedc; /*!< Cache of unused schedule structures and how many */
|
||||||
int schedccnt;
|
unsigned int schedccnt;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -180,7 +176,7 @@ static void schedule(struct sched_context *con, struct sched *s)
|
|||||||
struct sched *cur = NULL;
|
struct sched *cur = NULL;
|
||||||
|
|
||||||
AST_LIST_TRAVERSE_SAFE_BEGIN(&con->schedq, cur, list) {
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&con->schedq, cur, list) {
|
||||||
if (SOONER(s->when, cur->when)) {
|
if (ast_tvcmp(s->when, cur->when) == 1) {
|
||||||
AST_LIST_INSERT_BEFORE_CURRENT(&con->schedq, s, list);
|
AST_LIST_INSERT_BEFORE_CURRENT(&con->schedq, s, list);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -329,22 +325,23 @@ int ast_sched_runq(struct sched_context *con)
|
|||||||
{
|
{
|
||||||
struct sched *current;
|
struct sched *current;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
int x=0;
|
int numevents;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
DEBUG(ast_log(LOG_DEBUG, "ast_sched_runq()\n"));
|
DEBUG(ast_log(LOG_DEBUG, "ast_sched_runq()\n"));
|
||||||
|
|
||||||
ast_mutex_lock(&con->lock);
|
ast_mutex_lock(&con->lock);
|
||||||
for (;;) {
|
|
||||||
if (AST_LIST_EMPTY(&con->schedq))
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
for (numevents = 0; !AST_LIST_EMPTY(&con->schedq); numevents++) {
|
||||||
/* schedule all events which are going to expire within 1ms.
|
/* schedule all events which are going to expire within 1ms.
|
||||||
* We only care about millisecond accuracy anyway, so this will
|
* We only care about millisecond accuracy anyway, so this will
|
||||||
* help us get more than one event at one time if they are very
|
* help us get more than one event at one time if they are very
|
||||||
* close together.
|
* close together.
|
||||||
*/
|
*/
|
||||||
tv = ast_tvadd(ast_tvnow(), ast_tv(0, 1000));
|
tv = ast_tvadd(ast_tvnow(), ast_tv(0, 1000));
|
||||||
if (SOONER(AST_LIST_FIRST(&con->schedq)->when, tv)) {
|
if (ast_tvcmp(AST_LIST_FIRST(&con->schedq)->when, tv) != 1)
|
||||||
|
break;
|
||||||
|
|
||||||
current = AST_LIST_REMOVE_HEAD(&con->schedq, list);
|
current = AST_LIST_REMOVE_HEAD(&con->schedq, list);
|
||||||
con->schedcnt--;
|
con->schedcnt--;
|
||||||
|
|
||||||
@@ -374,18 +371,17 @@ int ast_sched_runq(struct sched_context *con)
|
|||||||
/* No longer needed, so release it */
|
/* No longer needed, so release it */
|
||||||
sched_release(con, current);
|
sched_release(con, current);
|
||||||
}
|
}
|
||||||
x++;
|
|
||||||
} else
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_mutex_unlock(&con->lock);
|
ast_mutex_unlock(&con->lock);
|
||||||
return x;
|
|
||||||
|
return numevents;
|
||||||
}
|
}
|
||||||
|
|
||||||
long ast_sched_when(struct sched_context *con,int id)
|
long ast_sched_when(struct sched_context *con,int id)
|
||||||
{
|
{
|
||||||
struct sched *s;
|
struct sched *s;
|
||||||
long secs;
|
long secs = -1;
|
||||||
DEBUG(ast_log(LOG_DEBUG, "ast_sched_when()\n"));
|
DEBUG(ast_log(LOG_DEBUG, "ast_sched_when()\n"));
|
||||||
|
|
||||||
ast_mutex_lock(&con->lock);
|
ast_mutex_lock(&con->lock);
|
||||||
@@ -393,7 +389,6 @@ long ast_sched_when(struct sched_context *con,int id)
|
|||||||
if (s->id == id)
|
if (s->id == id)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
secs = -1;
|
|
||||||
if (s) {
|
if (s) {
|
||||||
struct timeval now = ast_tvnow();
|
struct timeval now = ast_tvnow();
|
||||||
secs = s->when.tv_sec - now.tv_sec;
|
secs = s->when.tv_sec - now.tv_sec;
|
||||||
|
|||||||
Reference in New Issue
Block a user