From b7af3a8c36426811762bf331e3938f9d67b7429e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 2 Aug 2019 16:58:34 +0200 Subject: [SERVER] Make image->users atomic and get rid of some locking With this change it should be safe to read the users count of an image without locking first, assuming you already have a reference on the image or are otherwise sure it cannot be freed, i.e. in an active uplink. Updating users, or checking whether it's 0 in order to free the image should only be done while holding the imageListLock. --- src/server/globals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/server/globals.h') diff --git a/src/server/globals.h b/src/server/globals.h index b248800..73eb563 100644 --- a/src/server/globals.h +++ b/src/server/globals.h @@ -117,7 +117,7 @@ struct _dnbd3_image uint32_t masterCrc32; // CRC-32 of the crc-32 list int readFd; // used to read the image. Used from multiple threads, so use atomic operations (pread et al) int completenessEstimate; // Completeness estimate in percent - int users; // clients currently using this image + atomic_int users; // clients currently using this image. XXX Lock on imageListLock when modifying and checking whether the image should be freed. Reading it elsewhere is fine without the lock. int id; // Unique ID of this image. Only unique in the context of this running instance of DNBD3-Server bool working; // true if image exists and completeness is == 100% or a working upstream proxy is connected uint16_t rid; // revision of image -- cgit v1.2.3-55-g7522