summaryrefslogtreecommitdiff
path: root/src/lib/cdap.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-08-01 11:17:42 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-08-01 11:17:42 +0200
commit84293e0e57ee2a3d779a575717fbc54f8e94e178 (patch)
treee0825f5586c2870839f15e0c8f4b390463145cd0 /src/lib/cdap.c
parent434c782c99496b491684f4ab0058d9491c250774 (diff)
parentcf719963be2e42026012e152ae49f4c764dd9b4f (diff)
downloadouroboros-84293e0e57ee2a3d779a575717fbc54f8e94e178.tar.gz
ouroboros-84293e0e57ee2a3d779a575717fbc54f8e94e178.zip
Merged in sandervrijders/ouroboros/be-enrolment (pull request #182)
Be enrolment
Diffstat (limited to 'src/lib/cdap.c')
-rw-r--r--src/lib/cdap.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/src/lib/cdap.c b/src/lib/cdap.c
index 4275bfc7..4599fd8b 100644
--- a/src/lib/cdap.c
+++ b/src/lib/cdap.c
@@ -69,6 +69,28 @@ static ssize_t cdap_msg_to_buffer(cdap_t * msg,
return len;
}
+static int next_invoke_id(struct cdap * instance)
+{
+ int ret;
+
+ pthread_mutex_lock(&instance->ids_lock);
+ ret = bmp_allocate(instance->ids);
+ pthread_mutex_unlock(&instance->ids_lock);
+
+ return ret;
+}
+
+static int release_invoke_id(struct cdap * instance,
+ int id)
+{
+ int ret;
+
+ pthread_mutex_lock(&instance->ids_lock);
+ ret = bmp_release(instance->ids, id);
+ pthread_mutex_unlock(&instance->ids_lock);
+
+ return ret;
+}
static void * sdu_reader(void * o)
{
@@ -146,6 +168,7 @@ static void * sdu_reader(void * o)
msg->result,
val,
length);
+ release_invoke_id(instance, msg->invoke_id);
free(val);
}
break;
@@ -189,6 +212,7 @@ struct cdap * cdap_create(struct cdap_ops * ops,
}
instance->ops = ops;
+ instance->fd = fd;
instance->ids = bmp_create(IDS_SIZE, 0);
if (instance->ids == NULL) {
@@ -211,6 +235,9 @@ int cdap_destroy(struct cdap * instance)
pthread_cancel(instance->reader);
+ if (flow_dealloc(instance->fd))
+ return -1;
+
pthread_mutex_lock(&instance->ids_lock);
bmp_destroy(instance->ids);
@@ -225,29 +252,6 @@ int cdap_destroy(struct cdap * instance)
return 0;
}
-static int next_invoke_id(struct cdap * instance)
-{
- int ret;
-
- pthread_mutex_lock(&instance->ids_lock);
- ret = bmp_allocate(instance->ids);
- pthread_mutex_unlock(&instance->ids_lock);
-
- return ret;
-}
-
-static int release_invoke_id(struct cdap * instance,
- int id)
-{
- int ret;
-
- pthread_mutex_lock(&instance->ids_lock);
- ret = bmp_release(instance->ids, id);
- pthread_mutex_unlock(&instance->ids_lock);
-
- return ret;
-}
-
static int write_msg(struct cdap * instance,
cdap_t * msg)
{