summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-08-09 16:06:12 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-08-09 16:06:12 +0200
commit9dce327e10bffddc9dc5058f06407e8ff12389b7 (patch)
tree97c4672e8e912efbbaf1a4e1cf3077a0cfe402b4
parent067c5661859f6a1f75adb0bb325d1641fed221a1 (diff)
downloadouroboros-9dce327e10bffddc9dc5058f06407e8ff12389b7.tar.gz
ouroboros-9dce327e10bffddc9dc5058f06407e8ff12389b7.zip
lib: Various fixes
Fix missing set of api upon flow_alloc. Various locking fixes.
-rw-r--r--include/ouroboros/shm_ap_rbuff.h1
-rw-r--r--src/irmd/main.c16
-rw-r--r--src/irmd/reg_api.c5
-rw-r--r--src/irmd/registry.c4
-rw-r--r--src/lib/dev.c4
-rw-r--r--src/lib/shm_ap_rbuff.c13
-rw-r--r--src/lib/shm_du_map.c10
7 files changed, 26 insertions, 27 deletions
diff --git a/include/ouroboros/shm_ap_rbuff.h b/include/ouroboros/shm_ap_rbuff.h
index 50b077f0..a1949122 100644
--- a/include/ouroboros/shm_ap_rbuff.h
+++ b/include/ouroboros/shm_ap_rbuff.h
@@ -49,6 +49,5 @@ ssize_t shm_ap_rbuff_read_port(struct shm_ap_rbuff * rb,
ssize_t shm_ap_rbuff_read_port_b(struct shm_ap_rbuff * rb,
int port_id,
const struct timespec * timeout);
-pid_t shm_ap_rbuff_get_api(struct shm_ap_rbuff * rb);
void shm_ap_rbuff_reset(struct shm_ap_rbuff * rb);
#endif /* OUROBOROS_SHM_AP_RBUFF_H */
diff --git a/src/irmd/main.c b/src/irmd/main.c
index a79330ef..c7c1566d 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -524,6 +524,9 @@ static ssize_t list_ipcps(char * name,
ssize_t count = 0;
int i = 0;
+ pthread_rwlock_rdlock(&irmd->state_lock);
+ pthread_rwlock_rdlock(&irmd->reg_lock);
+
list_for_each(pos, &irmd->ipcps) {
struct ipcp_entry * tmp =
list_entry(pos, struct ipcp_entry, next);
@@ -535,6 +538,8 @@ static ssize_t list_ipcps(char * name,
*apis = malloc(count * sizeof(pid_t));
if (*apis == NULL) {
+ pthread_rwlock_unlock(&irmd->reg_lock);
+ pthread_rwlock_unlock(&irmd->state_lock);
return -1;
}
@@ -547,6 +552,9 @@ static ssize_t list_ipcps(char * name,
}
}
+ pthread_rwlock_unlock(&irmd->reg_lock);
+ pthread_rwlock_unlock(&irmd->state_lock);
+
return count;
}
@@ -884,6 +892,7 @@ static void cleanup_alloc_res(void * o)
struct irm_flow * f = (struct irm_flow *) o;
if (f->state == FLOW_PENDING)
f->state = FLOW_NULL;
+ pthread_cond_broadcast(&f->state_cond);
pthread_mutex_unlock(&f->state_lock);
}
@@ -936,6 +945,7 @@ static int flow_alloc_res(int port_id)
pthread_mutex_lock(&f->state_lock);
if (f->state == FLOW_ALLOCATED) {
+ pthread_cond_broadcast(&f->state_cond);
pthread_mutex_unlock(&f->state_lock);
pthread_rwlock_unlock(&irmd->flows_lock);
pthread_rwlock_unlock(&irmd->state_lock);
@@ -943,7 +953,7 @@ static int flow_alloc_res(int port_id)
}
f->state = FLOW_NULL;
- pthread_cond_signal(&f->state_cond);
+ pthread_cond_broadcast(&f->state_cond);
pthread_mutex_unlock(&f->state_lock);
pthread_rwlock_unlock(&irmd->flows_lock);
pthread_rwlock_unlock(&irmd->state_lock);
@@ -1040,7 +1050,7 @@ static struct irm_flow * flow_req_arr(pid_t api,
LOG_WARN("Failed to set timestamp.");
pthread_rwlock_rdlock(&irmd->state_lock);
- pthread_rwlock_rdlock(&irmd->reg_lock);
+ pthread_rwlock_wrlock(&irmd->reg_lock);
rne = registry_get_entry_by_name(&irmd->registry, dst_name);
if (rne == NULL) {
@@ -1172,7 +1182,7 @@ static int flow_alloc_reply(int port_id,
struct irm_flow * f;
pthread_rwlock_rdlock(&irmd->state_lock);
- pthread_rwlock_rdlock(&irmd->flows_lock);
+ pthread_rwlock_wrlock(&irmd->flows_lock);
f = get_irm_flow(port_id);
if (f == NULL) {
diff --git a/src/irmd/reg_api.c b/src/irmd/reg_api.c
index d50f89e8..648dc1b3 100644
--- a/src/irmd/reg_api.c
+++ b/src/irmd/reg_api.c
@@ -111,8 +111,11 @@ void reg_api_wake(struct reg_api * i)
pthread_cond_broadcast(&i->state_cond);
+ pthread_cleanup_push((void(*)(void *)) pthread_mutex_unlock,
+ (void *) &i->state_lock);
+
while (i->state == REG_I_WAKE)
pthread_cond_wait(&i->state_cond, &i->state_lock);
- pthread_mutex_unlock(&i->state_lock);
+ pthread_cleanup_pop(true);
}
diff --git a/src/irmd/registry.c b/src/irmd/registry.c
index ec1c3987..ae8c3b0a 100644
--- a/src/irmd/registry.c
+++ b/src/irmd/registry.c
@@ -503,6 +503,8 @@ struct reg_api * registry_add_api_name(struct list_head * registry,
return NULL;
}
+ pthread_mutex_lock(&e->state_lock);
+
if (e->state == REG_NAME_IDLE || e->state == REG_NAME_AUTO_ACCEPT
|| e->state == REG_NAME_AUTO_EXEC) {
e->state = REG_NAME_FLOW_ACCEPT;
@@ -511,6 +513,8 @@ struct reg_api * registry_add_api_name(struct list_head * registry,
list_add(&i->next, &e->reg_apis);
+ pthread_mutex_unlock(&e->state_lock);
+
return i;
}
diff --git a/src/lib/dev.c b/src/lib/dev.c
index 6f0de8c8..3c31ce6d 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -203,6 +203,7 @@ int flow_accept(char ** ae_name)
_ap_instance->flows[cfd].port_id = recv_msg->port_id;
_ap_instance->flows[cfd].oflags = FLOW_O_DEFAULT;
+ _ap_instance->flows[cfd].api = recv_msg->api;
pthread_rwlock_unlock(&_ap_instance->flows_lock);
pthread_rwlock_unlock(&_ap_instance->data_lock);
@@ -321,8 +322,7 @@ int flow_alloc(char * dst_name,
_ap_instance->flows[fd].port_id = recv_msg->port_id;
_ap_instance->flows[fd].oflags = FLOW_O_DEFAULT;
- _ap_instance->flows[fd].api =
- shm_ap_rbuff_get_api(_ap_instance->flows[fd].rb);
+ _ap_instance->flows[fd].api = recv_msg->api;
pthread_rwlock_unlock(&_ap_instance->flows_lock);
pthread_rwlock_unlock(&_ap_instance->data_lock);
diff --git a/src/lib/shm_ap_rbuff.c b/src/lib/shm_ap_rbuff.c
index 62ef5cf1..1c7fd600 100644
--- a/src/lib/shm_ap_rbuff.c
+++ b/src/lib/shm_ap_rbuff.c
@@ -462,19 +462,6 @@ ssize_t shm_ap_rbuff_read_port_b(struct shm_ap_rbuff * rb,
return idx;
}
-pid_t shm_ap_rbuff_get_api(struct shm_ap_rbuff *rb)
-{
- pid_t api = -1;
- if (rb == NULL)
- return -1;
-
- pthread_mutex_lock(rb->lock);
- api = rb->api;
- pthread_mutex_unlock(rb->lock);
-
- return api;
-}
-
void shm_ap_rbuff_reset(struct shm_ap_rbuff * rb)
{
if (rb == NULL)
diff --git a/src/lib/shm_du_map.c b/src/lib/shm_du_map.c
index 3e2c99d4..9ca282b9 100644
--- a/src/lib/shm_du_map.c
+++ b/src/lib/shm_du_map.c
@@ -91,14 +91,11 @@ static void garbage_collect(struct shm_du_map * dum)
{
#ifdef SHM_DU_MAP_MULTI_BLOCK
struct shm_du_buff * sdb;
- while (!shm_map_empty(dum) &&
- (sdb = get_tail_ptr(dum))->dst_api == -1)
-
+ while (!shm_map_empty(dum) && (sdb = get_tail_ptr(dum))->dst_api == -1)
*dum->ptr_tail = (*dum->ptr_tail + sdb->blocks)
& (SHM_BUFFER_SIZE - 1);
#else
- while (!shm_map_empty(dum) &&
- get_tail_ptr(dum)->dst_api == -1)
+ while (!shm_map_empty(dum) && get_tail_ptr(dum)->dst_api == -1)
*dum->ptr_tail =
(*dum->ptr_tail + 1) & (SHM_BUFFER_SIZE - 1);
@@ -296,8 +293,7 @@ void * shm_du_map_sanitize(void * o)
struct timespec now;
struct timespec dl;
- if (pthread_cond_wait(dum->full, dum->lock)
- == EOWNERDEAD) {
+ if (pthread_cond_wait(dum->full, dum->lock) == EOWNERDEAD) {
LOG_WARN("Recovering dead mutex.");
pthread_mutex_consistent(dum->lock);
}