Skip to content

Commit b7ed4d7

Browse files
addaleaxtargos
authored andcommitted
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: #27705 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 1f935f8 commit b7ed4d7

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/node_messaging.cc

+5-6
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,9 @@ void MessagePort::OnMessage() {
588588
Mutex::ScopedLock lock(data_->mutex_);
589589

590590
Debug(this, "MessagePort has message, receiving = %d",
591-
static_cast<int>(data_->receiving_messages_));
591+
static_cast<int>(receiving_messages_));
592592

593-
if (!data_->receiving_messages_)
593+
if (!receiving_messages_)
594594
break;
595595
if (data_->incoming_messages_.empty())
596596
break;
@@ -722,17 +722,16 @@ void MessagePort::PostMessage(const FunctionCallbackInfo<Value>& args) {
722722
}
723723

724724
void MessagePort::Start() {
725-
Mutex::ScopedLock lock(data_->mutex_);
726725
Debug(this, "Start receiving messages");
727-
data_->receiving_messages_ = true;
726+
receiving_messages_ = true;
727+
Mutex::ScopedLock lock(data_->mutex_);
728728
if (!data_->incoming_messages_.empty())
729729
TriggerAsync();
730730
}
731731

732732
void MessagePort::Stop() {
733-
Mutex::ScopedLock lock(data_->mutex_);
734733
Debug(this, "Stop receiving messages");
735-
data_->receiving_messages_ = false;
734+
receiving_messages_ = false;
736735
}
737736

738737
void MessagePort::Start(const FunctionCallbackInfo<Value>& args) {

src/node_messaging.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ class MessagePortData : public MemoryRetainer {
116116
// This mutex protects all fields below it, with the exception of
117117
// sibling_.
118118
mutable Mutex mutex_;
119-
bool receiving_messages_ = false;
120119
std::list<Message> incoming_messages_;
121120
MessagePort* owner_ = nullptr;
122121
// This mutex protects the sibling_ field and is shared between two entangled
@@ -205,6 +204,7 @@ class MessagePort : public HandleWrap {
205204
void TriggerAsync();
206205

207206
std::unique_ptr<MessagePortData> data_ = nullptr;
207+
bool receiving_messages_ = false;
208208
uv_async_t async_;
209209

210210
friend class MessagePortData;

0 commit comments

Comments
 (0)