diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-12-28 09:51:08 +0100 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-12-28 09:51:08 +0100 |
commit | f8e230049143412ac424d4cbfd4ca95b6c7f64e1 (patch) | |
tree | 3e722461be65504e6658f75b7b651f93bb8764e1 /src/irmd/registry.c | |
parent | 502e7bb39096f6ce7718c29d9616bbd0314d045e (diff) | |
download | ouroboros-f8e230049143412ac424d4cbfd4ca95b6c7f64e1.tar.gz ouroboros-f8e230049143412ac424d4cbfd4ca95b6c7f64e1.zip |
irmd: Hide reg_entry internal lock
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) { |