Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4ab2521
timing
Uglymotha May 8, 2020
9fbfe5f
config.h to top
Uglymotha May 9, 2020
5dd7a68
Remove unused variables from reloadconfig()
Uglymotha May 9, 2020
26489a0
IfDesc.index -> signed
Uglymotha May 9, 2020
4a1d330
vifindex -> signed
Uglymotha May 9, 2020
822b619
vifindex / upstrvif -> signed
Uglymotha May 9, 2020
1c6340b
upstrvif -> signed
Uglymotha May 9, 2020
d0fa83a
vifindex -> signed
Uglymotha May 9, 2020
d44ad8a
if (upsvifcount >= MAX_UPS_VIFS)
Uglymotha May 9, 2020
e5ed28f
reintroduce use of confg variable
Uglymotha May 9, 2020
1b7f553
ifdp->index -> signed
Uglymotha May 10, 2020
5c26021
function definition - includes
Uglymotha May 10, 2020
4ba9b43
style fixes
Uglymotha May 10, 2020
4b98f3c
style fixes
Uglymotha May 10, 2020
bed0b9d
style fixes
Uglymotha May 10, 2020
8a495ae
style fixes
Uglymotha May 10, 2020
1db3ae3
style fixes
Uglymotha May 10, 2020
53cdf60
style fixes
Uglymotha May 10, 2020
0b08284
style fixes
Uglymotha May 10, 2020
fab1b19
style fixes
Uglymotha May 10, 2020
f55af10
style fixes
Uglymotha May 10, 2020
cc47744
style fixes
Uglymotha May 10, 2020
7e08496
style fixes
Uglymotha May 10, 2020
0c17249
clearroutes
Uglymotha May 10, 2020
f365de4
clearroutes
Uglymotha May 10, 2020
b19a4b1
clearroutes
Uglymotha May 10, 2020
e7fd153
style fixes
Uglymotha May 10, 2020
9df9e7d
clearroutes
Uglymotha May 10, 2020
3939a26
style fixes
Uglymotha May 10, 2020
aed9314
index unsinged
Uglymotha May 11, 2020
7114b67
compare index unsinged -1
Uglymotha May 11, 2020
798b4cf
vifindex unsigned
Uglymotha May 11, 2020
af06070
vifindex unsigned
Uglymotha May 11, 2020
2c19ff7
index unsigned-1
Uglymotha May 11, 2020
2d58db6
remove joinmcrouters
Uglymotha May 12, 2020
b082eec
clearroutes instead of initroutetable
Uglymotha May 12, 2020
a64fd02
remove initroutetable()
Uglymotha May 12, 2020
68d5bf0
remove joinmcrroutergroup fro createvifs()
Uglymotha May 12, 2020
f13f139
configurevifs ix unsigned
Uglymotha May 12, 2020
5f26f14
typo
Uglymotha May 12, 2020
bed8ecd
remove joinmcrouters
Uglymotha May 12, 2020
c947ab7
Syncd changes with master branch
Uglymotha May 19, 2020
10f044d
Syncd changes with master branch
Uglymotha May 19, 2020
68e69d5
Syncd changes with master branch
Uglymotha May 19, 2020
6c3bed1
Syncd changes with master branch
Uglymotha May 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 46 additions & 160 deletions src/callout.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,91 +37,48 @@

/* the code below implements a callout queue */
static int id = 0;
static struct timeOutQueue *queue = 0; /* pointer to the beginning of timeout queue */
static struct timeOutQueue *queue = NULL; /* pointer to the beginning of timeout queue */

struct timeOutQueue {
struct timeOutQueue *next; // Next event in queue
int id;
timer_f func; // function to call
void *data; // Data for function
int time; // Time offset for next event
long time; // Time for event
struct timeOutQueue *next; // Next event in queue
};

// Method for dumping the Queue to the log.
static void debugQueue(void);

/**
* Initializes the callout queue
*/
void callout_init(void) {
queue = NULL;
}

/**
* Clears all scheduled timeouts...
*/
void free_all_callouts(void) {
struct timeOutQueue *p;

while (queue) {
p = queue;
queue = queue->next;
free(p);
for (p = queue ? queue->next : NULL; queue; queue = p, p = queue->next) {
free(queue); // Alloced by timer_setTimer()
}
}


/**
* elapsed_time seconds have passed; perform all the events that should
* happen.
* Execute all expired timers, using .5s grace.
*/
void age_callout_queue(int elapsed_time) {
struct timeOutQueue *ptr;
struct timeOutQueue *_queue = NULL;
struct timeOutQueue *last = NULL;
int i = 0;

for (ptr = queue; ptr; ptr = ptr->next) {
if (ptr->time > elapsed_time) {
ptr->time -= elapsed_time;
break;
} else {
elapsed_time -= ptr->time;
if (_queue == NULL)
_queue = ptr;
last = ptr;
}
}

queue = ptr;
if (last) {
last->next = NULL;
}

/* process existing events */
for (ptr = _queue; ptr; ptr = _queue, i++) {
_queue = _queue->next;
void age_callout_queue(struct timespec curtime) {
struct timeOutQueue *ptr = queue;
int i = 1;

if (curtime.tv_sec == 0) clock_gettime (CLOCK_MONOTONIC, &curtime);
while (ptr && ((ptr->time <= curtime.tv_sec) || (curtime.tv_nsec >= 500000000 && ptr->time <= curtime.tv_sec-1))) {
my_log(LOG_DEBUG, 0, "About to call timeout %d (#%d)", ptr->id, i);
if (ptr->func)
ptr->func(ptr->data);
free(ptr);
}
}

/**
* Return in how many seconds age_callout_queue() would like to be called.
* Return -1 if there are no events pending.
*/
int timer_nextTimer(void) {
if (queue) {
if (queue->time < 0) {
my_log(LOG_WARNING, 0, "timer_nextTimer top of queue says %d",
queue->time);
return 0;
struct timeOutQueue *tmp = ptr;
if (ptr->func) {
ptr->func(ptr->data);
}
return queue->time;
queue = ptr = ptr->next;
free(tmp); // Alloced by timer_setTimer()
i++;
}
return -1;
}

/**
Expand All @@ -131,61 +88,40 @@ int timer_nextTimer(void) {
* @param data - Pointer to the function data to supply...
*/
int timer_setTimer(int delay, timer_f action, void *data) {
struct timeOutQueue *ptr, *node, *prev;
int i = 0;
struct timeOutQueue *ptr = queue, *node;
struct timespec curtime;
int i = 1;

/* create a node */
// create a node. Freed by free_all_callouts() and age_callout_queue().
node = (struct timeOutQueue *)malloc(sizeof(struct timeOutQueue));
if (node == 0) {
if (! node) {
my_log(LOG_WARNING, 0, "Malloc Failed in timer_settimer\n");
return -1;
}
clock_gettime(CLOCK_MONOTONIC, &curtime);
node->func = action;
node->data = data;
node->time = delay;
node->next = 0;
node->time = curtime.tv_sec + delay;
node->id = ++id;
node->next = NULL;

prev = ptr = queue;

/* insert node in the queue */

/* if the queue is empty, insert the node and return */
if (!queue) {
if (! queue) {
// if the queue is empty, insert the node and return.
queue = node;
}
else {
/* chase the pointer looking for the right place */
while (ptr) {
if (delay < ptr->time) {
// We found the correct node
node->next = ptr;
if (ptr == queue) {
queue = node;
}
else {
prev->next = node;
}
ptr->time -= node->time;
my_log(LOG_DEBUG, 0,
"Created timeout %d (#%d) - delay %d secs",
node->id, i, node->time);
debugQueue();
return node->id;
} else {
// Continur to check nodes.
delay -= ptr->time; node->time = delay;
prev = ptr;
ptr = ptr->next;
}
i++;
} else {
// chase the queue looking for the right place.
for (i++; ptr->next && node->time >= ptr->next->time; ptr = ptr->next, i++);
if (ptr == queue && node->time < ptr->time) {
// Start of queue, insert.
queue = node;
node->next = ptr;
} else {
node->next = ptr->next;
ptr->next = node;
}
prev->next = node;
}
my_log(LOG_DEBUG, 0, "Created timeout %d (#%d) - delay %d secs",
node->id, i, node->time);
debugQueue();

my_log(LOG_DEBUG, 0, "Created timeout %d (#%d) - delay %d secs", node->id, i, delay);
return node->id;
}

Expand All @@ -194,76 +130,26 @@ int timer_setTimer(int delay, timer_f action, void *data) {
*/
int timer_leftTimer(int timer_id) {
struct timeOutQueue *ptr;
int left = 0;

if (!timer_id)
return -1;
struct timespec curtime;

if (!timer_id || !queue) return -1;
for (ptr = queue; ptr; ptr = ptr->next) {
left += ptr->time;
if (ptr->id == timer_id) {
return left;
clock_gettime(CLOCK_MONOTONIC, &curtime);
return (ptr->time - curtime.tv_sec);
}
}
return -1;
}

/**
* clears the associated timer. Returns 1 if succeeded.
*/
int timer_clearTimer(int timer_id) {
struct timeOutQueue *ptr, *prev;
int i = 0;

if (!timer_id)
return 0;

prev = ptr = queue;

/*
* find the right node, delete it. the subsequent node's time
* gets bumped up
*/

debugQueue();
while (ptr) {
if (ptr->id == timer_id) {
/* got the right node */

/* unlink it from the queue */
if (ptr == queue)
queue = queue->next;
else
prev->next = ptr->next;

/* increment next node if any */
if (ptr->next != 0)
(ptr->next)->time += ptr->time;

if (ptr->data)
free(ptr->data);
my_log(LOG_DEBUG, 0, "deleted timer %d (#%d)", ptr->id, i);
free(ptr);
debugQueue();
return 1;
}
prev = ptr;
ptr = ptr->next;
i++;
}
// If we get here, the timer was not deleted.
my_log(LOG_DEBUG, 0, "failed to delete timer %d (#%d)", timer_id, i);
debugQueue();
return 0;
}

/**
* debugging utility
*/
static void debugQueue(void) {
struct timeOutQueue *ptr;
int i;

for (ptr = queue; ptr; ptr = ptr->next) {
my_log(LOG_DEBUG, 0, "(Id:%d, Time:%d) ", ptr->id, ptr->time);
for (i = 1, ptr = queue; ptr; ptr = ptr->next, i++) {
my_log(LOG_DEBUG, 0, "(%d - Id:%d, Time:%d) ", i, ptr->id, ptr->time);
}
}
Loading