summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2017-03-21 16:14:18 +0100
committerdimitri staessens <[email protected]>2017-03-21 16:14:18 +0100
commit19a3277dbff7fc79c12be8a200ab6c8dfe6b50b9 (patch)
tree835d86fa8c9695e95ef213dc5644d1a7f1fdc395 /src
parent15b492ffb0de010b94bfb4e80c721e04ef6f63c2 (diff)
downloadouroboros-19a3277dbff7fc79c12be8a200ab6c8dfe6b50b9.tar.gz
ouroboros-19a3277dbff7fc79c12be8a200ab6c8dfe6b50b9.zip
irmd: Fix timeouts in reg_entry
This fixes bad timedwaits for the state of the reg_entry. Also slightly revised timedwaits throughout the prototype.
Diffstat (limited to 'src')
-rw-r--r--src/ipcpd/shim-data.c10
-rw-r--r--src/irmd/api_table.c23
-rw-r--r--src/irmd/main.c2
-rw-r--r--src/irmd/registry.c6
-rw-r--r--src/lib/shm_flow_set.c2
5 files changed, 29 insertions, 14 deletions
diff --git a/src/ipcpd/shim-data.c b/src/ipcpd/shim-data.c
index 933f3a64..bec2486c 100644
--- a/src/ipcpd/shim-data.c
+++ b/src/ipcpd/shim-data.c
@@ -492,12 +492,10 @@ int shim_data_dir_query_wait(struct dir_query * query,
query->state = QUERY_PENDING;
- while (query->state == QUERY_PENDING) {
- if ((ret = -pthread_cond_timedwait(&query->cond,
- &query->lock,
- &abstime)) == -ETIMEDOUT)
- break;
- }
+ while (query->state == QUERY_PENDING && ret != -ETIMEDOUT)
+ ret = -pthread_cond_timedwait(&query->cond,
+ &query->lock,
+ &abstime);
if (query->state == QUERY_DESTROY)
ret = -1;
diff --git a/src/irmd/api_table.c b/src/irmd/api_table.c
index df300cea..83153aac 100644
--- a/src/irmd/api_table.c
+++ b/src/irmd/api_table.c
@@ -34,6 +34,7 @@
struct api_entry * api_entry_create(pid_t api, char * apn)
{
struct api_entry * e;
+ pthread_condattr_t cattr;
if (apn == NULL)
return NULL;
@@ -53,8 +54,26 @@ struct api_entry * api_entry_create(pid_t api, char * apn)
e->state = API_INIT;
- pthread_mutex_init(&e->state_lock, NULL);
- pthread_cond_init(&e->state_cond, NULL);
+ if (pthread_condattr_init(&cattr)) {
+ free(e);
+ return NULL;
+ }
+
+#ifndef __APPLE__
+ pthread_condattr_setclock(&cattr, PTHREAD_COND_CLOCK);
+#endif
+
+ if (pthread_mutex_init(&e->state_lock, NULL)) {
+ free(e);
+ return NULL;
+ }
+
+
+ if (pthread_cond_init(&e->state_cond, &cattr)) {
+ pthread_mutex_destroy(&e->state_lock);
+ free(e);
+ return NULL;
+ }
return e;
}
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 658a08f6..cc13ccea 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -1360,7 +1360,7 @@ static struct irm_flow * flow_req_arr(pid_t api,
pid_t h_api = -1;
int port_id = -1;
- struct timespec wt = {IRMD_REQ_ARR_TIMEOUT % 1000,
+ struct timespec wt = {IRMD_REQ_ARR_TIMEOUT / 1000,
(IRMD_REQ_ARR_TIMEOUT % 1000) * MILLION};
log_dbg("Flow req arrived from IPCP %d for %s on AE %s.",
diff --git a/src/irmd/registry.c b/src/irmd/registry.c
index 985ecda0..9512d664 100644
--- a/src/irmd/registry.c
+++ b/src/irmd/registry.c
@@ -76,7 +76,7 @@ static struct reg_entry * reg_entry_init(struct reg_entry * e,
if (pthread_condattr_init(&cattr))
return NULL;
-#ifdef __APPLE__
+#ifndef __APPLE__
pthread_condattr_setclock(&cattr, PTHREAD_COND_CLOCK);
#endif
if (pthread_cond_init(&e->state_cond, &cattr))
@@ -429,7 +429,7 @@ int reg_entry_leave_state(struct reg_entry * e,
if (timeout)
ret = -pthread_cond_timedwait(&e->state_cond,
&e->state_lock,
- timeout);
+ &abstime);
else
ret = -pthread_cond_wait(&e->state_cond,
&e->state_lock);
@@ -468,7 +468,7 @@ int reg_entry_wait_state(struct reg_entry * e,
if (timeout)
ret = -pthread_cond_timedwait(&e->state_cond,
&e->state_lock,
- timeout);
+ &abstime);
else
ret = -pthread_cond_wait(&e->state_cond,
&e->state_lock);
diff --git a/src/lib/shm_flow_set.c b/src/lib/shm_flow_set.c
index 161e070c..f561c514 100644
--- a/src/lib/shm_flow_set.c
+++ b/src/lib/shm_flow_set.c
@@ -360,8 +360,6 @@ ssize_t shm_flow_set_wait(const struct shm_flow_set * set,
if (ret == -EOWNERDEAD)
pthread_mutex_consistent(set->lock);
#endif
- if (ret == -ETIMEDOUT)
- break;
}
if (ret != -ETIMEDOUT) {