• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

I_Event.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022 
00023  */
00024 
00025 #ifndef _Event_h_
00026 #define _Event_h_
00027 
00028 #include "libts.h"
00029 #include "I_Action.h"
00030 
00031 //
00032 //  Defines
00033 //
00034 
00035 #define MAX_EVENTS_PER_THREAD     100000
00036 
00037 // Events
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 // Event callback return functions
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 // Event numbers block allocation
00055 // ** ALL NEW EVENT TYPES SHOULD BE ALLOCATED FROM BLOCKS LISTED HERE! **
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 //define misc events here
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; // conservative, these are dynamically allocated
00100 
00101 class EThread;
00102 
00103 /**
00104   A type of Action returned by the EventProcessor. The Event class
00105   is the type of Action returned by the EventProcessor as a result
00106   of scheduling an operation. Unlike asynchronous operations
00107   represented by actions, events never call reentrantly.
00108 
00109   Besides being able to cancel an event (because it is an action),
00110   you can also reschedule it once received.
00111 
00112   <b>Remarks</b>
00113 
00114   When reschedulling an event through any of the Event class
00115   schedulling fuctions, state machines must not make these calls
00116   in other thread other than the one that called them back. They
00117   also must have acquired the continuation's lock before calling
00118   any of the schedulling functions.
00119 
00120   The rules for cancelling an event are the same as those for
00121   actions:
00122 
00123   The canceller of an event must be the state machine that will be
00124   called back by the task and that state machine's lock must be
00125   held while calling cancel. Any reference to that event object
00126   (ie. pointer) held by the state machine must not be used after
00127   the cancellation.
00128 
00129   Event Codes:
00130 
00131   At the completion of an event, state machines use the event code
00132   passed in through the Continuation's handler function to distinguish
00133   the type of event and handle the data parameter accordingly. State
00134   machine implementers should be careful when defining the event
00135   codes since they can impact on other state machines presents. For
00136   this reason, this numbers are usually allocated from a common
00137   pool.
00138 
00139   Time values:
00140 
00141   The schedulling functions use a time parameter typed as ink_hrtime
00142   for specifying the timeouts or periods. This is a nanosecond value
00143   supported by libts and you should use the time functions and
00144   macros defined in ink_hrtime.h.
00145 
00146   The difference between the timeout specified for schedule_at and
00147   schedule_in is that in the former it is an absolute value of time
00148   that is expected to be in the future where in the latter it is
00149   an amount of time to add to the current time (obtained with
00150   ink_get_hrtime).
00151 
00152 */
00153 class Event:public Action
00154 {
00155 public:
00156 
00157   ///////////////////////////////////////////////////////////
00158   // Common Interface                                      //
00159   ///////////////////////////////////////////////////////////
00160 
00161   /**
00162      Reschedules this event immediately. Instructs the event object
00163      to reschedule itself as soon as possible in the EventProcessor.
00164 
00165      @param callback_event Event code to return at the completion
00166       of this event. See the Remarks section.
00167 
00168   */
00169   void schedule_imm(int callback_event = EVENT_IMMEDIATE);
00170 
00171   /**
00172      Reschedules this event to callback at time 'atimeout_at'.
00173      Instructs the event object to reschedule itself at the time
00174      specified in atimeout_at on the EventProcessor.
00175 
00176      @param atimeout_at Time at which to callcallback. See the Remarks section.
00177      @param callback_event Event code to return at the completion of this event. See the Remarks section.
00178 
00179   */
00180   void schedule_at(ink_hrtime atimeout_at, int callback_event = EVENT_INTERVAL);
00181 
00182   /**
00183      Reschedules this event to callback at time 'atimeout_at'.
00184      Instructs the event object to reschedule itself at the time
00185      specified in atimeout_at on the EventProcessor.
00186 
00187      @param atimeout_in Time at which to callcallback. See the Remarks section.
00188      @param callback_event Event code to return at the completion of this event. See the Remarks section.
00189 
00190   */
00191   void schedule_in(ink_hrtime atimeout_in, int callback_event = EVENT_INTERVAL);
00192 
00193   /**
00194      Reschedules this event to callback every 'aperiod'. Instructs
00195      the event object to reschedule itself to callback every 'aperiod'
00196      from now.
00197 
00198      @param aperiod Time period at which to callcallback. See the Remarks section.
00199      @param callback_event Event code to return at the completion of this event. See the Remarks section.
00200 
00201   */
00202   void schedule_every(ink_hrtime aperiod, int callback_event = EVENT_INTERVAL);
00203 
00204   // inherited from Action::cancel
00205   // virtual void cancel(Continuation * c = NULL);
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     This field can be set when an event is created. It is returned
00223     as part of the Event structure to the continuation when handleEvent
00224     is called.
00225 
00226   */
00227   void *cookie;
00228 
00229   // Private
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);     // use the fast allocators
00242 
00243 private:
00244   // prevent unauthorized copies (Not implemented)
00245     Event(const Event &);
00246     Event & operator =(const Event &);
00247 
00248 public:
00249   LINK(Event, link);
00250 
00251   /*-------------------------------------------------------*\
00252   | UNIX/non-NT Interface                                   |
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 // Event Allocator
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 /*_Event_h_*/

Generated by  doxygen 1.7.1