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

event_int.h

Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 2005 by Kevin L. Mitchell <klmitch@mit.edu>
00003 **
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 **
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software
00016 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 **
00018 ** @(#)$Id: event_int.h,v 1.34 2005/12/29 04:33:58 klmitch Exp $
00019 */
00020 #ifndef __include_event_int_h__
00021 #define __include_event_int_h__
00022 
00038 #define __EVENT_LIBRARY__ /* Inside the library */
00039 
00040 #include "config.h"
00041 
00042 #include "_stdint.h"
00043 #include "event_err.h"
00044 #include "event_version.h"
00045 #include "gcc-attrs.h"
00046 #include "event.h"
00047 #include "sock.h"
00048 #include "sig.h"
00049 #include "tim.h"
00050 
00051 #include <stdlib.h> /* for size_t, abort() */
00052 #include <sys/types.h> /* for gettimeofday() */
00053 #include <treeconf/treeconf.h>
00054 
00069 #if !_GCA_PREREQ(3, 0)
00070 # define __builtin_expect(expr, expect)         (expr)
00071 #endif
00072 
00092 #undef _gca_format
00093 #if _GCA_PREREQ(2, 4)
00094 # define _gca_format(archetype, index, first)                                 \
00095                 __attribute__((format(archetype, index, first)))
00096 #else
00097 # define _gca_format(archetype, index, first)
00098 #endif
00099 
00115 #undef _gca_func
00116 #undef _gca_have_func
00117 #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
00118 # define _gca_func              __func__
00119 # define _gca_have_func 1
00120 #elif _GCA_PREREQ(2, 4)
00121 # define _gca_func              __FUNCTION__
00122 # define _gca_have_func 1
00123 #else
00124 # define _gca_func              ((const char *) 0)
00125 # define _gca_have_func 0
00126 #endif
00127 
00135 #define RCSTAG(tag) static char rcsid[] _gca_unused = tag
00136 
00144 #define EV_CTX_LTDLINIT         0x00000004
00145 
00152 typedef struct _ev_varlist_s ev_varlist_t;
00153 
00160 typedef struct _ev_overvars_s ev_overvars_t;
00161 
00169 typedef struct _ev_attr_s _ev_attr_t;
00170 
00178 typedef struct _ev_genlist_s ev_genlist_t;
00179 
00187 typedef struct _ev_gendesc_s ev_gendesc_t;
00188 
00197 typedef struct _ev_gens_s ev_gens_t;
00198 
00204 struct _ev_varlist_s {
00205   ev_varlist_t         *vl_next;        
00206   ev_varlist_t        **vl_prev_p;      
00207   const char           *vl_name;        
00208   const char           *vl_default;     
00209   treeconf_nodown_t     vl_nodown;      
00210   treeconf_change_t     vl_change;      
00211   void                 *vl_assoc;       
00212 };
00213 
00219 struct _ev_overvars_s {
00220   ev_overvars_t        *ov_next;        
00221   ev_overvars_t       **ov_prev_p;      
00222   const char           *ov_name;        
00223   const char           *ov_value;       
00224 };
00225 
00231 struct _ev_attr_s {
00232   ev_magic_t            ea_magic;       
00233   const char           *ea_confpath;    
00234   const char           *ea_libpath;     
00235   const char           *ea_modlist;     
00236   ev_varlist_t         *ea_varlist;     
00237   ev_overvars_t        *ea_ovars;       
00238   struct _ev_engine_s  *ea_engines;     
00239 };
00240 
00246 #define EV_ATTR_MAGIC 0x492d393e
00247 
00263 #define _ea(attr, field)        ((*(attr))->ea_ ## field)
00264 
00278 #define ea_verify(attr)         ((attr) && *(attr) &&                         \
00279                                  _ea((attr), magic) == EV_ATTR_MAGIC)
00280 
00294 #define ea_confpath(attr)       _ea((attr), confpath)
00295 
00309 #define ea_libpath(attr)        _ea((attr), libpath)
00310 
00324 #define ea_modlist(attr)        _ea((attr), modlist)
00325 
00339 #define ea_varlist(attr)        _ea((attr), varlist)
00340 
00354 #define ea_ovars(attr)          _ea((attr), ovars)
00355 
00369 #define ea_engines(attr)        _ea((attr), engines)
00370 
00376 struct _ev_genlist_s {
00377   unsigned int          gl_count;       
00378   ev_genhdr_t          *gl_list;        
00379 };
00380 
00386 struct _ev_gendesc_s {
00387   unsigned int          gd_type;        
00388   ev_magic_t            gd_magic;       
00389   size_t                gd_size;        
00390   ev_freegen_t          gd_release;     
00392   ev_genlist_t          gd_active;      
00393   ev_genlist_t          gd_free;        
00394 };
00395 
00401 struct _ev_gens_s {
00402   ev_gens_t            *gs_next;        
00403   ev_gens_t            *gs_prev;        
00404   unsigned int          gs_first;       
00405   unsigned int          gs_count;       
00406   ev_gendesc_t          gs_gens[1];     
00407 };
00408 
00415 extern const _ev_attr_t const *_ev_defattr;
00416 
00426 extern ev_flags_t _ev_asflags;
00427 
00434 #define EVAS_LOG        0x0001
00435 
00442 #define EVAS_ABORT      0x0002
00443 
00452 #define EVAS_LOOP       0x0004
00453 
00460 #define EVAS_TRACE      0x0008  /* tracing function entry */
00461 
00470 extern ev_log_t _ev_debuglog;
00471 
00485 #define ev_log(flag, msg)                                                     \
00486 do {                                                                          \
00487   if ((_ev_asflags & (flag)) && _ev_debuglog) /* if we can log messages */    \
00488     (_ev_debuglog)(__FILE__, __LINE__, _gca_func, (msg)); /* then do so */    \
00489 } while (0)
00490 
00502 #define ev_abort()                                                            \
00503 do {                                                                          \
00504   if (_ev_asflags & EVAS_ABORT) /* If aborting demanded, abort... */          \
00505     abort();                                                                  \
00506   else /* Otherwise, just tell caller about assertion failure... */           \
00507     ev_return(EV_ERR_ASSERT);                                                 \
00508 } while (0)
00509 
00528 #define ev_assert(expr)                                                       \
00529 do {                                                                          \
00530   if (__builtin_expect(!(expr), 0)) { /* check the assertion... */            \
00531     if (__builtin_expect(_ev_asflags & EVAS_LOOP, 0)) /* are we looping? */   \
00532       ev_abort(); /* OK, just break out of the loop */                        \
00533     _ev_asflags |= EVAS_LOOP; /* remember we've been here once before */      \
00534     ev_log(EVAS_LOG, "Assertion failure: " #expr); /* log assertion failure */\
00535     ev_abort(); /* OK, we're done; get out of here! */                        \
00536   }                                                                           \
00537 } while (0)
00538 
00548 #define ev_trace()      ev_log(EVAS_TRACE, "Function entry")
00549 
00566 #define ev_init()                                                             \
00567 do {                                                                          \
00568   initialize_evnt_error_table(); /* initialize the error table... */          \
00569   if (__builtin_expect(_ev_asflags & EVAS_LOOP, 0)) /* did we assert? */      \
00570     ev_abort(); /* if so, then get out of here! */                            \
00571   ev_trace(); /* log function entry... */                                     \
00572 } while (0)
00573 
00584 #define ev_return(val)                                                        \
00585 do {                                                                          \
00586   ev_err_t _err = (val); /* save return value... */                           \
00587   _ev_debug(EVAS_TRACE, __FILE__, __LINE__, _gca_func,                        \
00588             "Function exit: " #val " (%u)", _err);                            \
00589   return _err;                                                                \
00590 } while (0)
00591 
00602 #define ev_gen_init(ctx, gen, gd)                                             \
00603 do {                                                                          \
00604   ev_genhdr_t *_gen = (ev_genhdr_t *)(gen);                                   \
00605   ev_gendesc_t *_gd = (gd);                                                   \
00606   _gen->eg_type = _gd->gd_type;                                               \
00607   _gen->eg_flags = 0;                                                         \
00608   _gen->eg_next = 0;                                                          \
00609   _gen->eg_prev = 0;                                                          \
00610   _gen->eg_context = (ctx);                                                   \
00611   _gen->eg_ref = 0;                                                           \
00612   _gen->eg_callback = 0;                                                      \
00613   _gen->eg_calldata = 0;                                                      \
00614   _gen->eg_engdata.egd_int = 0;                                               \
00615   _gen->eg_magic = _gd->gd_magic; /* initialize magic number last */          \
00616 } while (0)
00617 
00637 #define tv_comp(tv1, tv2)       (((tv1)->tv_sec == (tv2)->tv_sec) ?           \
00638                                  ((tv1)->tv_usec - (tv2)->tv_usec) :          \
00639                                  ((tv1)->tv_sec  - (tv2)->tv_sec))
00640 
00648 #define tt_node_fix(tim)                                                      \
00649 do {                                                                          \
00650   ev_tim_t *_tim = (tim);                                                     \
00651   if (_tim->ti_node.tn_next)                                                  \
00652     _tim->ti_node.tn_next->ti_node.tn_prev = _tim;                            \
00653   if (_tim->ti_node.tn_prev)                                                  \
00654     _tim->ti_node.tn_prev->ti_node.tn_next = _tim;                            \
00655   if (_tim->ti_node.tn_left)                                                  \
00656     _tim->ti_node.tn_left->ti_node.tn_parent = _tim;                          \
00657   if (_tim->ti_node.tn_right)                                                 \
00658     _tim->ti_node.tn_right->ti_node.tn_parent = _tim;                         \
00659 } while (0)
00660 
00673 #define tt_node_init(tim, parent, prev)                                       \
00674 do {                                                                          \
00675   ev_tim_t *_tim = (tim);                                                     \
00676   _tim->ti_node.tn_parent = (parent); /* initialize node structure */         \
00677   _tim->ti_node.tn_next = 0;                                                  \
00678   _tim->ti_node.tn_prev = (prev);                                             \
00679   _tim->ti_node.tn_left = 0;                                                  \
00680   _tim->ti_node.tn_right = 0;                                                 \
00681   if (_tim->ti_node.tn_prev) /* update previous node in thread */             \
00682     _tim->ti_node.tn_prev->ti_node.tn_next = _tim;                            \
00683 } while (0)
00684 
00694 #define ti_expire_comp(tim)                                                   \
00695 do {                                                                          \
00696   struct timeval _c_tim;                                                      \
00697   ev_tim_t *_tim = (tim);                                                     \
00698   if (_tim->ti_type == TT_ABSOLUTE)                                           \
00699     _tim->ti_expire = _tim->ti_value; /* value is absolute time */            \
00700   else {                                                                      \
00701     gettimeofday(&_c_tim, 0); /* get the current time... */                   \
00702     /* compute the absolute time for expiration */                            \
00703     tim->ti_expire.tv_sec  = _c_tim.tv_sec  + _tim->ti_value.tv_sec;          \
00704     tim->ti_expire.tv_usec = _c_tim.tv_usec + _tim->ti_value.tv_usec;         \
00705   }                                                                           \
00706 } while (0)
00707 
00716 #define so_uevents_set(sock, flags)                                           \
00717                                 _so_set((sock), _so_encev((flags),            \
00718                                                           _EV_SOCK_UEVENTS))
00719 
00728 #define so_uevents_clr(sock, flags)                                           \
00729                                 _so_clr((sock), _so_encev((flags),            \
00730                                                           _EV_SOCK_UEVENTS))
00731 
00740 #define so_blocked_set(sock, flags)                                           \
00741                                 _so_set((sock), _so_encev((flags),            \
00742                                                           _EV_SOCK_BLOCKED))
00743 
00752 #define so_blocked_clr(sock, flags)                                           \
00753                                 _so_clr((sock), _so_encev((flags),            \
00754                                                           _EV_SOCK_BLOCKED))
00755 
00764 #define so_closed_set(sock, flags)                                            \
00765                                 _so_set((sock), _so_encev((flags),            \
00766                                                           _EV_SOCK_CLOSED))
00767 
00778 #define so_closed_clr(sock, flags)                                            \
00779                                 _so_clr((sock), _so_encev((flags),            \
00780                                                           _EV_SOCK_CLOSED))
00781 
00801 extern void _ev_debug(ev_flags_t flags, const char *file, int line,
00802                       const char *func, const char *fmt, ...)
00803      _gca_nonnull((2, 5)) _gca_format(printf, 5, 6);
00804 
00821 extern ev_err_t _ev_gen_lookup(ev_ctx_t *ctx, unsigned int gentype,
00822                                ev_gendesc_t **gen)
00823      _gca_nonnull((1, 3));
00824 
00840 extern ev_err_t _timer_insert(ev_ctx_t *ctx, ev_tim_t *tim)
00841      _gca_nonnull((1, 2));
00842 
00857 extern ev_err_t _timer_heapify_up(ev_ctx_t *ctx, ev_tim_t *tim)
00858      _gca_nonnull((1, 2));
00859 
00874 extern ev_err_t _timer_heapify_down(ev_ctx_t *ctx, ev_tim_t *tim)
00875      _gca_nonnull((1, 2));
00876 
00892 extern ev_err_t _timer_untree(ev_ctx_t *ctx, ev_tim_t *tim)
00893      _gca_nonnull((1, 2));
00894 
00895 #endif /* __include_event_int_h__ */

Generated on Wed Dec 28 23:36:56 2005 for event by  doxygen 1.4.4