Use the shared nodes_lock also for final nodes

parent e1d456a7
......@@ -581,7 +581,7 @@ fini_final(struct vdp_ctx *vdx, struct node *node)
if (node->final.fi_state == FI_DESTROYED)
return;
AZ(pthread_mutex_lock(&node->final.fi_mtx));
Lck_Lock(node->final.shared_lock);
if (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)
}
if (node->final.fi_state < FI_DONE)
AZ(pthread_cond_wait(&node->final.fi_cond,
&node->final.fi_mtx));
AZ(Lck_CondWait(&node->final.fi_cond,
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);
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;
}
......@@ -690,16 +690,16 @@ push_final(struct vdp_ctx *vdx, struct bytes_tree *tree,
assert(node->type == T_FINAL);
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;
AZ(pthread_cond_signal(&node->final.fi_cond));
if (node->final.fi_state < FI_DONE)
AZ(pthread_cond_wait(&node->final.fi_cond,
&node->final.fi_mtx));
AZ(Lck_CondWait(&node->final.fi_cond,
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);
return (tree->retval);
......
......@@ -173,9 +173,9 @@ enum fi_state {
/* we block the sub-thread when it's ready for delivery and continue when the
* topreqp tells it to */
struct node_final {
enum fi_state fi_state;
pthread_mutex_t fi_mtx;
struct lock *shared_lock; // == &tree->nodes_lock
pthread_cond_t fi_cond;
enum fi_state fi_state;
};
enum n_alloc {
......@@ -184,7 +184,7 @@ enum n_alloc {
NA_MPL
} __attribute__ ((__packed__));
struct node { // 128b
struct node { // 120b
unsigned magic;
#define NODE_MAGIC 0xe31edef3
enum n_type type;
......@@ -199,7 +199,7 @@ struct node { // 128b
struct node_nexus nexus; // T_NEXUS 72b
struct node_data data; // T_DATA 32b
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
};
};
......
......@@ -1440,24 +1440,24 @@ vped_deliver(struct req *req, struct boc *boc, int wantbody)
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));
assert(node->final.fi_state == FI_READY);
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
* 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);
if (node->final.fi_state < FI_GO)
AZ(pthread_cond_wait(&node->final.fi_cond,
&node->final.fi_mtx));
AZ(Lck_CondWait(&node->final.fi_cond,
node->final.shared_lock));
assert(node->final.fi_state == FI_GO);
......@@ -1467,7 +1467,7 @@ vped_deliver(struct req *req, struct boc *boc, int wantbody)
node->final.fi_state = FI_DONE;
AZ(pthread_cond_signal(&node->final.fi_cond));
AZ(pthread_mutex_unlock(&node->final.fi_mtx));
Lck_Unlock(node->final.shared_lock);
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