summaryrefslogtreecommitdiff
path: root/src/irmd
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-06-14 09:26:07 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-06-14 09:26:07 +0200
commitf8afe1b570c4829bdc47e5963c93609e7196f414 (patch)
tree80a7ef5022e9ba023dcbf61a0ea51f05f5fe81c1 /src/irmd
parent7834e92b218da69cd934679dec9c2d714d89d15e (diff)
downloadouroboros-f8afe1b570c4829bdc47e5963c93609e7196f414.tar.gz
ouroboros-f8afe1b570c4829bdc47e5963c93609e7196f414.zip
irmd: cond_var to wait for ap to accept
A condition variable is now used to wait for an auto-executed AP to accept the requested flow.
Diffstat (limited to 'src/irmd')
-rw-r--r--src/irmd/main.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c
index ea52d67f..fc856687 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -81,6 +81,7 @@ struct reg_name_entry {
int flow_arrived;
pthread_cond_t acc_signal;
+ pthread_cond_t acc_arr_signal;
pthread_mutex_t acc_lock;
};
@@ -271,6 +272,11 @@ static struct reg_name_entry * reg_name_entry_create()
e->req_ae_name = NULL;
e->flow_arrived = -1;
+ if (pthread_cond_init(&e->acc_arr_signal, NULL)) {
+ free(e);
+ return NULL;
+ }
+
if (pthread_cond_init(&e->acc_signal, NULL)) {
free(e);
return NULL;
@@ -312,7 +318,7 @@ static int reg_name_entry_destroy(struct reg_name_entry * e)
pthread_mutex_lock(&e->acc_lock);
e->flow_arrived = -2;
pthread_mutex_unlock(&e->acc_lock);
- pthread_cond_broadcast(&e->acc_signal);
+ pthread_cond_broadcast(&e->acc_arr_signal);
sched_yield();
}
@@ -811,6 +817,8 @@ static struct port_map_entry * flow_accept(pid_t pid,
rne->accept = true;
rne->flow_arrived = -1;
+ pthread_cond_broadcast(&rne->acc_signal);
+
rw_lock_unlock(&instance->reg_lock);
rw_lock_unlock(&instance->state_lock);
@@ -819,7 +827,7 @@ static struct port_map_entry * flow_accept(pid_t pid,
(void*) &rne->acc_lock);
while (rne->flow_arrived == -1)
- pthread_cond_wait(&rne->acc_signal, &rne->acc_lock);
+ pthread_cond_wait(&rne->acc_arr_signal, &rne->acc_lock);
pthread_mutex_unlock(&rne->acc_lock);
pthread_cleanup_pop(0);
@@ -1151,7 +1159,8 @@ static struct port_map_entry * flow_req_arr(pid_t pid,
if (rne->autoexec) {
pme->n_pid = auto_execute(rne->api->name, rne->argv);
while (rne->accept == false)
- sched_yield();
+ pthread_cond_wait(&rne->acc_signal,
+ &rne->acc_lock);
}
else {
pthread_mutex_unlock(&rne->acc_lock);
@@ -1165,7 +1174,7 @@ static struct port_map_entry * flow_req_arr(pid_t pid,
pthread_mutex_unlock(&rne->acc_lock);
- if (pthread_cond_signal(&rne->acc_signal))
+ if (pthread_cond_signal(&rne->acc_arr_signal))
LOG_ERR("Failed to send signal.");
while (acc_wait) {