dm: safely use pthread_cond_broadcast()

Use pthread_cond_broadcast() while holding the mutex to guarantee the
signaling of its condition variable.

Tracked-On: #2763
Signed-off-by: Peter Fang <peter.fang@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
This commit is contained in:
Peter Fang 2019-03-17 01:57:50 -07:00 committed by wenlingz
parent fa375a2aa1
commit 18aebc0196
2 changed files with 4 additions and 2 deletions

View File

@ -925,8 +925,9 @@ blockif_close(struct blockif_ctxt *bc)
*/
pthread_mutex_lock(&bc->mtx);
bc->closing = 1;
pthread_mutex_unlock(&bc->mtx);
pthread_cond_broadcast(&bc->cond);
pthread_mutex_unlock(&bc->mtx);
for (i = 0; i < BLOCKIF_NUMTHR; i++)
pthread_join(bc->btid[i], &jval);

View File

@ -295,9 +295,10 @@ virtio_net_tx_stop(struct virtio_net *net)
{
void *jval;
pthread_mutex_lock(&net->tx_mtx);
net->closing = 1;
pthread_cond_broadcast(&net->tx_cond);
pthread_mutex_unlock(&net->tx_mtx);
pthread_join(net->tx_tid, &jval);
}