Skip to content

Commit

Permalink
worker: move receiving_messages_ field to MessagePort
Browse files Browse the repository at this point in the history
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 <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
addaleax authored and targos committed May 18, 2019
1 parent 1f935f8 commit b7ed4d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/node_messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,9 @@ void MessagePort::OnMessage() {
Mutex::ScopedLock lock(data_->mutex_);

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

if (!data_->receiving_messages_)
if (!receiving_messages_)
break;
if (data_->incoming_messages_.empty())
break;
Expand Down Expand Up @@ -722,17 +722,16 @@ void MessagePort::PostMessage(const FunctionCallbackInfo<Value>& 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<Value>& args) {
Expand Down
2 changes: 1 addition & 1 deletion src/node_messaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Message> incoming_messages_;
MessagePort* owner_ = nullptr;
// This mutex protects the sibling_ field and is shared between two entangled
Expand Down Expand Up @@ -205,6 +204,7 @@ class MessagePort : public HandleWrap {
void TriggerAsync();

std::unique_ptr<MessagePortData> data_ = nullptr;
bool receiving_messages_ = false;
uv_async_t async_;

friend class MessagePortData;
Expand Down

0 comments on commit b7ed4d7

Please sign in to comment.