00001 /* 00002 * $Id: cq.h,v 1.5 2005/09/16 21:58:03 rmanfredi Exp $ 00003 * 00004 * Copyright (c) 2002-2003, Raphael Manfredi 00005 * 00006 *---------------------------------------------------------------------- 00007 * This file is part of gtk-gnutella. 00008 * 00009 * gtk-gnutella is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * gtk-gnutella is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with gtk-gnutella; if not, write to the Free Software 00021 * Foundation, Inc.: 00022 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 *---------------------------------------------------------------------- 00024 */ 00025 00036 #ifndef _cq_h_ 00037 #define _cq_h_ 00038 00039 #include <glib.h> 00040 00041 struct cqueue; 00042 00043 typedef void (*cq_service_t)(struct cqueue *cq, gpointer obj); 00044 00048 typedef struct cevent { 00049 struct cevent *ce_bnext; 00050 struct cevent *ce_bprev; 00051 cq_service_t ce_fn; 00052 gpointer ce_arg; 00053 time_t ce_time; 00054 guint ce_magic; 00055 } cevent_t; 00056 00082 struct chash { 00083 cevent_t *ch_head; 00084 cevent_t *ch_tail; 00085 }; 00086 00087 typedef struct cqueue { 00088 struct chash *cq_hash; 00089 time_t cq_time; 00090 gint cq_ticks; 00091 gint cq_items; 00092 gint cq_last_bucket; 00093 struct chash *cq_current; 00094 } cqueue_t; 00095 00096 #define cq_ticks(x) ((x)->cq_ticks) 00097 00098 /* 00099 * Interface routines. 00100 */ 00101 00102 extern cqueue_t *callout_queue; /* Single global instance */ 00103 00104 gdouble callout_queue_coverage(gint old_ticks); 00105 00106 void cq_init(void); 00107 void cq_close(void); 00108 00109 cqueue_t *cq_make(time_t now); 00110 void cq_free(cqueue_t *cq); 00111 gpointer cq_insert(cqueue_t *cq, gint delay, cq_service_t fn, gpointer arg); 00112 void cq_expire(cqueue_t *cq, cevent_t *ev); 00113 void cq_cancel(cqueue_t *cq, gpointer handle); 00114 void cq_resched(cqueue_t *cq, gpointer handle, gint delay); 00115 void cq_clock(cqueue_t *cq, gint elapsed); 00116 00117 #endif /* _cq_h_ */ 00118 00119 /* vi: set ts=4: */