Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[isolate] consume all queue on channel tick

  • Loading branch information...
commit c8f37f2b40648b066c67f0a29f4561db9233e46e 1 parent e8726c6
@indutny authored
Showing with 14 additions and 5 deletions.
  1. +14 −5 src/node_isolate.cc
View
19 src/node_isolate.cc
@@ -78,9 +78,7 @@ class Queue {
~Queue() {
IF_DEBUG({
- uv_mutex_lock(&mutex_);
- assert(ngx_queue_empty(&queue_));
- uv_mutex_unlock(&mutex_);
+ assert(IsEmpty());
})
uv_mutex_destroy(&mutex_);
}
@@ -107,6 +105,15 @@ class Queue {
return item;
}
+ bool IsEmpty() {
+ bool result;
+ uv_mutex_lock(&mutex_);
+ result = ngx_queue_empty(&queue_);
+ uv_mutex_unlock(&mutex_);
+
+ return result;
+ }
+
private:
struct Message {
ngx_queue_t queue_;
@@ -147,8 +154,10 @@ class Channel {
}
void OnMessage() {
- T item = queue_.Consume();
- callback_(item, arg_);
+ while (!queue_.IsEmpty()) {
+ T item = queue_.Consume();
+ callback_(item, arg_);
+ }
}
void* arg_;

1 comment on commit c8f37f2

@bnoordhuis

I didn't take this commit. I took a slightly different approach in 97e4b3a.

Please sign in to comment.
Something went wrong with that request. Please try again.