diff options
author | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-12-28 10:57:04 +0100 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-12-28 10:57:04 +0100 |
commit | 43a3231b03aa0a639bcd8d61784c84095edfdb6e (patch) | |
tree | 3e722461be65504e6658f75b7b651f93bb8764e1 /src/irmd/registry.c | |
parent | bd99555a130400cfec1cbdcf5e4eaa08f133d041 (diff) | |
parent | f8e230049143412ac424d4cbfd4ca95b6c7f64e1 (diff) | |
download | ouroboros-43a3231b03aa0a639bcd8d61784c84095edfdb6e.tar.gz ouroboros-43a3231b03aa0a639bcd8d61784c84095edfdb6e.zip |
Merged in dstaesse/ouroboros/be-qoscube (pull request #329)
Some fixes
Diffstat (limited to 'src/irmd/registry.c')
-rw-r--r-- | src/irmd/registry.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/irmd/registry.c b/src/irmd/registry.c index 61d562fc..34d0a921 100644 --- a/src/irmd/registry.c +++ b/src/irmd/registry.c @@ -278,6 +278,9 @@ int reg_entry_add_api(struct reg_entry * e, pid_t api) return -ENOMEM; i->pid = api; + + pthread_mutex_lock(&e->state_lock); + list_add(&i->next, &e->reg_apis); if (e->state == REG_NAME_IDLE || @@ -287,6 +290,8 @@ int reg_entry_add_api(struct reg_entry * e, pid_t api) pthread_cond_signal(&e->state_cond); } + pthread_mutex_unlock(&e->state_lock); + return 0; } @@ -329,6 +334,52 @@ pid_t reg_entry_get_api(struct reg_entry * e) return list_first_entry(&e->reg_apis, struct pid_el, next)->pid; } +enum reg_name_state reg_entry_get_state(struct reg_entry * e) +{ + enum reg_name_state state; + + if (e == NULL) + return REG_NAME_NULL; + + pthread_mutex_lock(&e->state_lock); + + state = e->state; + + pthread_mutex_unlock(&e->state_lock); + + return state; +} + +int reg_entry_set_state(struct reg_entry * e, enum reg_name_state state) +{ + if (state == REG_NAME_DESTROY) + return -EPERM; + + pthread_mutex_lock(&e->state_lock); + + e->state = state; + pthread_cond_broadcast(&e->state_cond); + + pthread_mutex_unlock(&e->state_lock); + + return 0; +} + +int reg_entry_leave_state(struct reg_entry * e, enum reg_name_state state) +{ + if (e == NULL || state == REG_NAME_DESTROY) + return -EINVAL; + + pthread_mutex_lock(&e->state_lock); + + while (e->state == state) + pthread_cond_wait(&e->state_cond, &e->state_lock); + + pthread_mutex_unlock(&e->state_lock); + + return 0; +} + struct reg_entry * registry_get_entry(struct list_head * registry, char * name) { |