Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions iocore/eventsystem/Continuation.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/** @file

Contination.cc

@section license License

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "I_EventSystem.h"
#include "I_Continuation.h"
#include "I_EThread.h"

int
Continuation::handleEvent(int event, void *data)
{
// If there is a lock, we must be holding it on entry
ink_release_assert(!mutex || mutex->thread_holding == this_ethread());
return (this->*handler)(event, data);
}

int
Continuation::dispatchEvent(int event, void *data)
{
if (mutex) {
EThread *t = this_ethread();
MUTEX_TRY_LOCK(lock, this->mutex, t);
if (!lock.is_locked()) {
t->schedule_imm(this, event, data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An event is created by schedule_imm, is there any mechanism to guarantee the Continuation will not be destroyed before the event call back. @shinrich

return 0;
} else {
return (this->*handler)(event, data);
}
} else {
return (this->*handler)(event, data);
}
}
22 changes: 16 additions & 6 deletions iocore/eventsystem/I_Continuation.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,28 @@ class Continuation : private force_VFPT_to_top
This function receives the event code and data for an event and
forwards them to the current continuation handler. The processor
calling back the continuation is responsible for acquiring its
lock.
lock. If the lock is present and not held, this method will assert.

@param event Event code to be passed at callback (Processor specific).
@param data General purpose data related to the event code (Processor specific).
@return State machine and processor specific return code.

*/
int
handleEvent(int event = CONTINUATION_EVENT_NONE, void *data = nullptr)
{
return (this->*handler)(event, data);
}
int handleEvent(int event = CONTINUATION_EVENT_NONE, void *data = nullptr);

/**
Receives the event code and data for an Event.

It will attempt to get the lock for the continuation, and reschedule
the event if the lock cannot be obtained. If the lock can be obtained
dispatchEvent acts like handleEvent.

@param event Event code to be passed at callback (Processor specific).
@param data General purpose data related to the event code (Processor specific).
@return State machine and processor specific return code.

*/
int dispatchEvent(int event = CONTINUATION_EVENT_NONE, void *data = nullptr);

protected:
/**
Expand Down
1 change: 1 addition & 0 deletions iocore/eventsystem/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ libinkevent_a_SOURCES = \
P_UnixSocketManager.h \
P_VConnection.h \
P_VIO.h \
Continuation.cc \
Processor.cc \
ProtectedQueue.cc \
ProxyAllocator.cc \
Expand Down
1 change: 1 addition & 0 deletions iocore/eventsystem/UnixEThread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ EThread::process_event(Event *e, int calling_code)
return;
}
Continuation *c_temp = e->continuation;
// Make sure that the contination is locked before calling the handler
e->continuation->handleEvent(calling_code, e);
ink_assert(!e->in_the_priority_queue);
ink_assert(c_temp == e->continuation);
Expand Down
2 changes: 1 addition & 1 deletion iocore/net/UnixNetAccept.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ net_accept(NetAccept *na, void *ep, bool blockable)
SET_CONTINUATION_HANDLER(vc, (NetVConnHandler)&UnixNetVConnection::acceptEvent);

if (e->ethread->is_event_type(na->opt.etype)) {
vc->handleEvent(EVENT_NONE, e);
vc->dispatchEvent(EVENT_NONE, e);
} else {
eventProcessor.schedule_imm(vc, na->opt.etype);
}
Expand Down
2 changes: 1 addition & 1 deletion iocore/net/UnixNetVConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ UnixNetVConnection::acceptEvent(int event, Event *e)
UnixNetVConnection::set_active_timeout(active_timeout_in);
}

action_.continuation->handleEvent(NET_EVENT_ACCEPT, this);
action_.continuation->dispatchEvent(NET_EVENT_ACCEPT, this);
return EVENT_DONE;
}

Expand Down
2 changes: 1 addition & 1 deletion proxy/http/HttpConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ HttpConfig::startup()

OutboundConnTrack::config_init(&c.outbound_conntrack, &c.oride.outbound_conntrack);

http_config_cont->handleEvent(EVENT_NONE, nullptr);
http_config_cont->dispatchEvent(EVENT_NONE, nullptr);

return;
}
Expand Down
10 changes: 5 additions & 5 deletions proxy/http/HttpSM.cc
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ HttpSM::setup_client_read_request_header()
ua_entry->read_vio = ua_txn->do_io_read(this, INT64_MAX, ua_buffer_reader->mbuf);
// The header may already be in the buffer if this
// a request from a keep-alive connection
handleEvent(VC_EVENT_READ_READY, ua_entry->read_vio);
dispatchEvent(VC_EVENT_READ_READY, ua_entry->read_vio);
}

void
Expand Down Expand Up @@ -866,7 +866,7 @@ HttpSM::state_watch_for_client_abort(int event, void *data)
"[%" PRId64 "] [watch_for_client_abort] "
"forwarding event %s to tunnel",
sm_id, HttpDebugNames::get_event_name(event));
tunnel.handleEvent(event, c->write_vio);
tunnel.dispatchEvent(event, c->write_vio);
return 0;
} else {
tunnel.kill_tunnel();
Expand Down Expand Up @@ -3954,7 +3954,7 @@ HttpSM::do_remap_request(bool run_inline)
if (!ret) {
SMDebug("url_rewrite", "Could not find a valid remapping entry for this request [%" PRId64 "]", sm_id);
if (!run_inline) {
handleEvent(EVENT_REMAP_COMPLETE, nullptr);
dispatchEvent(EVENT_REMAP_COMPLETE, nullptr);
}
return;
}
Expand Down Expand Up @@ -5402,13 +5402,13 @@ HttpSM::handle_server_setup_error(int event, void *data)

ua_producer->alive = false;
ua_producer->handler_state = HTTP_SM_POST_SERVER_FAIL;
tunnel.handleEvent(VC_EVENT_ERROR, c->write_vio);
tunnel.dispatchEvent(VC_EVENT_ERROR, c->write_vio);
return;
}
} else {
// c could be null here as well
if (c != nullptr) {
tunnel.handleEvent(event, c->write_vio);
tunnel.dispatchEvent(event, c->write_vio);
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions proxy/http/HttpTunnel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ HttpTunnel::tunnel_run(HttpTunnelProducer *p_arg)
// back to say we are done
if (!is_tunnel_alive()) {
active = false;
sm->handleEvent(HTTP_TUNNEL_EVENT_DONE, this);
sm->dispatchEvent(HTTP_TUNNEL_EVENT_DONE, this);
}
}

Expand Down Expand Up @@ -1640,7 +1640,7 @@ HttpTunnel::main_handler(int event, void *data)
if (reentrancy_count == 1) {
reentrancy_count = 0;
active = false;
sm->handleEvent(HTTP_TUNNEL_EVENT_DONE, this);
sm->dispatchEvent(HTTP_TUNNEL_EVENT_DONE, this);
return EVENT_DONE;
} else {
call_sm = true;
Expand Down
4 changes: 2 additions & 2 deletions src/traffic_server/InkAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ APIHook::invoke(int event, void *edata)
ink_assert(!"not reached");
}
}
return m_cont->handleEvent(event, edata);
return m_cont->dispatchEvent(event, edata);
}

APIHook *
Expand Down Expand Up @@ -4519,7 +4519,7 @@ int
TSContCall(TSCont contp, TSEvent event, void *edata)
{
Continuation *c = (Continuation *)contp;
return c->handleEvent((int)event, edata);
return c->dispatchEvent((int)event, edata);
}

TSMutex
Expand Down