diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2017-02-17 23:51:57 +0100 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2017-02-18 00:07:16 +0100 |
commit | f53bf64bc8e1a72e24cd6bdd309cfe2dba801166 (patch) | |
tree | 895e42a615160cc2e6cd2187292cd2276354e6be /src/lib/cdap_req.c | |
parent | 645cf66af11ac36b81648f2e1eb3b1f5aeb7b544 (diff) | |
download | ouroboros-f53bf64bc8e1a72e24cd6bdd309cfe2dba801166.tar.gz ouroboros-f53bf64bc8e1a72e24cd6bdd309cfe2dba801166.zip |
lib: Set cdap_req state to REQ_NULL after timeout
This prevented destruction of a CDAP instance that had a timed out
request.
Diffstat (limited to 'src/lib/cdap_req.c')
-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); |