From 08c1a279ed1909d7560038a3628598133f031742 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Thu, 7 Sep 2017 18:43:52 +0200 Subject: ipcpd: Shutdown DHT work thread first at destroy This prevents a potential deadlock on the wrlock. --- src/ipcpd/normal/dht.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ipcpd/normal/dht.c b/src/ipcpd/normal/dht.c index f24ed932..d139cb91 100644 --- a/src/ipcpd/normal/dht.c +++ b/src/ipcpd/normal/dht.c @@ -2335,8 +2335,11 @@ void dht_destroy(struct dht * dht) if (dht == NULL) return; - if (dht_get_state(dht) == DHT_RUNNING) + if (dht_get_state(dht) == DHT_RUNNING) { dht_set_state(dht, DHT_SHUTDOWN); + pthread_cancel(dht->worker); + pthread_join(dht->worker, NULL); + } pthread_rwlock_wrlock(&dht->lock); @@ -2366,11 +2369,6 @@ void dht_destroy(struct dht * dht) pthread_rwlock_unlock(&dht->lock); - if (dht_get_state(dht) == DHT_SHUTDOWN) { - pthread_cancel(dht->worker); - pthread_join(dht->worker, NULL); - } - if (dht->buckets != NULL) bucket_destroy(dht->buckets); -- cgit v1.2.3