Back to index

courier  0.68.2
pcpdtimer.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 2001 Double Precision, Inc.  See COPYING for
00003 ** distribution information.
00004 */
00005 
00006 
00007 #include "config.h"
00008 #include "pcpdtimer.h"
00009 #include <string.h>
00010 #include <time.h>
00011 
00012 extern struct pcpdtimer *first_timer, *last_timer;
00013 
00014 struct pcpdtimer *first_timer=NULL, *last_timer=NULL;
00015 
00016 void pcpdtimer_install(struct pcpdtimer *p, time_t nseconds)
00017 {
00018        struct pcpdtimer *q;
00019 
00020        if (p->alarm)
00021        {
00022               if (p->prev)
00023                      p->prev->next=p->next;
00024               else
00025                      first_timer=p->next;
00026 
00027               if (p->next)
00028                      p->next->prev=p->prev;
00029               else
00030                      last_timer=p->prev;
00031        }
00032 
00033        time(&p->alarm);
00034        p->alarm += nseconds;
00035 
00036        for (q=first_timer; q; q=q->next)
00037        {
00038               if (q->alarm > p->alarm)
00039                      break;
00040        }
00041 
00042        if (!q)
00043        {
00044               if ((p->prev=last_timer) != 0)
00045                      p->prev->next=p;
00046               else
00047                      first_timer=p;
00048               p->next=0;
00049               last_timer=p;
00050        }
00051        else
00052        {
00053               if ((p->prev=q->prev) != 0)
00054                      p->prev->next=p;
00055               else
00056                      first_timer=p;
00057 
00058               p->next=q;
00059               q->prev=p;
00060        }
00061 }
00062 
00063 void pcpdtimer_triggered(struct pcpdtimer *p)
00064 {
00065        if (!p->alarm)
00066               return;
00067 
00068        if (p->prev)
00069               p->prev->next=p->next;
00070        else
00071               first_timer=p->next;
00072 
00073        if (p->next)
00074               p->next->prev=p->prev;
00075        else
00076               last_timer=p->prev;
00077 
00078        p->alarm=0;
00079 }