Please wait until the page is fully downloaded and then press the "Expand" button or the blue line numbers.

0028001 /*
0028002 inet/generic/event.c
0028003 
0028004 Created:       April 1995 by Philip Homburg <philip@cs.vu.nl>
0028005 
0028006 Implementation of an event queue.
0028007 
0028008 Copyright 1995 Philip Homburg
0028009 */
0028010 
0028011 #include "inet.h"
0028012 #include "assert.h"
0028013 #include "event.h"
0028014 
0028015 THIS_FILE
0028016 
event_t / ev_enqueue() / ev_process() / ev_init() / ev_in_queue()

The event_t typedef is declared in inet/generic/event.h:

typedef struct event

{
ev_func_t ev_func;
ev_arg_t ev_arg;
struct event *ev_next;
} event_t;
If an event needs to be scheduled, ev_enqueue() is called to place the event in the system-wide event queue whose head is ev_head. ev_process() is eventually called from the main loop in inet.c to process the events. ev_in_queue(ev) simply returns TRUE if the event ev, ev_in_queue()'s only parameter, has a non-null value for func (see below) and FALSE if func is null. In this way, ev_in_queue() determines whether the event has been configured.

ev_init(ev) simply zeroes out the ev_func and ev_next fields of the event ev, ev_init()'s only parameter.

ev_func: A function (e.g., ip_process_loopb()) that performs some task.

ev_arg:

typedef union ev_arg

{
int ev_int;
void *ev_ptr;
} ev_arg_t;
ev_arg is ev_func's argument. In the case of a packet destined for the loopback address (127.0.0.1), the argument will be the ip port associated with the ip file descriptor that is sending out the packet. In the case of a message from the ethernet task that caused a deadlock, ev_arg is a pointer to the message's destination ethernet port.

ev_next: The next event in the system-wide event queue.


0028017 event_t *ev_head;
0028018 static event_t *ev_tail;
"ev" stands for "event."


0028019 
0028020 void ev_init(ev)
0028021 event_t *ev;
0028022 {
0028023          ev->ev_func= 0;
0028024          ev->ev_next= NULL;
0028025 }
0028026 
0028027 void ev_enqueue(ev, func, ev_arg)
0028028 event_t *ev;
0028029 ev_func_t func;
0028030 ev_arg_t ev_arg;
Place the event at the tail of the system-wide event queue.


0028031 {
0028032          assert(ev->ev_func == 0);
0028033          ev->ev_func= func;
0028034          ev->ev_arg= ev_arg;
0028035          ev->ev_next= NULL;
0028036          if (ev_head == NULL)
0028037                   ev_head= ev;
0028038          else
0028039                   ev_tail->ev_next= ev;
0028040          ev_tail= ev;
0028041 }
0028042 
0028043 void ev_process()
ev_process() is used to process the event queue. This function is called from the main loop of inet.c.

Go through each of the events, calling each event's function with the event's arguments.


0028044 {
0028045          ev_func_t func;
0028046          event_t *curr;
0028047 
0028048          while (ev_head)
0028049          {
0028050                   curr= ev_head;
0028051                   ev_head= curr->ev_next;
0028052                   func= curr->ev_func;
0028053                   curr->ev_func= 0;
0028054 
0028055                   assert(func != 0);
0028056                   func(curr, curr->ev_arg);
An example of func is ip_process_loopb(). Its argument will be the ip port associated with the ip file descriptor that is sending out the packet.


0028057          }
0028058 }
0028059 
0028060 int ev_in_queue(ev)
0028061 event_t *ev;
0028062 {
0028063          return ev->ev_func != 0;
0028064 }
0028065 
0028066 
0028067 /*
0028068  * $PchId: event.c,v 1.4 1995/11/21 06:45:27 philip Exp $
0028069  */