Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

cq.c File Reference


Detailed Description

Callout queue.

Author:
Raphael Manfredi
Date:
2002-2003

#include "common.h"
#include "cq.h"
#include "misc.h"
#include "tm.h"
#include "walloc.h"
#include "override.h"

Data Structures

struct  cevent
 Callout queue event. More...
struct  chash
struct  cqueue
 Callout queue descriptor. More...

Defines

#define HASH_SIZE   1024
 Hash list size, must be power of 2.
#define HASH_MASK   (HASH_SIZE - 1)
#define EV_MAGIC   0xc0110172U
 Magic number for event marking.
#define EV_HASH(x)   (((x) >> 5) & HASH_MASK)
#define EV_OVER(x)   (((x) >> 5) & ~HASH_MASK)
#define valid_ptr(a)   (cast_to_gconstpointer(a) > GUINT_TO_POINTER(100U))
#define CALLOUT_PERIOD   100

Functions

cqueue_tcq_make (cq_time_t now)
 Create a new callout queue object.
void cq_free (cqueue_t *cq)
 Free the callout queue and all contained event objects.
void ev_link (cqueue_t *cq, cevent_t *ev)
 Link event into the callout queue.
void ev_unlink (cqueue_t *cq, cevent_t *ev)
 Unlink event from callout queue.
cevent_tcq_insert (cqueue_t *cq, gint delay, cq_service_t fn, gpointer arg)
 Insert a new event in the callout queue and return an opaque handle that can be used to cancel the event.
void cq_cancel (cqueue_t *cq, cevent_t **handle_ptr)
 Cancel a recorded timeout.
void cq_resched (cqueue_t *cq, cevent_t *handle, gint delay)
 Reschedule event at some other point in time.
void cq_expire (cqueue_t *cq, cevent_t *ev)
 Expire timeout by removing it out of the queue and firing its callback.
void cq_clock (cqueue_t *cq, gint elapsed)
 The heartbeat of our callout queue.
gboolean callout_timer (gpointer unused_p)
 Called every CALLOUT_PERIOD to heartbeat the callout queue.
gdouble callout_queue_coverage (gint old_ticks)
 Returns percentage of coverage of the callout timer, i.e.
gint cq_ticks (cqueue_t *cq)
void cq_init (void)
 Initialization.
void cq_close (void)
 Final cleanup.

Variables

cqueue_tcallout_queue


Define Documentation

#define CALLOUT_PERIOD   100
 

#define EV_HASH  )     (((x) >> 5) & HASH_MASK)
 

#define EV_MAGIC   0xc0110172U
 

Magic number for event marking.

#define EV_OVER  )     (((x) >> 5) & ~HASH_MASK)
 

#define HASH_MASK   (HASH_SIZE - 1)
 

#define HASH_SIZE   1024
 

Hash list size, must be power of 2.

#define valid_ptr  )     (cast_to_gconstpointer(a) > GUINT_TO_POINTER(100U))
 


Function Documentation

gdouble callout_queue_coverage gint  old_ticks  ) 
 

Returns percentage of coverage of the callout timer, i.e.

the real amount of ticks we processed divided by the theoretical number, yielding a number between 0.0 and 1.0.

Parameters:
old_ticks the previous amount of processed ticks

gboolean callout_timer gpointer  unused_p  )  [static]
 

Called every CALLOUT_PERIOD to heartbeat the callout queue.

void cq_cancel cqueue_t cq,
cevent_t **  handle_ptr
 

Cancel a recorded timeout.

They give us the opaque handle we returned via cq_insert().

Note:
This routine is also used internally to remove an expired event from the list before firing it off.

void cq_clock cqueue_t cq,
gint  elapsed
 

The heartbeat of our callout queue.

Called to notify us about the elapsed "time" so that we can expire timeouts and maintain our notion of "current time".

NB: The time maintained by the callout queue is "virtual". It's the elapased delay given by regular calls to cq_clock() that define its unit. For gtk-gnutella, the time unit is the millisecond.

void cq_close void   ) 
 

Final cleanup.

void cq_expire cqueue_t cq,
cevent_t ev
 

Expire timeout by removing it out of the queue and firing its callback.

void cq_free cqueue_t cq  ) 
 

Free the callout queue and all contained event objects.

void cq_init void   ) 
 

Initialization.

cevent_t* cq_insert cqueue_t cq,
gint  delay,
cq_service_t  fn,
gpointer  arg
 

Insert a new event in the callout queue and return an opaque handle that can be used to cancel the event.

The event is specified to occur in some "delay" amount of time, at which time we shall call fn(cq, arg), where cq is the callout queue from where we triggered, and arg is an additional argument.

Parameters:
cq The callout queue
delay The delay, expressed in cq's "virtual time" (see cq_clock)
fn The callback function
arg The argument to be passed to the callback function
Returns:
the handle, or NULL on error.

cqueue_t* cq_make cq_time_t  now  ) 
 

Create a new callout queue object.

The 'now' parameter is used to initialize the "current time". Use zero if you don't care...

void cq_resched cqueue_t cq,
cevent_t handle,
gint  delay
 

Reschedule event at some other point in time.

It is the responsibility of the user code to determine that the handle for the event has not yet expired, i.e. that the event has not triggered yet.

gint cq_ticks cqueue_t cq  ) 
 

void ev_link cqueue_t cq,
cevent_t ev
[static]
 

Link event into the callout queue.

void ev_unlink cqueue_t cq,
cevent_t ev
[static]
 

Unlink event from callout queue.


Variable Documentation

cqueue_t* callout_queue
 


Generated on Sat Jun 30 17:53:25 2007 for gtk-gnutella by  doxygen 1.3.9.1