Use the shared nodes_lock also for final nodes

parent e1d456a7
...@@ -581,7 +581,7 @@ fini_final(struct vdp_ctx *vdx, struct node *node) ...@@ -581,7 +581,7 @@ fini_final(struct vdp_ctx *vdx, struct node *node)
if (node->final.fi_state == FI_DESTROYED) if (node->final.fi_state == FI_DESTROYED)
return; return;
AZ(pthread_mutex_lock(&node->final.fi_mtx)); Lck_Lock(node->final.shared_lock);
if (node->final.fi_state < FI_GO) { if (node->final.fi_state < FI_GO) {
node->final.fi_state = FI_GO; node->final.fi_state = FI_GO;
...@@ -589,15 +589,15 @@ fini_final(struct vdp_ctx *vdx, struct node *node) ...@@ -589,15 +589,15 @@ fini_final(struct vdp_ctx *vdx, struct node *node)
} }
if (node->final.fi_state < FI_DONE) if (node->final.fi_state < FI_DONE)
AZ(pthread_cond_wait(&node->final.fi_cond, AZ(Lck_CondWait(&node->final.fi_cond,
&node->final.fi_mtx)); node->final.shared_lock));
AZ(pthread_mutex_unlock(&node->final.fi_mtx)); Lck_Unlock(node->final.shared_lock);
assert(node->final.fi_state == FI_DONE); assert(node->final.fi_state == FI_DONE);
AZ(pthread_cond_destroy(&node->final.fi_cond)); AZ(pthread_cond_destroy(&node->final.fi_cond));
AZ(pthread_mutex_destroy(&node->final.fi_mtx)); node->final.shared_lock = NULL;
node->final.fi_state = FI_DESTROYED; node->final.fi_state = FI_DESTROYED;
} }
...@@ -690,16 +690,16 @@ push_final(struct vdp_ctx *vdx, struct bytes_tree *tree, ...@@ -690,16 +690,16 @@ push_final(struct vdp_ctx *vdx, struct bytes_tree *tree,
assert(node->type == T_FINAL); assert(node->type == T_FINAL);
assert(node->final.fi_state == FI_READY); assert(node->final.fi_state == FI_READY);
AZ(pthread_mutex_lock(&node->final.fi_mtx)); Lck_Lock(node->final.shared_lock);
node->final.fi_state = FI_GO; node->final.fi_state = FI_GO;
AZ(pthread_cond_signal(&node->final.fi_cond)); AZ(pthread_cond_signal(&node->final.fi_cond));
if (node->final.fi_state < FI_DONE) if (node->final.fi_state < FI_DONE)
AZ(pthread_cond_wait(&node->final.fi_cond, AZ(Lck_CondWait(&node->final.fi_cond,
&node->final.fi_mtx)); node->final.shared_lock));
AZ(pthread_mutex_unlock(&node->final.fi_mtx)); Lck_Unlock(node->final.shared_lock);
assert(node->final.fi_state == FI_DONE); assert(node->final.fi_state == FI_DONE);
return (tree->retval); return (tree->retval);
......
...@@ -173,9 +173,9 @@ enum fi_state { ...@@ -173,9 +173,9 @@ enum fi_state {
/* we block the sub-thread when it's ready for delivery and continue when the /* we block the sub-thread when it's ready for delivery and continue when the
* topreqp tells it to */ * topreqp tells it to */
struct node_final { struct node_final {
enum fi_state fi_state; struct lock *shared_lock; // == &tree->nodes_lock
pthread_mutex_t fi_mtx;
pthread_cond_t fi_cond; pthread_cond_t fi_cond;
enum fi_state fi_state;
}; };
enum n_alloc { enum n_alloc {
...@@ -184,7 +184,7 @@ enum n_alloc { ...@@ -184,7 +184,7 @@ enum n_alloc {
NA_MPL NA_MPL
} __attribute__ ((__packed__)); } __attribute__ ((__packed__));
struct node { // 128b struct node { // 120b
unsigned magic; unsigned magic;
#define NODE_MAGIC 0xe31edef3 #define NODE_MAGIC 0xe31edef3
enum n_type type; enum n_type type;
...@@ -199,7 +199,7 @@ struct node { // 128b ...@@ -199,7 +199,7 @@ struct node { // 128b
struct node_nexus nexus; // T_NEXUS 72b struct node_nexus nexus; // T_NEXUS 72b
struct node_data data; // T_DATA 32b struct node_data data; // T_DATA 32b
struct node_subreq subreq; // T_SUBREQ 88b struct node_subreq subreq; // T_SUBREQ 88b
struct node_final final; // T_FINAL 96b struct node_final final; // T_FINAL 64b
struct node_crc crc; // T_CRC 16b struct node_crc crc; // T_CRC 16b
}; };
}; };
......
...@@ -1440,24 +1440,24 @@ vped_deliver(struct req *req, struct boc *boc, int wantbody) ...@@ -1440,24 +1440,24 @@ vped_deliver(struct req *req, struct boc *boc, int wantbody)
node_mutate_prep(tree, node); node_mutate_prep(tree, node);
AZ(pthread_mutex_init(&node->final.fi_mtx, NULL)); node->final.shared_lock = &tree->nodes_lock;
AZ(pthread_cond_init(&node->final.fi_cond, NULL)); AZ(pthread_cond_init(&node->final.fi_cond, NULL));
assert(node->final.fi_state == FI_READY); assert(node->final.fi_state == FI_READY);
node_mutate_lock(tree, node, T_FINAL, ST_DATA); node_mutate_lock(tree, node, T_FINAL, ST_DATA);
/* /*
* we deliberately take the fi_mtx under the tree mutex (via * we deliberately take the nodes lock under the tree mutex (via
* node_mutate_lock) to ensure unpending never gets unlocked * node_mutate_lock) to ensure unpending never gets unlocked
* access to ensure we get the signal * access to ensure we get the signal
*/ */
AZ(pthread_mutex_lock(&node->final.fi_mtx)); Lck_Lock(node->final.shared_lock);
node_mutate_unlock(tree); node_mutate_unlock(tree);
if (node->final.fi_state < FI_GO) if (node->final.fi_state < FI_GO)
AZ(pthread_cond_wait(&node->final.fi_cond, AZ(Lck_CondWait(&node->final.fi_cond,
&node->final.fi_mtx)); node->final.shared_lock));
assert(node->final.fi_state == FI_GO); assert(node->final.fi_state == FI_GO);
...@@ -1467,7 +1467,7 @@ vped_deliver(struct req *req, struct boc *boc, int wantbody) ...@@ -1467,7 +1467,7 @@ vped_deliver(struct req *req, struct boc *boc, int wantbody)
node->final.fi_state = FI_DONE; node->final.fi_state = FI_DONE;
AZ(pthread_cond_signal(&node->final.fi_cond)); AZ(pthread_cond_signal(&node->final.fi_cond));
AZ(pthread_mutex_unlock(&node->final.fi_mtx)); Lck_Unlock(node->final.shared_lock);
return; return;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment