summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-09-07 18:43:52 +0200
committerdimitri staessens <dimitri.staessens@ugent.be>2017-09-07 18:43:52 +0200
commit08c1a279ed1909d7560038a3628598133f031742 (patch)
tree4897dfeaa541325fc3c7990e17b7d8c5a3099edc /src/ipcpd/normal
parentf01187436eb51f955db604ad5fd19bf1389fb544 (diff)
downloadouroboros-08c1a279ed1909d7560038a3628598133f031742.tar.gz
ouroboros-08c1a279ed1909d7560038a3628598133f031742.zip
ipcpd: Shutdown DHT work thread first at destroy
This prevents a potential deadlock on the wrlock.
Diffstat (limited to 'src/ipcpd/normal')
-rw-r--r--src/ipcpd/normal/dht.c10
1 files 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);