modules/pike/timer.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <assert.h>
00030
00031 #include "../../dprint.h"
00032 #include "timer.h"
00033 #include "ip_tree.h"
00034
00035
00036
00037 void append_to_timer(struct list_link *head, struct list_link *new_ll )
00038 {
00039 LM_DBG("%p in %p(%p,%p)\n", new_ll, head,head->prev,head->next);
00040 assert( !has_timer_set(new_ll) );
00041
00042 new_ll->prev = head->prev;
00043 head->prev->next = new_ll;
00044 head->prev = new_ll;
00045 new_ll->next = head;
00046 }
00047
00048
00049
00050 void remove_from_timer(struct list_link *head, struct list_link *ll)
00051 {
00052 LM_DBG("%p from %p(%p,%p)\n", ll, head,head->prev,head->next);
00053 assert( has_timer_set(ll) );
00054
00055 ll->next->prev = ll->prev;
00056 ll->prev->next = ll->next;
00057
00058 ll->next = ll->prev = 0;
00059 }
00060
00061
00062
00063
00064 void check_and_split_timer(struct list_link *head, unsigned int time,
00065 struct list_link *split, unsigned char *mask)
00066 {
00067 struct list_link *ll;
00068 struct ip_node *node;
00069 unsigned char b;
00070 int i;
00071
00072
00073 for(i=0;i<32;mask[i++]=0);
00074
00075 ll = head->next;
00076 while( ll!=head && (node=ll2ipnode(ll))->expires<=time) {
00077 LM_DBG("splitting %p(%p,%p)node=%p\n", ll,ll->prev,ll->next, node);
00078
00079 node->flags |= NODE_EXPIRED_FLAG;
00080 node->flags &= ~NODE_INTIMER_FLAG;
00081 b = node->branch;
00082 ll=ll->next;
00083
00084 mask[b>>3] |= (1<<(b&0x07));
00085 }
00086
00087 if (ll==head->next) {
00088
00089 split->next = split->prev = split;
00090 } else {
00091
00092 split->next = head->next;
00093 split->next->prev = split;
00094
00095 split->prev = ll->prev;
00096 split->prev->next = split;
00097
00098 head->next = ll;
00099 ll->prev = head;
00100 }
00101
00102 LM_DBG("succ. to split (h=%p)(p=%p,n=%p)\n", head,head->prev,head->next);
00103 return;
00104 }
00105
00106
00107
00108