diff options
author | dimitri staessens <[email protected]> | 2017-08-29 15:45:44 +0000 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2017-08-29 15:45:44 +0000 |
commit | f7942245a37c591d3c3b8d6526dcc38dcf255d25 (patch) | |
tree | 276c1b3d0d3dece08bd78162946df8433d1c04f3 /src/ipcpd/normal | |
parent | 768064e211c311142697335b3e9c714ea54b204a (diff) | |
parent | b05dbd778f16eb4c977e7769bd1ba03dd4e55b90 (diff) | |
download | ouroboros-f7942245a37c591d3c3b8d6526dcc38dcf255d25.tar.gz ouroboros-f7942245a37c591d3c3b8d6526dcc38dcf255d25.zip |
Merged in dstaesse/ouroboros/be-dht (pull request #577)
ipcpd: Fix state in dht lookup at lookup_wait
Diffstat (limited to 'src/ipcpd/normal')
-rw-r--r-- | src/ipcpd/normal/dht.c | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/src/ipcpd/normal/dht.c b/src/ipcpd/normal/dht.c index b5bac913..a1d21ad7 100644 --- a/src/ipcpd/normal/dht.c +++ b/src/ipcpd/normal/dht.c @@ -837,6 +837,24 @@ static void lookup_new_addrs(struct lookup * lu, pthread_mutex_unlock(&lu->lock); } +static void lookup_set_state(struct lookup * lu, + enum lookup_state state) +{ + pthread_mutex_lock(&lu->lock); + + lu->state = state; + pthread_cond_signal(&lu->cond); + + pthread_mutex_unlock(&lu->lock); +} + +static void cleanup_wait(void * o) +{ + struct lookup * lu = (struct lookup *) o; + lookup_set_state(lu, LU_NULL); + lookup_destroy(lu); +} + static enum lookup_state lookup_wait(struct lookup * lu) { struct timespec timeo = {KAD_T_RESP, 0}; @@ -853,7 +871,7 @@ static enum lookup_state lookup_wait(struct lookup * lu) lu->state = LU_PENDING; pthread_cond_signal(&lu->cond); - pthread_cleanup_push((void (*)(void *)) lookup_destroy, (void *) lu); + pthread_cleanup_push(cleanup_wait, lu); while (lu->state == LU_PENDING && ret != -ETIMEDOUT) ret = -pthread_cond_timedwait(&lu->cond, &lu->lock, &abs); @@ -861,9 +879,9 @@ static enum lookup_state lookup_wait(struct lookup * lu) pthread_cleanup_pop(false); if (ret == -ETIMEDOUT) - state = LU_COMPLETE; - else - state = lu->state; + lu->state = LU_COMPLETE; + + state = lu->state; pthread_mutex_unlock(&lu->lock); @@ -1501,17 +1519,6 @@ static ssize_t kad_find(struct dht * dht, return sent; } -static void lookup_set_state(struct lookup * lu, - enum lookup_state state) -{ - pthread_mutex_lock(&lu->lock); - - lu->state = state; - pthread_cond_signal(&lu->cond); - - pthread_mutex_unlock(&lu->lock); -} - static struct lookup * kad_lookup(struct dht * dht, const uint8_t * id, enum kad_code code) @@ -1540,7 +1547,6 @@ static struct lookup * kad_lookup(struct dht * dht, pthread_rwlock_wrlock(&dht->lock); list_del(&lu->next); pthread_rwlock_unlock(&dht->lock); - lu->state = LU_COMPLETE; return lu; } @@ -1554,6 +1560,7 @@ static struct lookup * kad_lookup(struct dht * dht, pthread_rwlock_wrlock(&dht->lock); list_del(&lu->next); pthread_rwlock_unlock(&dht->lock); + lookup_set_state(lu, LU_COMPLETE); return lu; } |