summaryrefslogtreecommitdiffstats
path: root/src/server/globals.h
diff options
context:
space:
mode:
authorSimon Rettberg2019-08-02 16:58:34 +0200
committerSimon Rettberg2019-08-02 16:58:34 +0200
commitb7af3a8c36426811762bf331e3938f9d67b7429e (patch)
tree09ea38075824d6c0ee94e0105ee3eff191cf6691 /src/server/globals.h
parenti[SERVER] Include new pretendClient in config dump (diff)
downloaddnbd3-b7af3a8c36426811762bf331e3938f9d67b7429e.tar.gz
dnbd3-b7af3a8c36426811762bf331e3938f9d67b7429e.tar.xz
dnbd3-b7af3a8c36426811762bf331e3938f9d67b7429e.zip
[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.
Diffstat (limited to 'src/server/globals.h')
-rw-r--r--src/server/globals.h2
1 files changed, 1 insertions, 1 deletions
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