modules/pike/timer.c

Go to the documentation of this file.
00001 /* 
00002  * $Id: timer.c 4518 2008-07-28 15:39:28Z henningw $
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of Kamailio, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License 
00019  * along with this program; if not, write to the Free Software 
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  * History:
00023  * --------
00024  *  2005-05-02  flags field added to node stucture -better sync between timer
00025  *              and worker processes; some races eliminated (bogdan)
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 /* "head" list MUST not be empty */
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    /*  reset the mask */
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       /* mark the node as expired and un-mark it as being in timer list */
00079       node->flags |= NODE_EXPIRED_FLAG;
00080       node->flags &= ~NODE_INTIMER_FLAG;
00081       b = node->branch;
00082       ll=ll->next;
00083       /*LM_DBG("b=%d; [%d,%d]\n",   b,b>>3,1<<(b&0x07));*/
00084       mask[b>>3] |= (1<<(b&0x07));
00085    }
00086 
00087    if (ll==head->next) {
00088       /* nothing to return */
00089       split->next = split->prev = split;
00090    } else {
00091       /* the detached list begins with current beginning */
00092       split->next = head->next;
00093       split->next->prev = split;
00094       /* and we mark the end of the split list */
00095       split->prev = ll->prev;
00096       split->prev->next = split;
00097       /* the shortened list starts from where we suspended */
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 

Generated on Wed May 23 20:00:32 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6