From 2860f3393025e114f11feb1b576d2ac6353fbd23 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 8 Aug 2018 12:09:14 +0200 Subject: [SERVER] Use atomic var for (total)bytesSent counters Gets rid of the lastBytesSent field as well as the stats lock per client. Cleaned and split up the messy net_clientsToJson function while at it. --- src/server/globals.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/server/globals.h') diff --git a/src/server/globals.h b/src/server/globals.h index c384ac6..84588c3 100644 --- a/src/server/globals.h +++ b/src/server/globals.h @@ -127,16 +127,14 @@ struct _dnbd3_image struct _dnbd3_client { #define HOSTNAMELEN (48) - uint64_t bytesSent; // Byte counter for this client. Use statsLock when accessing. - uint64_t lastBytesSent; // Byte counter from when we last added to global counter. Use statsLock when accessing. - dnbd3_image_t *image; + atomic_uint_fast64_t bytesSent; // Byte counter for this client. + dnbd3_image_t *image; // Image in use by this client, or NULL during handshake int sock; - bool isServer; // true if a server in proxy mode, false if real client + bool isServer; // true if a server in proxy mode, false if real client dnbd3_host_t host; - char hostName[HOSTNAMELEN]; - pthread_mutex_t sendMutex; + char hostName[HOSTNAMELEN]; // inet_ntop version of host + pthread_mutex_t sendMutex; // Held while writing to sock if image is incomplete (since uplink uses socket too) pthread_spinlock_t lock; - pthread_spinlock_t statsLock; }; // ####################################################### -- cgit v1.2.3-55-g7522