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/shim-eth-llc | |
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/shim-eth-llc')
-rw-r--r-- | src/ipcpd/shim-eth-llc/main.c | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c index 145085e7..e4d7429a 100644 --- a/src/ipcpd/shim-eth-llc/main.c +++ b/src/ipcpd/shim-eth-llc/main.c @@ -197,7 +197,7 @@ void eth_llc_ipcp_data_destroy() if (_ipcp == NULL) return; - pthread_rwlock_wrlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); if (_ipcp->state != IPCP_SHUTDOWN) LOG_WARN("Cleaning up while not in shutdown."); @@ -218,7 +218,7 @@ void eth_llc_ipcp_data_destroy() shm_ap_rbuff_close(ipcp_flow(i)->rb); pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); ipcp_data_destroy(_ipcp->data); } @@ -478,12 +478,12 @@ static int eth_llc_ipcp_port_req(uint8_t r_sap, ssize_t index = 0; int i; - pthread_rwlock_wrlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); pthread_rwlock_wrlock(&shim_data(_ipcp)->flows_lock); index = bmp_allocate(shim_data(_ipcp)->indices); if (index < 0) { - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); LOG_ERR("Out of free indices."); return -1; @@ -496,7 +496,7 @@ static int eth_llc_ipcp_port_req(uint8_t r_sap, if (port_id < 0) { bmp_release(shim_data(_ipcp)->indices, index); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); LOG_ERR("Could not get port id from IRMd."); return -1; @@ -511,7 +511,7 @@ static int eth_llc_ipcp_port_req(uint8_t r_sap, } pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); LOG_DBG("New flow request, port_id %d, remote SAP %d.", port_id, r_sap); @@ -528,20 +528,20 @@ static int eth_llc_ipcp_port_alloc_reply(uint8_t ssap, int port_id = -1; int i; - pthread_rwlock_rdlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); pthread_rwlock_rdlock(&shim_data(_ipcp)->flows_lock); index = sap_to_index(ssap); if (index < 0) { pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); LOG_ERR("No flow found with that SAP."); return -1; /* -EFLOWNOTFOUND */ } if (ipcp_flow(index)->state != FLOW_PENDING) { pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); return -1; /* -EFLOWNOTPENDING */ } @@ -558,7 +558,7 @@ static int eth_llc_ipcp_port_alloc_reply(uint8_t ssap, } pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); LOG_DBG("Flow reply, port_id %d, remote SAP %d.", port_id, dsap); @@ -578,13 +578,13 @@ static int eth_llc_ipcp_flow_dealloc_req(uint8_t ssap, int port_id = -1; int i = 0; - pthread_rwlock_rdlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); pthread_rwlock_wrlock(&shim_data(_ipcp)->flows_lock); i = sap_to_index(ssap); if (i < 0) { pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); LOG_ERR("No flow found for remote deallocation request."); return 0; } @@ -593,7 +593,7 @@ static int eth_llc_ipcp_flow_dealloc_req(uint8_t ssap, destroy_ipcp_flow(i); pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); ipcp_flow_dealloc(0, port_id); @@ -669,14 +669,14 @@ static void * eth_llc_ipcp_sdu_reader(void * o) memset(br_addr, 0xff, MAC_SIZE * sizeof(uint8_t)); while (true) { - pthread_rwlock_rdlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); if (_ipcp->state != IPCP_ENROLLED) { - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); return (void *) 1; /* -ENOTENROLLED */ } - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); #if defined(PACKET_RX_RING) && defined(PACKET_TX_RING) header = (void *) shim_data(_ipcp)->rx_ring + @@ -789,13 +789,13 @@ static void * eth_llc_ipcp_sdu_writer(void * o) if (e == NULL) continue; - pthread_rwlock_rdlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); if (_ipcp->state != IPCP_ENROLLED) { - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); return (void *) 1; /* -ENOTENROLLED */ } - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); len = shm_du_map_read((uint8_t **) &buf, shim_data(_ipcp)->dum, @@ -847,14 +847,14 @@ void ipcp_sig_handler(int sig, siginfo_t * info, void * c) LOG_DBG("Terminating by order of %d. Bye.", info->si_pid); - pthread_rwlock_wrlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); if (_ipcp->state == IPCP_ENROLLED) clean_threads = true; _ipcp->state = IPCP_SHUTDOWN; - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); if (clean_threads) { pthread_cancel(shim_data(_ipcp)->sdu_reader); @@ -1030,10 +1030,10 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf) #endif - pthread_rwlock_wrlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); if (_ipcp->state != IPCP_INIT) { - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); LOG_ERR("IPCP in wrong state."); close(fd); return -1; @@ -1055,7 +1055,7 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf) eth_llc_ipcp_sdu_writer, NULL); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); LOG_DBG("Bootstrapped shim IPCP over Ethernet with LLC with api %d.", getpid()); @@ -1065,21 +1065,21 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf) static int eth_llc_ipcp_name_reg(char * name) { - pthread_rwlock_rdlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); if (_ipcp->state != IPCP_ENROLLED) { - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); LOG_DBGF("Won't register with non-enrolled IPCP."); return -1; /* -ENOTENROLLED */ } if (ipcp_data_add_reg_entry(_ipcp->data, name)) { - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); LOG_ERR("Failed to add %s to local registry.", name); return -1; } - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); LOG_DBG("Registered %s.", name); @@ -1088,11 +1088,11 @@ static int eth_llc_ipcp_name_reg(char * name) static int eth_llc_ipcp_name_unreg(char * name) { - pthread_rwlock_rdlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); ipcp_data_del_reg_entry(_ipcp->data, name); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); return 0; } @@ -1120,11 +1120,11 @@ static int eth_llc_ipcp_flow_alloc(pid_t n_api, if (rb == NULL) return -1; /* -ENORBUFF */ - pthread_rwlock_wrlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); if (_ipcp->state != IPCP_ENROLLED) { shm_ap_rbuff_close(rb); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); LOG_DBGF("Won't allocate flow with non-enrolled IPCP."); return -1; /* -ENOTENROLLED */ } @@ -1132,7 +1132,7 @@ static int eth_llc_ipcp_flow_alloc(pid_t n_api, index = bmp_allocate(shim_data(_ipcp)->indices); if (index < 0) { shm_ap_rbuff_close(rb); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); return -1; } @@ -1143,7 +1143,7 @@ static int eth_llc_ipcp_flow_alloc(pid_t n_api, shm_ap_rbuff_close(rb); bmp_release(shim_data(_ipcp)->indices, index); pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); return -1; } @@ -1153,7 +1153,7 @@ static int eth_llc_ipcp_flow_alloc(pid_t n_api, shim_data(_ipcp)->flows[index].sap = ssap; pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); memset(r_addr, 0xff, MAC_SIZE * sizeof(uint8_t)); @@ -1161,11 +1161,11 @@ static int eth_llc_ipcp_flow_alloc(pid_t n_api, dst_name, src_ae_name) < 0) { LOG_DBGF("Port alloc returned -1."); - pthread_rwlock_wrlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); pthread_rwlock_wrlock(&shim_data(_ipcp)->flows_lock); destroy_ipcp_flow(index); pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); return -1; } @@ -1183,20 +1183,20 @@ static int eth_llc_ipcp_flow_alloc_resp(pid_t n_api, int index = -1; uint8_t ssap = 0; - pthread_rwlock_wrlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); pthread_rwlock_wrlock(&shim_data(_ipcp)->flows_lock); index = port_id_to_index(port_id); if (index < 0) { pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); LOG_DBGF("Could not find flow with port_id %d.", port_id); return -1; } if (ipcp_flow(index)->state != FLOW_PENDING) { pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); LOG_DBGF("Flow was not pending."); return -1; } @@ -1208,7 +1208,7 @@ static int eth_llc_ipcp_flow_alloc_resp(pid_t n_api, ipcp_flow(index)->port_id = -1; bmp_release(shim_data(_ipcp)->indices, index); pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); return -1; } @@ -1219,7 +1219,7 @@ static int eth_llc_ipcp_flow_alloc_resp(pid_t n_api, shm_ap_rbuff_close(ipcp_flow(index)->rb); bmp_release(shim_data(_ipcp)->indices, index); pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); return -1; } @@ -1228,17 +1228,17 @@ static int eth_llc_ipcp_flow_alloc_resp(pid_t n_api, shim_data(_ipcp)->flows[index].sap = ssap; pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); if (eth_llc_ipcp_port_alloc_resp(shim_data(_ipcp)->flows[index].r_addr, shim_data(_ipcp)->flows[index].r_sap, ssap, response) < 0) { - pthread_rwlock_rdlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); pthread_rwlock_wrlock(&shim_data(_ipcp)->flows_lock); destroy_ipcp_flow(index); pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); LOG_DBGF("Could not send response."); return -1; @@ -1257,13 +1257,13 @@ static int eth_llc_ipcp_flow_dealloc(int port_id) int i; int ret; - pthread_rwlock_rdlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); pthread_rwlock_wrlock(&shim_data(_ipcp)->flows_lock); index = port_id_to_index(port_id); if (index < 0) { pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); return 0; } @@ -1277,7 +1277,7 @@ static int eth_llc_ipcp_flow_dealloc(int port_id) pthread_rwlock_unlock(&shim_data(_ipcp)->flows_lock); ret = eth_llc_ipcp_port_dealloc(addr, sap); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); if (ret < 0) LOG_DBGF("Could not notify remote."); @@ -1353,7 +1353,7 @@ int main(int argc, char * argv[]) _ipcp->ops = ð_llc_ops; _ipcp->state = IPCP_INIT; - pthread_rwlock_wrlock(&_ipcp->state_lock); + pthread_mutex_lock(&_ipcp->state_lock); pthread_sigmask(SIG_BLOCK, &sigset, NULL); @@ -1362,7 +1362,7 @@ int main(int argc, char * argv[]) pthread_sigmask(SIG_UNBLOCK, &sigset, NULL); - pthread_rwlock_unlock(&_ipcp->state_lock); + pthread_mutex_unlock(&_ipcp->state_lock); if (ipcp_create_r(getpid())) { LOG_ERR("Failed to notify IRMd we are initialized."); |