about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--include/uv_link_t.h4
-rw-r--r--src/uv_link_t.c18
2 files changed, 16 insertions, 6 deletions
diff --git a/include/uv_link_t.h b/include/uv_link_t.h
index 34c7760..a5710e2 100644
--- a/include/uv_link_t.h
+++ b/include/uv_link_t.h
@@ -66,7 +66,9 @@ struct uv_link_methods_s {
     /* Private, used for close */                                             \
     int close_depth;                                                          \
     int close_waiting;                                                        \
-    uv_link_close_cb saved_close_cb;
+    uv_link_close_cb saved_close_cb;                                          \
+    uv_link_close_cb pending_close_cb;                                        \
+    uv_link_t* pending_close_source;
 
 struct uv_link_s {
   UV_LINK_FIELDS
diff --git a/src/uv_link_t.c b/src/uv_link_t.c
index 9058b55..59b5fa7 100644
--- a/src/uv_link_t.c
+++ b/src/uv_link_t.c
@@ -87,14 +87,17 @@ void uv_link_close(uv_link_t* link, uv_link_close_cb cb) {
 
 void uv_link_maybe_close(uv_link_t* link) {
   uv_link_close_cb cb;
+  uv_link_t* source;
 
-  if (link->saved_close_cb == NULL)
+  if (link->pending_close_cb == NULL)
     return;
 
-  cb = link->saved_close_cb;
+  cb = link->pending_close_cb;
+  source = link->pending_close_source;
 
-  link->saved_close_cb = NULL;
-  return uv_link_propagate_close(link, link, cb);
+  link->pending_close_cb = NULL;
+  link->pending_close_source = NULL;
+  return uv_link_propagate_close(link, source, cb);
 }
 
 
@@ -139,7 +142,12 @@ void uv_link_propagate_close(uv_link_t* link, uv_link_t* source,
     if (child != NULL)
       CHECK_EQ(uv_link_unchain(root, child), 0, "close unchain");
 
-    root->methods->close(root, source, uv_link_close_join);
+    if (root->close_depth == 0) {
+      root->methods->close(root, source, uv_link_close_join);
+    } else {
+      root->pending_close_cb = uv_link_close_join;
+      root->pending_close_source = source;
+    }
     root = child;
   }
 }