You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ma...@apache.org on 2018/11/21 00:11:48 UTC
[trafficserver] branch master updated: Unify cross event scheduling
code
This is an automated email from the ASF dual-hosted git repository.
maskit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new a5f145d Unify cross event scheduling code
a5f145d is described below
commit a5f145d9ade9a2ba41448d15c4fd22381f4df4e2
Author: Masakazu Kitajo <ma...@apache.org>
AuthorDate: Sun Nov 11 18:06:52 2018 +0900
Unify cross event scheduling code
---
proxy/http2/Http2Stream.cc | 55 ++++++++++++++++++++++++++--------------------
proxy/http2/Http2Stream.h | 13 ++++++-----
2 files changed, 38 insertions(+), 30 deletions(-)
diff --git a/proxy/http2/Http2Stream.cc b/proxy/http2/Http2Stream.cc
index 2e1e65e..429b55f 100644
--- a/proxy/http2/Http2Stream.cc
+++ b/proxy/http2/Http2Stream.cc
@@ -34,19 +34,16 @@ ClassAllocator<Http2Stream> http2StreamAllocator("http2StreamAllocator");
int
Http2Stream::main_event_handler(int event, void *edata)
{
- Event *e = static_cast<Event *>(edata);
+ SCOPED_MUTEX_LOCK(lock, this->mutex, this_ethread());
- Thread *this_thread = this_ethread();
- if (this->get_thread() != this_thread) {
- // Send on to the owning thread
- if (cross_thread_event == nullptr) {
- cross_thread_event = this->get_thread()->schedule_imm(this, event, edata);
- }
+ if (!this->_switch_thread_if_not_on_right_thread(event, edata)) {
+ // Not on the right thread
return 0;
}
+ ink_release_assert(this->_thread == this_ethread());
+
+ Event *e = static_cast<Event *>(edata);
reentrancy_count++;
- ink_release_assert(this->get_thread() == this_ethread());
- SCOPED_MUTEX_LOCK(lock, this->mutex, this_ethread());
if (e == cross_thread_event) {
cross_thread_event = nullptr;
} else if (e == active_event) {
@@ -467,15 +464,13 @@ Http2Stream::update_read_request(int64_t read_len, bool call_update, bool check_
if (closed || parent == nullptr || current_reader == nullptr || read_vio.mutex == nullptr) {
return;
}
- if (this->get_thread() != this_ethread()) {
- SCOPED_MUTEX_LOCK(stream_lock, this->mutex, this_ethread());
- if (cross_thread_event == nullptr) {
- // Send to the right thread
- cross_thread_event = this->get_thread()->schedule_imm(this, VC_EVENT_READ_READY, nullptr);
- }
+
+ if (!this->_switch_thread_if_not_on_right_thread(VC_EVENT_READ_READY, nullptr)) {
+ // Not on the right thread
return;
}
- ink_release_assert(this->get_thread() == this_ethread());
+ ink_release_assert(this->_thread == this_ethread());
+
SCOPED_MUTEX_LOCK(lock, read_vio.mutex, this_ethread());
if (read_vio.nbytes > 0 && read_vio.ndone <= read_vio.nbytes) {
// If this vio has a different buffer, we must copy
@@ -532,15 +527,13 @@ Http2Stream::update_write_request(IOBufferReader *buf_reader, int64_t write_len,
(buf_reader == nullptr && write_len == 0)) {
return;
}
- if (this->get_thread() != this_ethread()) {
- SCOPED_MUTEX_LOCK(stream_lock, this->mutex, this_ethread());
- if (cross_thread_event == nullptr) {
- // Send to the right thread
- cross_thread_event = this->get_thread()->schedule_imm(this, VC_EVENT_WRITE_READY, nullptr);
- }
+
+ if (!this->_switch_thread_if_not_on_right_thread(VC_EVENT_WRITE_READY, nullptr)) {
+ // Not on the right thread
return;
}
- ink_release_assert(this->get_thread() == this_ethread());
+ ink_release_assert(this->_thread == this_ethread());
+
Http2ClientSession *parent = static_cast<Http2ClientSession *>(this->get_parent());
SCOPED_MUTEX_LOCK(lock, write_vio.mutex, this_ethread());
@@ -550,7 +543,7 @@ Http2Stream::update_write_request(IOBufferReader *buf_reader, int64_t write_len,
if (this->chunked) {
if (chunked_handler.dechunked_buffer && chunked_handler.dechunked_buffer->max_read_avail() > HTTP2_MAX_BUFFER_USAGE) {
if (buffer_full_write_event == nullptr) {
- buffer_full_write_event = get_thread()->schedule_imm(this, VC_EVENT_WRITE_READY);
+ buffer_full_write_event = _thread->schedule_imm(this, VC_EVENT_WRITE_READY);
}
} else {
this->response_process_data(is_done);
@@ -887,3 +880,17 @@ Http2Stream::release(IOBufferReader *r)
current_reader = nullptr; // State machine is on its own way down.
this->do_io_close();
}
+
+bool
+Http2Stream::_switch_thread_if_not_on_right_thread(int event, void *edata)
+{
+ if (this->_thread != this_ethread()) {
+ SCOPED_MUTEX_LOCK(stream_lock, this->mutex, this_ethread());
+ if (cross_thread_event == nullptr) {
+ // Send to the right thread
+ cross_thread_event = this->_thread->schedule_imm(this, event, edata);
+ }
+ return false;
+ }
+ return true;
+}
diff --git a/proxy/http2/Http2Stream.h b/proxy/http2/Http2Stream.h
index b46134d..bc74c72 100644
--- a/proxy/http2/Http2Stream.h
+++ b/proxy/http2/Http2Stream.h
@@ -180,12 +180,6 @@ public:
MIOBuffer request_buffer = CLIENT_CONNECTION_FIRST_READ_BUFFER_SIZE_INDEX;
Http2DependencyTree::Node *priority_node = nullptr;
- EThread *
- get_thread()
- {
- return _thread;
- }
-
IOBufferReader *response_get_data_reader() const;
bool
response_is_chunked() const
@@ -235,6 +229,13 @@ private:
Event *send_tracked_event(Event *event, int send_event, VIO *vio);
void send_response_body(bool call_update);
+ /**
+ * Check if this thread is the right thread to process events for this
+ * continuation.
+ * Return true if the caller can continue event processing.
+ */
+ bool _switch_thread_if_not_on_right_thread(int event, void *edata);
+
HTTPParser http_parser;
ink_hrtime _start_time = 0;
EThread *_thread = nullptr;