diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-08-12 11:55:52 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-08-12 11:55:52 +0200 |
commit | 44cc6aaa41d88dc978a087178fd74a1c2dba70fd (patch) | |
tree | 10b398bf23356751a961c332a9dff053c6927f24 /src/ipcpd/normal/ribmgr.c | |
parent | cf30e07cf862b117013e8c7fa2fb5c2ac8fef245 (diff) | |
parent | 5432e665fd6eac776c5985d98058e5c4645ec0e4 (diff) | |
download | ouroboros-44cc6aaa41d88dc978a087178fd74a1c2dba70fd.tar.gz ouroboros-44cc6aaa41d88dc978a087178fd74a1c2dba70fd.zip |
Merged in sandervrijders/ouroboros/be-state-mutex (pull request #209)
ipcpd: Add condition variable to IPCP state
Diffstat (limited to 'src/ipcpd/normal/ribmgr.c')
-rw-r--r-- | src/ipcpd/normal/ribmgr.c | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/ipcpd/normal/ribmgr.c b/src/ipcpd/normal/ribmgr.c index 2a68877a..bbc29b64 100644 --- a/src/ipcpd/normal/ribmgr.c +++ b/src/ipcpd/normal/ribmgr.c @@ -220,15 +220,15 @@ int ribmgr_cdap_write(struct cdap * instance, static_info_msg_t * msg; int ret = 0; - pthread_rwlock_wrlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); if (_ipcp->state == IPCP_PENDING_ENROLL && strcmp(name, STATIC_INFO) == 0) { LOG_DBG("Received static DIF information."); msg = static_info_msg__unpack(NULL, len, data); if (msg == NULL) { - _ipcp->state = IPCP_INIT; - pthread_rwlock_unlock(&_ipcp->state_lock); + ipcp_state_change(_ipcp, IPCP_INIT); + pthread_mutex_unlock(&_ipcp->state_lock); cdap_send_reply(instance, invoke_id, -1, NULL, 0); LOG_ERR("Failed to unpack static info message."); return -1; @@ -246,8 +246,8 @@ int ribmgr_cdap_write(struct cdap * instance, rib->address = msg->address; if (frct_init(&rib->dtc, rib->address)) { - _ipcp->state = IPCP_INIT; - pthread_rwlock_unlock(&_ipcp->state_lock); + ipcp_state_change(_ipcp, IPCP_INIT); + pthread_mutex_unlock(&_ipcp->state_lock); cdap_send_reply(instance, invoke_id, -1, NULL, 0); static_info_msg__free_unpacked(msg, NULL); LOG_ERR("Failed to init FRCT"); @@ -257,7 +257,7 @@ int ribmgr_cdap_write(struct cdap * instance, static_info_msg__free_unpacked(msg, NULL); } else ret = -1; - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); if (cdap_send_reply(instance, invoke_id, ret, NULL, 0)) { LOG_ERR("Failed to send reply to write request."); @@ -298,13 +298,13 @@ int ribmgr_cdap_start(struct cdap * instance, size_t len = 0; int iid = 0; - pthread_rwlock_rdlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); if (_ipcp->state == IPCP_ENROLLED && strcmp(name, ENROLLMENT) == 0) { LOG_DBG("New enrollment request."); if (cdap_send_reply(instance, invoke_id, 0, NULL, 0)) { - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); LOG_ERR("Failed to send reply to enrollment request."); return -1; } @@ -323,14 +323,14 @@ int ribmgr_cdap_start(struct cdap * instance, len = static_info_msg__get_packed_size(&stat_info); if (len == 0) { - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); LOG_ERR("Failed to get size of static information."); return -1; } data = malloc(len); if (data == NULL) { - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); LOG_ERR("Failed to allocate memory."); return -1; } @@ -344,7 +344,7 @@ int ribmgr_cdap_start(struct cdap * instance, iid = cdap_send_write(instance, STATIC_INFO, data, len, 0); if (iid < 0) { pthread_mutex_unlock(&rib->cdap_reqs_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); free(data); LOG_ERR("Failed to send static information."); return -1; @@ -352,7 +352,7 @@ int ribmgr_cdap_start(struct cdap * instance, if (cdap_request_add(instance, WRITE, STATIC_INFO, iid)) { pthread_mutex_unlock(&rib->cdap_reqs_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); free(data); LOG_ERR("Failed to add CDAP request to list."); return -1; @@ -368,7 +368,7 @@ int ribmgr_cdap_start(struct cdap * instance, iid = cdap_send_stop(instance, ENROLLMENT); if (iid < 0) { pthread_mutex_unlock(&rib->cdap_reqs_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); free(data); LOG_ERR("Failed to send stop of enrollment."); return -1; @@ -376,7 +376,7 @@ int ribmgr_cdap_start(struct cdap * instance, if (cdap_request_add(instance, STOP, ENROLLMENT, iid)) { pthread_mutex_unlock(&rib->cdap_reqs_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); free(data); LOG_ERR("Failed to add CDAP request to list."); return -1; @@ -386,12 +386,12 @@ int ribmgr_cdap_start(struct cdap * instance, free(data); } else { if (cdap_send_reply(instance, invoke_id, -1, NULL, 0)) { - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); LOG_ERR("Failed to send reply to start request."); return -1; } } - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); return 0; } @@ -402,21 +402,21 @@ int ribmgr_cdap_stop(struct cdap * instance, { int ret = 0; - pthread_rwlock_wrlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); if (_ipcp->state == IPCP_PENDING_ENROLL && strcmp(name, ENROLLMENT) == 0) { LOG_DBG("Stop enrollment received."); - _ipcp->state = IPCP_ENROLLED; + ipcp_state_change(_ipcp, IPCP_ENROLLED); } else ret = -1; if (cdap_send_reply(instance, invoke_id, ret, NULL, 0)) { - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); LOG_ERR("Failed to send reply to stop request."); return -1; } - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); return 0; } @@ -452,11 +452,11 @@ int ribmgr_add_flow(int fd) flow->instance = instance; flow->fd = fd; - pthread_rwlock_wrlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); pthread_rwlock_wrlock(&rib->flows_lock); if (list_empty(&rib->flows) && _ipcp->state == IPCP_INIT) { - _ipcp->state = IPCP_PENDING_ENROLL; + ipcp_state_change(_ipcp, IPCP_PENDING_ENROLL); pthread_mutex_lock(&rib->cdap_reqs_lock); iid = cdap_send_start(instance, @@ -480,7 +480,7 @@ int ribmgr_add_flow(int fd) } pthread_mutex_unlock(&rib->cdap_reqs_lock); } - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); list_add(&flow->next, &rib->flows); pthread_rwlock_unlock(&rib->flows_lock); |