From 0228f3c86fefa582ec77b6aa97e89363b0f9b329 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 17 Sep 2013 15:44:50 +0200 Subject: [SERVER] Properly decrease uplink.queueLen when removing a client --- src/server/uplink.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/server/uplink.c') diff --git a/src/server/uplink.c b/src/server/uplink.c index 61b353f..67936d5 100644 --- a/src/server/uplink.c +++ b/src/server/uplink.c @@ -103,13 +103,11 @@ void uplink_shutdown(dnbd3_image_t *image) void uplink_removeClient(dnbd3_connection_t *uplink, dnbd3_client_t *client) { spin_lock( &uplink->queueLock ); - for (int i = 0; i < uplink->queueLen; ++i) { + for (int i = uplink->queueLen - 1; i >= 0; --i) { if ( uplink->queue[i].client == client ) { - // Lock on the send mutex as the uplink thread might just be writing to the client - pthread_mutex_lock( &client->sendMutex ); uplink->queue[i].client = NULL; uplink->queue[i].status = ULR_FREE; - pthread_mutex_unlock( &client->sendMutex ); + if ( i > 20 && uplink->queueLen == i + 1 ) uplink->queueLen--; } } spin_unlock( &uplink->queueLock ); -- cgit v1.2.3-55-g7522