3
A brief file description
5
@section license License
7
Licensed to the Apache Software Foundation (ASF) under one
8
or more contributor license agreements. See the NOTICE file
9
distributed with this work for additional information
10
regarding copyright ownership. The ASF licenses this file
11
to you under the Apache License, Version 2.0 (the
12
"License"); you may not use this file except in compliance
13
with the License. You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
17
Unless required by applicable law or agreed to in writing, software
18
distributed under the License is distributed on an "AS IS" BASIS,
19
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
See the License for the specific language governing permissions and
21
limitations under the License.
35
#define MAX_EVENTS_PER_THREAD 100000
39
#define EVENT_NONE CONTINUATION_EVENT_NONE // 0
40
#define EVENT_IMMEDIATE 1
41
#define EVENT_INTERVAL 2
43
#define EVENT_CALL 4 // used internally in state machines
44
#define EVENT_POLL 5 // negative event; activated on poll or epoll
46
// Event callback return functions
48
#define EVENT_DONE CONTINUATION_DONE // 0
49
#define EVENT_CONT CONTINUATION_CONT // 1
50
#define EVENT_RETURN 5
51
#define EVENT_RESTART 6
52
#define EVENT_RESTART_DELAYED 7
54
// Event numbers block allocation
55
// ** ALL NEW EVENT TYPES SHOULD BE ALLOCATED FROM BLOCKS LISTED HERE! **
57
#define VC_EVENT_EVENTS_START 100
58
#define NET_EVENT_EVENTS_START 200
59
#define DISK_EVENT_EVENTS_START 300
60
#define CLUSTER_EVENT_EVENTS_START 400
61
#define HOSTDB_EVENT_EVENTS_START 500
62
#define DNS_EVENT_EVENTS_START 600
63
#define CONFIG_EVENT_EVENTS_START 800
64
#define LOG_EVENT_EVENTS_START 900
65
#define MULTI_CACHE_EVENT_EVENTS_START 1000
66
#define CACHE_EVENT_EVENTS_START 1100
67
#define CACHE_DIRECTORY_EVENT_EVENTS_START 1200
68
#define CACHE_DB_EVENT_EVENTS_START 1300
69
#define HTTP_NET_CONNECTION_EVENT_EVENTS_START 1400
70
#define HTTP_NET_VCONNECTION_EVENT_EVENTS_START 1500
71
#define GC_EVENT_EVENTS_START 1600
72
#define ICP_EVENT_EVENTS_START 1800
73
#define TRANSFORM_EVENTS_START 2000
74
#define STAT_PAGES_EVENTS_START 2100
75
#define HTTP_SESSION_EVENTS_START 2200
76
#define HTTP_TUNNEL_EVENTS_START 2300
77
#define HTTP_SCH_UPDATE_EVENTS_START 2400
78
#define NT_ASYNC_CONNECT_EVENT_EVENTS_START 3000
79
#define NT_ASYNC_IO_EVENT_EVENTS_START 3100
80
#define RAFT_EVENT_EVENTS_START 3200
81
#define SIMPLE_EVENT_EVENTS_START 3300
82
#define UPDATE_EVENT_EVENTS_START 3500
83
#define LOG_COLLATION_EVENT_EVENTS_START 3800
84
#define AIO_EVENT_EVENTS_START 3900
85
#define BLOCK_CACHE_EVENT_EVENTS_START 4000
86
#define UTILS_EVENT_EVENTS_START 5000
87
#define CONGESTION_EVENT_EVENTS_START 5100
88
#define INK_API_EVENT_EVENTS_START 60000
89
#define SRV_EVENT_EVENTS_START 62000
90
#define REMAP_EVENT_EVENTS_START 63000
92
//define misc events here
93
#define ONE_WAY_TUNNEL_EVENT_PEER_CLOSE (SIMPLE_EVENT_EVENTS_START+1)
94
#define PREFETCH_EVENT_SEND_URL (SIMPLE_EVENT_EVENTS_START+2)
96
typedef int EventType;
97
const int ET_CALL = 0;
98
const int MAX_EVENT_TYPES = 8; // conservative, these are dynamically allocated
103
A type of Action returned by the EventProcessor. The Event class
104
is the type of Action returned by the EventProcessor as a result
105
of scheduling an operation. Unlike asynchronous operations
106
represented by actions, events never call reentrantly.
108
Besides being able to cancel an event (because it is an action),
109
you can also reschedule it once received.
113
When reschedulling an event through any of the Event class
114
schedulling fuctions, state machines must not make these calls
115
in other thread other than the one that called them back. They
116
also must have acquired the continuation's lock before calling
117
any of the schedulling functions.
119
The rules for cancelling an event are the same as those for
122
The canceller of an event must be the state machine that will be
123
called back by the task and that state machine's lock must be
124
held while calling cancel. Any reference to that event object
125
(ie. pointer) held by the state machine must not be used after
130
At the completion of an event, state machines use the event code
131
passed in through the Continuation's handler function to distinguish
132
the type of event and handle the data parameter accordingly. State
133
machine implementers should be careful when defining the event
134
codes since they can impact on other state machines presents. For
135
this reason, this numbers are usually allocated from a common
140
The schedulling functions use a time parameter typed as ink_hrtime
141
for specifying the timeouts or periods. This is a nanosecond value
142
supported by libts and you should use the time functions and
143
macros defined in ink_hrtime.h.
145
The difference between the timeout specified for schedule_at and
146
schedule_in is that in the former it is an absolute value of time
147
that is expected to be in the future where in the latter it is
148
an amount of time to add to the current time (obtained with
152
class Event:public Action
156
///////////////////////////////////////////////////////////
157
// Common Interface //
158
///////////////////////////////////////////////////////////
161
Reschedules this event immediately. Instructs the event object
162
to reschedule itself as soon as possible in the EventProcessor.
164
@param callback_event Event code to return at the completion
165
of this event. See the Remarks section.
168
void schedule_imm(int callback_event = EVENT_IMMEDIATE);
171
Reschedules this event to callback at time 'atimeout_at'.
172
Instructs the event object to reschedule itself at the time
173
specified in atimeout_at on the EventProcessor.
175
@param atimeout_at Time at which to callcallback. See the Remarks section.
176
@param callback_event Event code to return at the completion of this event. See the Remarks section.
179
void schedule_at(ink_hrtime atimeout_at, int callback_event = EVENT_INTERVAL);
182
Reschedules this event to callback at time 'atimeout_at'.
183
Instructs the event object to reschedule itself at the time
184
specified in atimeout_at on the EventProcessor.
186
@param atimeout_in Time at which to callcallback. See the Remarks section.
187
@param callback_event Event code to return at the completion of this event. See the Remarks section.
190
void schedule_in(ink_hrtime atimeout_in, int callback_event = EVENT_INTERVAL);
193
Reschedules this event to callback every 'aperiod'. Instructs
194
the event object to reschedule itself to callback every 'aperiod'
197
@param aperiod Time period at which to callcallback. See the Remarks section.
198
@param callback_event Event code to return at the completion of this event. See the Remarks section.
201
void schedule_every(ink_hrtime aperiod, int callback_event = EVENT_INTERVAL);
203
// inherited from Action::cancel
204
// virtual void cancel(Continuation * c = NULL);
210
unsigned int in_the_prot_queue:1;
211
unsigned int in_the_priority_queue:1;
212
unsigned int immediate:1;
213
unsigned int globally_allocated:1;
214
unsigned int in_heap:4;
217
ink_hrtime timeout_at;
221
This field can be set when an event is created. It is returned
222
as part of the Event structure to the continuation when handleEvent
233
Event *init(Continuation * c, ink_hrtime atimeout_at = 0, ink_hrtime aperiod = 0);
235
#ifdef ENABLE_TIME_TRACE
236
ink_hrtime start_time;
240
void *operator new(size_t size); // use the fast allocators
243
// prevent unauthorized copies (Not implemented)
244
Event(const Event &);
245
Event & operator =(const Event &);
250
/*-------------------------------------------------------*\
251
| UNIX/non-NT Interface |
252
\*-------------------------------------------------------*/
254
#ifdef ONLY_USED_FOR_FIB_AND_BIN_HEAP
256
void set_node_pointer(void *x)
260
void *get_node_pointer()
266
#if defined(__GNUC__)
275
extern ClassAllocator<Event> eventAllocator;
277
#define EVENT_ALLOC(_a, _t) THREAD_ALLOC(_a, _t)
278
#define EVENT_FREE(_p, _a, _t) \
280
if (_p->globally_allocated) ::_a.free(_p); \
281
else THREAD_FREE_TO(_p, _a, _t, MAX_EVENTS_PER_THREAD)