Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 #ifndef _Event_h_
00026 #define _Event_h_
00027 
00028 #include "libts.h"
00029 #include "I_Action.h"
00030 
00031 
00032 
00033 
00034 
00035 #define MAX_EVENTS_PER_THREAD     100000
00036 
00037 
00038 
00039 #define EVENT_NONE                CONTINUATION_EVENT_NONE       // 0
00040 #define EVENT_IMMEDIATE           1
00041 #define EVENT_INTERVAL            2
00042 #define EVENT_ERROR               3
00043 #define EVENT_CALL                4     // used internally in state machines
00044 #define EVENT_POLL                5     // negative event; activated on poll or epoll
00045 
00046 
00047 
00048 #define EVENT_DONE                CONTINUATION_DONE     // 0
00049 #define EVENT_CONT                CONTINUATION_CONT     // 1
00050 #define EVENT_RETURN              5
00051 #define EVENT_RESTART             6
00052 #define EVENT_RESTART_DELAYED     7
00053 
00054 
00055 
00056 
00057 #define VC_EVENT_EVENTS_START                     100
00058 #define NET_EVENT_EVENTS_START                    200
00059 #define DISK_EVENT_EVENTS_START                   300
00060 #define CLUSTER_EVENT_EVENTS_START                400
00061 #define HOSTDB_EVENT_EVENTS_START                 500
00062 #define DNS_EVENT_EVENTS_START                    600
00063 #define CONFIG_EVENT_EVENTS_START                 800
00064 #define LOG_EVENT_EVENTS_START                    900
00065 #define MULTI_CACHE_EVENT_EVENTS_START            1000
00066 #define CACHE_EVENT_EVENTS_START                  1100
00067 #define CACHE_DIRECTORY_EVENT_EVENTS_START        1200
00068 #define CACHE_DB_EVENT_EVENTS_START               1300
00069 #define HTTP_NET_CONNECTION_EVENT_EVENTS_START    1400
00070 #define HTTP_NET_VCONNECTION_EVENT_EVENTS_START   1500
00071 #define GC_EVENT_EVENTS_START                     1600
00072 #define ICP_EVENT_EVENTS_START                    1800
00073 #define TRANSFORM_EVENTS_START                    2000
00074 #define STAT_PAGES_EVENTS_START                   2100
00075 #define HTTP_SESSION_EVENTS_START                 2200
00076 #define HTTP2_SESSION_EVENTS_START                2250
00077 #define HTTP_TUNNEL_EVENTS_START                  2300
00078 #define HTTP_SCH_UPDATE_EVENTS_START              2400
00079 #define NT_ASYNC_CONNECT_EVENT_EVENTS_START       3000
00080 #define NT_ASYNC_IO_EVENT_EVENTS_START            3100
00081 #define RAFT_EVENT_EVENTS_START                   3200
00082 #define SIMPLE_EVENT_EVENTS_START                 3300
00083 #define UPDATE_EVENT_EVENTS_START                 3500
00084 #define LOG_COLLATION_EVENT_EVENTS_START          3800
00085 #define AIO_EVENT_EVENTS_START                    3900
00086 #define BLOCK_CACHE_EVENT_EVENTS_START            4000
00087 #define UTILS_EVENT_EVENTS_START                  5000
00088 #define CONGESTION_EVENT_EVENTS_START             5100
00089 #define INK_API_EVENT_EVENTS_START                60000
00090 #define SRV_EVENT_EVENTS_START                    62000
00091 #define REMAP_EVENT_EVENTS_START                  63000
00092 
00093 
00094 #define ONE_WAY_TUNNEL_EVENT_PEER_CLOSE (SIMPLE_EVENT_EVENTS_START+1)
00095 #define PREFETCH_EVENT_SEND_URL         (SIMPLE_EVENT_EVENTS_START+2)
00096 
00097 typedef int EventType;
00098 const int ET_CALL = 0;
00099 const int MAX_EVENT_TYPES = 8; 
00100 
00101 class EThread;
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 class Event:public Action
00154 {
00155 public:
00156 
00157 
00158   
00159 
00160 
00161 
00162 
00163 
00164 
00165 
00166 
00167 
00168 
00169   void schedule_imm(int callback_event = EVENT_IMMEDIATE);
00170 
00171 
00172 
00173 
00174 
00175 
00176 
00177 
00178 
00179 
00180   void schedule_at(ink_hrtime atimeout_at, int callback_event = EVENT_INTERVAL);
00181 
00182 
00183 
00184 
00185 
00186 
00187 
00188 
00189 
00190 
00191   void schedule_in(ink_hrtime atimeout_in, int callback_event = EVENT_INTERVAL);
00192 
00193 
00194 
00195 
00196 
00197 
00198 
00199 
00200 
00201 
00202   void schedule_every(ink_hrtime aperiod, int callback_event = EVENT_INTERVAL);
00203 
00204   
00205   
00206 
00207   void free();
00208 
00209   EThread *ethread;
00210 
00211   unsigned int in_the_prot_queue:1;
00212   unsigned int in_the_priority_queue:1;
00213   unsigned int immediate:1;
00214   unsigned int globally_allocated:1;
00215   unsigned int in_heap:4;
00216   int callback_event;
00217 
00218   ink_hrtime timeout_at;
00219   ink_hrtime period;
00220 
00221 
00222 
00223 
00224 
00225 
00226 
00227   void *cookie;
00228 
00229   
00230 
00231   Event();
00232 
00233 
00234   Event *init(Continuation * c, ink_hrtime atimeout_at = 0, ink_hrtime aperiod = 0);
00235 
00236 #ifdef ENABLE_TIME_TRACE
00237   ink_hrtime start_time;
00238 #endif
00239 
00240 private:
00241   void *operator  new(size_t size);     
00242 
00243 private:
00244   
00245     Event(const Event &);
00246     Event & operator =(const Event &);
00247 
00248 public:
00249   LINK(Event, link);
00250 
00251   
00252 
00253 
00254 
00255 #ifdef ONLY_USED_FOR_FIB_AND_BIN_HEAP
00256   void *node_pointer;
00257   void set_node_pointer(void *x)
00258   {
00259     node_pointer = x;
00260   }
00261   void *get_node_pointer()
00262   {
00263     return node_pointer;
00264   }
00265 #endif
00266 
00267 #if defined(__GNUC__)
00268   virtual ~ Event() {
00269   }
00270 #endif
00271 };
00272 
00273 
00274 
00275 
00276 extern ClassAllocator<Event> eventAllocator;
00277 
00278 #define EVENT_ALLOC(_a, _t) THREAD_ALLOC(_a, _t)
00279 #define EVENT_FREE(_p, _a, _t)   \
00280   _p->mutex = NULL;              \
00281   if (_p->globally_allocated)    \
00282     ::_a.free(_p);               \
00283   else                           \
00284     THREAD_FREE(_p, _a, _t)
00285 
00286 #endif