diff options
author | dimitri staessens <[email protected]> | 2017-02-18 11:59:42 +0000 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2017-02-18 11:59:42 +0000 |
commit | 787fb78ff2fc54c36b37ecdf9b9c094800b9ef4c (patch) | |
tree | 895e42a615160cc2e6cd2187292cd2276354e6be | |
parent | f5ca2eed99c8fa741e8d2e8385d1b4f10e433df8 (diff) | |
parent | f53bf64bc8e1a72e24cd6bdd309cfe2dba801166 (diff) | |
download | ouroboros-787fb78ff2fc54c36b37ecdf9b9c094800b9ef4c.tar.gz ouroboros-787fb78ff2fc54c36b37ecdf9b9c094800b9ef4c.zip |
Merged in dstaesse/ouroboros/be-cdap (pull request #379)
lib: Set cdap_req state to REQ_NULL after timeout
-rw-r--r-- | src/lib/cdap_req.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/lib/cdap_req.c b/src/lib/cdap_req.c index 2f55b107..810ec9bf 100644 --- a/src/lib/cdap_req.c +++ b/src/lib/cdap_req.c @@ -65,17 +65,21 @@ void cdap_req_destroy(struct cdap_req * creq) pthread_mutex_lock(&creq->lock); - if (creq->state == REQ_DESTROY) { + switch(creq->state) { + case REQ_DESTROY: pthread_mutex_unlock(&creq->lock); return; - } - - if (creq->state == REQ_INIT) + case REQ_INIT: creq->state = REQ_NULL; - - if (creq->state == REQ_PENDING) { + pthread_cond_broadcast(&creq->cond); + break; + case REQ_PENDING: + case REQ_RESPONSE: creq->state = REQ_DESTROY; pthread_cond_broadcast(&creq->cond); + break; + default: + break; } while (creq->state != REQ_NULL) @@ -110,21 +114,25 @@ int cdap_req_wait(struct cdap_req * creq) creq->state = REQ_PENDING; pthread_cond_broadcast(&creq->cond); - while (creq->state == REQ_PENDING) { + while (creq->state == REQ_PENDING && ret != -ETIMEDOUT) ret = -pthread_cond_timedwait(&creq->cond, &creq->lock, &abstime); - if (ret == -ETIMEDOUT) - break; - } - if (creq->state == REQ_DESTROY) { + switch(creq->state) { + case REQ_DESTROY: ret = -1; + case REQ_PENDING: creq->state = REQ_NULL; pthread_cond_broadcast(&creq->cond); - } else { + break; + case REQ_RESPONSE: creq->state = REQ_DONE; pthread_cond_broadcast(&creq->cond); + break; + default: + assert(false); + break; } pthread_mutex_unlock(&creq->lock); |