Public Member Functions | Data Fields

EventProcessor Class Reference

Main processor for the Event System. More...

#include <I_EventProcessor.h>

Inherits Processor.

Collaboration diagram for EventProcessor:
Collaboration graph
[legend]

Public Member Functions

Eventspawn_thread (Continuation *cont, const char *thr_name, size_t stacksize=0)
 Spawn an additional thread for calling back the continuation.
EventType spawn_event_threads (int n_threads, const char *et_name, size_t stacksize)
 Spawns a group of threads for an event type.
Eventschedule_imm (Continuation *c, EventType event_type=ET_CALL, int callback_event=EVENT_IMMEDIATE, void *cookie=NULL)
 Schedules the continuation on a specific EThread to receive an event at the given timeout.
Eventschedule_imm_signal (Continuation *c, EventType event_type=ET_CALL, int callback_event=EVENT_IMMEDIATE, void *cookie=NULL)
Eventschedule_at (Continuation *c, ink_hrtime atimeout_at, EventType event_type=ET_CALL, int callback_event=EVENT_INTERVAL, void *cookie=NULL)
 Schedules the continuation on a specific thread group to receive an event at the given timeout.
Eventschedule_in (Continuation *c, ink_hrtime atimeout_in, EventType event_type=ET_CALL, int callback_event=EVENT_INTERVAL, void *cookie=NULL)
 Schedules the continuation on a specific thread group to receive an event after the specified timeout elapses.
Eventschedule_every (Continuation *c, ink_hrtime aperiod, EventType event_type=ET_CALL, int callback_event=EVENT_INTERVAL, void *cookie=NULL)
 Schedules the continuation on a specific thread group to receive an event periodically.
Eventreschedule_imm (Event *e, int callback_event=EVENT_IMMEDIATE)
Eventreschedule_at (Event *e, ink_hrtime atimeout_at, int callback_event=EVENT_INTERVAL)
Eventreschedule_in (Event *e, ink_hrtime atimeout_in, int callback_event=EVENT_INTERVAL)
Eventreschedule_every (Event *e, ink_hrtime aperiod, int callback_event=EVENT_INTERVAL)
 EventProcessor ()
int start (int n_net_threads, size_t stacksize=DEFAULT_STACKSIZE)
 Initializes the EventProcessor and its associated threads.
virtual void shutdown ()
 Stop the EventProcessor.
off_t allocate (int size)
 Allocates size bytes on the event threads.
Eventschedule (Event *e, EventType etype, bool fast_signal=false)
EThreadassign_thread (EventType etype)

Data Fields

EThreadall_ethreads [MAX_EVENT_THREADS]
 An array of pointers to all of the EThreads handled by the EventProcessor.
EThreadeventthread [MAX_EVENT_TYPES][MAX_THREADS_IN_EACH_TYPE]
 An array of pointers, organized by thread group, to all of the EThreads handled by the EventProcessor.
unsigned int next_thread_for_type [MAX_EVENT_TYPES]
int n_threads_for_type [MAX_EVENT_TYPES]
int n_ethreads
 Total number of threads controlled by this EventProcessor.
int n_thread_groups
 Total number of thread groups created so far.
EThreadall_dthreads [MAX_EVENT_THREADS]
int n_dthreads
volatile int thread_data_used

Detailed Description

Main processor for the Event System.

The EventProcessor is the core component of the Event System. Once started, it is responsible for creating and managing groups of threads that execute user-defined tasks asynchronously at a given time or periodically.

The EventProcessor provides a set of scheduling functions through which you can specify continuations to be called back by one of its threads. These function calls do not block. Instead they return an Event object and schedule the callback to the continuation passed in at a later or specific time, as soon as possible or at certain intervals.

Singleton model:

Every executable that imports and statically links against the EventSystem library is provided with a global instance of the EventProcessor called eventProcessor. Therefore, it is not necessary to create instances of the EventProcessor class because it was designed as a singleton. It is important to note that none of its functions are reentrant.

Thread Groups (Event types):

When the EventProcessor is started, the first group of threads is spawned and it is assigned the special id ET_CALL. Depending on the complexity of the state machine or protocol, you may be interested in creating additional threads and the EventProcessor gives you the ability to create a single thread or an entire group of threads. In the former case, you call spawn_thread and the thread is independent of the thread groups and it exists as long as your continuation handle executes and there are events to process. In the latter, you call spawn_event_theads which creates a new thread group and you get an id or event type with wich you must keep for use later on when scheduling continuations on that group.

Callback event codes:

UNIX: For all of the scheduling functions, the callback_event parameter is not used. On a callback, the event code passed in to the continuation handler is always EVENT_IMMEDIATE.

NT: The value of the event code passed in to the continuation handler is the value provided in the callback_event parameter.

Event allocation policy:

Events are allocated and deallocated by the EventProcessor. A state machine may access the returned, non-recurring event until it is cancelled or the callback from the event is complete. For recurring events, the Event may be accessed until it is cancelled. Once the event is complete or cancelled, it's the eventProcessor's responsibility to deallocate it.

Definition at line 100 of file I_EventProcessor.h.


Constructor & Destructor Documentation

TS_INLINE EventProcessor::EventProcessor (  ) 

Member Function Documentation

TS_INLINE off_t EventProcessor::allocate ( int  size  ) 

Allocates size bytes on the event threads.

This function is thread safe.

Parameters:
size bytes to be allocated.

Definition at line 45 of file P_UnixEventProcessor.h.

References INK_ALIGN, PER_THREAD_DATA, start(), and thread_data_used.

Referenced by RecAllocateRawStatBlock(), UDPNetProcessorInternal::start(), and UnixNetProcessor::start().

TS_INLINE EThread * EventProcessor::assign_thread ( EventType  etype  ) 
Event* EventProcessor::reschedule_at ( Event e,
ink_hrtime  atimeout_at,
int  callback_event = EVENT_INTERVAL 
)
Event* EventProcessor::reschedule_every ( Event e,
ink_hrtime  aperiod,
int  callback_event = EVENT_INTERVAL 
)
Event* EventProcessor::reschedule_imm ( Event e,
int  callback_event = EVENT_IMMEDIATE 
)
Event* EventProcessor::reschedule_in ( Event e,
ink_hrtime  atimeout_in,
int  callback_event = EVENT_INTERVAL 
)
TS_INLINE Event * EventProcessor::schedule ( Event e,
EventType  etype,
bool  fast_signal = false 
)
TS_INLINE Event * EventProcessor::schedule_at ( Continuation c,
ink_hrtime  atimeout_at,
EventType  event_type = ET_CALL,
int  callback_event = EVENT_INTERVAL,
void *  cookie = NULL 
)

Schedules the continuation on a specific thread group to receive an event at the given timeout.

Requests the EventProcessor to schedule the callback to the continuation 'c' at the time specified in 'atimeout_at'. The callback is handled by a thread in the specified thread group (event_type).

Parameters:
c Continuation to be called back at the time specified in 'atimeout_at'.
atimeout_at Time value at which to callback.
event_type thread group id (or event type) specifying the group of threads on which to schedule the callback.
callback_event code to be passed back to the continuation's handler. See the Remarks section.
cookie user-defined value or pointer to be passed back in the Event's object cookie field.
Returns:
reference to an Event object representing the scheduling of this callback.

Definition at line 117 of file P_UnixEventProcessor.h.

References Event::callback_event, Event::cookie, eventAllocator, Event::init(), ink_assert, MAX_EVENT_TYPES, and schedule().

TS_INLINE Event * EventProcessor::schedule_every ( Continuation c,
ink_hrtime  aperiod,
EventType  event_type = ET_CALL,
int  callback_event = EVENT_INTERVAL,
void *  cookie = NULL 
)

Schedules the continuation on a specific thread group to receive an event periodically.

Requests the EventProcessor to schedule the callback to the continuation 'c' everytime 'aperiod' elapses. The callback is handled by a thread in the specified thread group (event_type).

Parameters:
c Continuation to call back everytime 'aperiod' elapses.
aperiod duration of the time period between callbacks.
event_type thread group id (or event type) specifying the group of threads on which to schedule the callback.
callback_event code to be passed back to the continuation's handler. See the Remarks section.
cookie user-defined value or pointer to be passed back in the Event's object cookie field.
Returns:
reference to an Event object representing the scheduling of this callback.

Definition at line 140 of file P_UnixEventProcessor.h.

References Event::callback_event, Event::cookie, eventAllocator, Event::init(), ink_assert, ink_get_based_hrtime(), MAX_EVENT_TYPES, and schedule().

Referenced by clusterAPI_init(), cmd_check_internal(), cmd_clear(), UpdateScheduler::Init(), UpdateConfigManager::init(), RamCacheCLFUS::init(), ClusterLoadMonitor::init(), GlobalClusterPeriodicEvent::init(), ClusterAccept::Init(), init_signals2(), init_tracker(), main(), RecProcessStart(), run_RegressionTest(), PluginVC::set_inactivity_timeout(), SSLNetProcessor::start(), ICPProcessor::start(), HostDBProcessor::start(), start_stats_snap(), ClusterHandler::startClusterEvent(), and TSContScheduleEvery().

TS_INLINE Event * EventProcessor::schedule_imm ( Continuation c,
EventType  event_type = ET_CALL,
int  callback_event = EVENT_IMMEDIATE,
void *  cookie = NULL 
)

Schedules the continuation on a specific EThread to receive an event at the given timeout.

Requests the EventProcessor to schedule the callback to the continuation 'c' at the time specified in 'atimeout_at'. The event is assigned to the specified EThread.

Parameters:
c Continuation to be called back at the time specified in 'atimeout_at'.
atimeout_at time value at which to callback.
ethread EThread on which to schedule the event.
callback_event code to be passed back to the continuation's handler. See the Remarks section.
cookie user-defined value or pointer to be passed back in the Event's object cookie field.
Returns:
reference to an Event object representing the scheduling of this callback.

Definition at line 103 of file P_UnixEventProcessor.h.

References Event::callback_event, Event::cookie, eventAllocator, Event::init(), ink_assert, ink_get_hrtime(), MAX_EVENT_TYPES, and schedule().

Referenced by aio_thread_main(), cacheControlFile_CB(), CacheContinuation::callback_failure(), CacheHostTable::config_callback(), ClusterProcessor::connect(), UnixNetProcessor::connect_re_internal(), ClusterHandler::connectClusterEvent(), CacheContinuation::defer_callback_result(), TransformTerminus::do_io_close(), INKVConnInternal::do_io_close(), TransformTerminus::do_io_read(), INKVConnInternal::do_io_read(), INKVConnInternal::do_io_shutdown(), TransformTerminus::do_io_write(), INKVConnInternal::do_io_write(), CacheTestSM::event_handler(), NetVCTest::finished(), http_pages_callback(), ICPProcessor::ICPQuery(), init_http_update_test(), CacheContinuation::insert_cache_callback_user(), CacheContinuation::insertCallbackEvent(), ConfigUpdateCbTable::invoke(), CacheContinuation::lookupOpenWriteVC(), Http2ConnectionState::main_event_handler(), ICPConfiguration::mgr_icp_config_change_callback(), net_accept(), Cache::open(), RemapProcessor::perform_remap(), ICPPeriodicCont::PeriodicEvent(), TransformTerminus::reenable(), INKVConnInternal::reenable(), register_ShowCache(), register_ShowCacheInternal(), register_ShowNet(), TransformTest::run(), CacheTestSM::run(), LogCollationClientSM::send(), HostDBProcessor::setby_srv(), ClusterAccept::ShutdownDelete(), spdy_cs_create(), UpdateSM::Start(), HostDBProcessor::start(), CacheProcessor::start_internal(), MultiCacheBase::sync_partitions(), TSContSchedule(), TSHttpSchedule(), TSHttpSsnReenable(), TSHttpTxnReenable(), UDPNetProcessorInternal::udp_callback(), UpdateConfigManager::URL_list_update_callout(), and url_rewrite_CB().

TS_INLINE Event * EventProcessor::schedule_imm_signal ( Continuation c,
EventType  event_type = ET_CALL,
int  callback_event = EVENT_IMMEDIATE,
void *  cookie = NULL 
)
TS_INLINE Event * EventProcessor::schedule_in ( Continuation c,
ink_hrtime  atimeout_in,
EventType  event_type = ET_CALL,
int  callback_event = EVENT_INTERVAL,
void *  cookie = NULL 
)

Schedules the continuation on a specific thread group to receive an event after the specified timeout elapses.

Requests the EventProcessor to schedule the callback to the continuation 'c' after the time specified in 'atimeout_in' elapses. The callback is handled by a thread in the specified thread group (event_type).

Parameters:
c Continuation to call back aftert the timeout elapses.
atimeout_in amount of time after which to callback.
event_type Thread group id (or event type) specifying the group of threads on which to schedule the callback.
callback_event code to be passed back to the continuation's handler. See the Remarks section.
cookie user-defined value or pointer to be passed back in the Event's object cookie field.
Returns:
reference to an Event object representing the scheduling of this callback.

Definition at line 129 of file P_UnixEventProcessor.h.

References Event::callback_event, Event::cookie, eventAllocator, Event::init(), ink_assert, ink_get_based_hrtime(), MAX_EVENT_TYPES, and schedule().

Referenced by Vol::aggWriteDone(), cache_op_result_ClusterFunction(), UpdateScheduler::ChildExitEventHandler(), PrefetchConfigCont::conf_update_handler(), Congestion_CongestionDB(), Congestion_FailHistory(), ClusterProcessor::connect(), ClusterHandler::connectClusterEvent(), Vol::dir_init_done(), dir_sync_init(), CacheContinuation::disposeOfDataBuffer(), HostDBContinuation::dnsPendingEvent(), HttpSM::do_http_server_open(), CacheContinuation::do_op(), CacheContinuation::do_remote_lookup(), ConfigUpdateCallback::event_handler(), RecursiveHttpGet::ExitEventHandler(), FetchSM::ext_destroy(), free_ClusterMachine(), free_configuration(), get_congest_entry(), get_congest_list(), HttpPagesHandler::handle_callback(), HttpPagesHandler::handle_smdetails(), HttpPagesHandler::handle_smlist(), UpdateSM::HandleSMEvent(), http_config_cb(), ICPConfiguration::icp_config_change_callback(), ICPPeerReadCont::ICPPeerReadEvent(), ICPRequestCont::ICPRequestEvent(), ClusterVConnectionCache::init(), ink_aio_start(), HttpUpdateSM::kill_this_async_hook(), CacheSync::mainEvent(), new_Deleter(), new_Derefer(), new_FreeCaller(), new_Freer(), CacheDisk::openDone(), prefetch_config_cb(), ClusterHandler::protoZombieEvent(), reloadCacheControl(), CacheContinuation::remove_and_delete(), RegressionSM::run(), run_AutoStop(), RegressionSM::run_in(), Cache::scan(), CacheVC::scanObject(), CacheVC::scanVol(), PluginVC::set_active_timeout(), ClusterHandler::startClusterEvent(), PluginVCCore::state_send_accept(), PluginVCCore::state_send_accept_failed(), TSContSchedule(), TSHttpSchedule(), and ClusterHandler::zombify().

void EventProcessor::shutdown (  )  [virtual]

Stop the EventProcessor.

Attempts to stop the EventProcessor and all of the threads in each of the thread groups.

Reimplemented from Processor.

Definition at line 165 of file UnixEventProcessor.cc.

EventType EventProcessor::spawn_event_threads ( int  n_threads,
const char *  et_name,
size_t  stacksize 
)

Spawns a group of threads for an event type.

Spawns the number of event threads passed in (n_threads) creating a thread group and returns the thread group id (or EventType). See the remarks section for Thread Groups.

Returns:
EventType or thread id for the new group of threads.

Definition at line 33 of file UnixEventProcessor.cc.

References all_ethreads, Debug, eventthread, ink_release_assert, MAX_EVENT_THREADS, MAX_EVENT_TYPES, MAX_THREAD_NAME_LENGTH, n_ethreads, n_thread_groups, n_threads_for_type, REGULAR, EThread::set_event_type(), and Thread::start().

Referenced by UDPNetProcessorInternal::start(), TasksProcessor::start(), SSLNetProcessor::start(), RemapProcessor::start(), DNSProcessor::start(), and ClusterProcessor::start().

Event * EventProcessor::spawn_thread ( Continuation cont,
const char *  thr_name,
size_t  stacksize = 0 
)

Spawn an additional thread for calling back the continuation.

Spawns a dedicated thread (EThread) that calls back the continuation passed in as soon as possible.

Parameters:
cont continuation that the spawn thread will call back immediately.
Returns:
event object representing the start of the thread.

Definition at line 170 of file UnixEventProcessor.cc.

References all_dthreads, Action::continuation, DEDICATED, Event::ethread, eventAllocator, Event::init(), ink_release_assert, MAX_EVENT_THREADS, Thread::mutex, Continuation::mutex, Action::mutex, n_dthreads, and Thread::start().

Referenced by aio_init_fildes(), and NetAccept::init_accept_loop().

int EventProcessor::start ( int  n_net_threads,
size_t  stacksize = DEFAULT_STACKSIZE 
) [virtual]

Initializes the EventProcessor and its associated threads.

Spawns the specified number of threads, initializes their state information and sets them running. It creates the initial thread group, represented by the event type ET_CALL.

Returns:
0 if successful, and a negative value otherwise.

Reimplemented from Processor.

Definition at line 69 of file UnixEventProcessor.cc.

References all_ethreads, Thread::cur_time, Debug, ET_CALL, eventthread, global_mutex, ink_get_based_hrtime_internal(), ink_number_of_processors(), ink_release_assert, ink_thread_setspecific(), MAX_EVENT_THREADS, MAX_THREAD_NAME_LENGTH, Thread::mutex, n_ethreads, n_thread_groups, n_threads_for_type, REC_ReadConfigInteger, REGULAR, EThread::set_event_type(), Thread::start(), Thread::thread_data_key, and Warning.

Referenced by allocate(), and main().


Field Documentation

An array of pointers to all of the EThreads handled by the EventProcessor.

An array of pointers to all of the EThreads created throughout the existence of the EventProcessor instance.

Definition at line 272 of file I_EventProcessor.h.

Referenced by EventProcessor(), raw_stat_clear(), raw_stat_clear_count(), raw_stat_clear_sum(), raw_stat_get_total(), raw_stat_sync_to_global(), spawn_event_threads(), and start().

An array of pointers, organized by thread group, to all of the EThreads handled by the EventProcessor.

An array of pointers to all of the EThreads created throughout the existence of the EventProcessor instance. It is a two-dimensional array whose first dimension is the thread group id and the second the EThread pointers for that group.

Definition at line 282 of file I_EventProcessor.h.

Referenced by assign_thread(), NetAccept::init_accept_per_thread(), SSLNetAccept::init_accept_per_thread(), CacheContinuation::is_ClusterThread(), ShowNet::showConnections(), ShowNet::showConnectionsOnThread(), ShowNet::showSingleThread(), ShowNet::showThreads(), spawn_event_threads(), UDPNetProcessorInternal::start(), UnixNetProcessor::start(), start(), DNSProcessor::start(), ClusterProcessor::start(), CacheProcessor::start_internal(), and ClusterHandler::startClusterEvent().

Total number of threads controlled by this EventProcessor.

This is the count of all the EThreads spawn by this EventProcessor, excluding those created by spawn_thread

Definition at line 293 of file I_EventProcessor.h.

Referenced by ProtectedQueue::enqueue(), flush_signals(), raw_stat_clear(), raw_stat_clear_count(), raw_stat_clear_sum(), raw_stat_get_total(), raw_stat_sync_to_global(), spawn_event_threads(), and start().

Total number of thread groups created so far.

This is the count of all the thread groups (event types) created for this EventProcessor.

Definition at line 300 of file I_EventProcessor.h.

Referenced by spawn_event_threads(), and start().

Definition at line 284 of file I_EventProcessor.h.

Referenced by assign_thread(), and EventProcessor().

Definition at line 318 of file I_EventProcessor.h.

Referenced by allocate().


The documentation for this class was generated from the following files: