From 393a6be5c401e8e788d51f4c6e25f9937428360e Mon Sep 17 00:00:00 2001 From: sudden6 Date: Sat, 7 Sep 2019 01:57:51 +0200 Subject: don't wait for connection when killing Tox When tox_kill is called no other thread should be running anymore so this locking is not needed there. --- toxcore/net_crypto.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'toxcore') diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index da525a1f..01dd680e 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -1486,7 +1486,18 @@ static void connection_kill(Net_Crypto *c, int crypt_connection_id, void *userda userdata); } + while (1) { /* TODO(irungentoo): is this really the best way to do this? */ + pthread_mutex_lock(&c->connections_mutex); + + if (!c->connection_use_counter) { + break; + } + + pthread_mutex_unlock(&c->connections_mutex); + } + crypto_kill(c, crypt_connection_id); + pthread_mutex_unlock(&c->connections_mutex); } /* Handle a received data packet. @@ -2889,16 +2900,6 @@ int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t */ int crypto_kill(Net_Crypto *c, int crypt_connection_id) { - while (1) { /* TODO(irungentoo): is this really the best way to do this? */ - pthread_mutex_lock(&c->connections_mutex); - - if (!c->connection_use_counter) { - break; - } - - pthread_mutex_unlock(&c->connections_mutex); - } - Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); int ret = -1; @@ -2920,8 +2921,6 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id) ret = wipe_crypto_connection(c, crypt_connection_id); } - pthread_mutex_unlock(&c->connections_mutex); - return ret; } -- cgit v1.2.3