From 001526cc4ce6b3ec55fddcc927d9f610b162a657 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 18 Apr 2019 00:54:59 +0200 Subject: [PATCH] worker: move `receiving_messages_` field to `MessagePort` This is a property of the native object associated with the `MessagePort`, not something that should be set on the conceptual `MessagePort` that may be transferred around. PR-URL: https://github.com/nodejs/node/pull/27705 Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig --- src/node_messaging.cc | 11 +++++------ src/node_messaging.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/node_messaging.cc b/src/node_messaging.cc index c7d0b327003f41..b9212ba272d0fe 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -588,9 +588,9 @@ void MessagePort::OnMessage() { Mutex::ScopedLock lock(data_->mutex_); Debug(this, "MessagePort has message, receiving = %d", - static_cast(data_->receiving_messages_)); + static_cast(receiving_messages_)); - if (!data_->receiving_messages_) + if (!receiving_messages_) break; if (data_->incoming_messages_.empty()) break; @@ -722,17 +722,16 @@ void MessagePort::PostMessage(const FunctionCallbackInfo& args) { } void MessagePort::Start() { - Mutex::ScopedLock lock(data_->mutex_); Debug(this, "Start receiving messages"); - data_->receiving_messages_ = true; + receiving_messages_ = true; + Mutex::ScopedLock lock(data_->mutex_); if (!data_->incoming_messages_.empty()) TriggerAsync(); } void MessagePort::Stop() { - Mutex::ScopedLock lock(data_->mutex_); Debug(this, "Stop receiving messages"); - data_->receiving_messages_ = false; + receiving_messages_ = false; } void MessagePort::Start(const FunctionCallbackInfo& args) { diff --git a/src/node_messaging.h b/src/node_messaging.h index aa2559af2c8061..0a729c141088cb 100644 --- a/src/node_messaging.h +++ b/src/node_messaging.h @@ -116,7 +116,6 @@ class MessagePortData : public MemoryRetainer { // This mutex protects all fields below it, with the exception of // sibling_. mutable Mutex mutex_; - bool receiving_messages_ = false; std::list incoming_messages_; MessagePort* owner_ = nullptr; // This mutex protects the sibling_ field and is shared between two entangled @@ -205,6 +204,7 @@ class MessagePort : public HandleWrap { void TriggerAsync(); std::unique_ptr data_ = nullptr; + bool receiving_messages_ = false; uv_async_t async_; friend class MessagePortData;