summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2019-08-07 14:39:44 +0200
committerSimon Rettberg2019-08-07 14:39:44 +0200
commit4e2e258dba3c9268e8d4fd061cbb9f291017ed2f (patch)
tree4f5e07a350a47802ef012bd0ef6af32a7e700c96 /src
parent[SERVER] Fix race condition and invalid lock order (diff)
downloaddnbd3-4e2e258dba3c9268e8d4fd061cbb9f291017ed2f.tar.gz
dnbd3-4e2e258dba3c9268e8d4fd061cbb9f291017ed2f.tar.xz
dnbd3-4e2e258dba3c9268e8d4fd061cbb9f291017ed2f.zip
[SERVER] Use more _Atomic
Diffstat (limited to 'src')
-rw-r--r--src/server/globals.h6
-rw-r--r--src/server/net.c3
2 files changed, 4 insertions, 5 deletions
diff --git a/src/server/globals.h b/src/server/globals.h
index cd5ad7e..86b8865 100644
--- a/src/server/globals.h
+++ b/src/server/globals.h
@@ -60,7 +60,7 @@ struct _dnbd3_connection
// If BGR == BGR_HASHBLOCK, -1 means "currently no incomplete block"
uint64_t replicationHandle; // Handle of pending replication request
atomic_uint_fast64_t bytesReceived; // Number of bytes received by the uplink since startup.
- int queueLen; // length of queue
+ atomic_int queueLen; // length of queue
uint32_t idleTime; // How many seconds the uplink was idle (apart from keep-alives)
dnbd3_queued_request_t queue[SERVER_MAX_UPLINK_QUEUE];
};
@@ -107,7 +107,7 @@ struct _dnbd3_image
int completenessEstimate; // Completeness estimate in percent
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
+ atomic_bool working; // true if image exists and completeness is == 100% or a working upstream proxy is connected
uint16_t rid; // revision of image
pthread_mutex_t lock;
};
@@ -116,7 +116,7 @@ struct _dnbd3_client
{
#define HOSTNAMELEN (48)
atomic_uint_fast64_t bytesSent; // Byte counter for this client.
- dnbd3_image_t *image; // Image in use by this client, or NULL during handshake
+ dnbd3_image_t * _Atomic 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
dnbd3_host_t host;
diff --git a/src/server/net.c b/src/server/net.c
index c1fa6fa..92728c0 100644
--- a/src/server/net.c
+++ b/src/server/net.c
@@ -255,9 +255,8 @@ void* net_handleNewConnection(void *clientPtr)
// No BGR mismatch, but don't lookup if image is unknown locally
image = image_get( image_name, rid, true );
}
- mutex_lock( &client->lock );
client->image = image;
- mutex_unlock( &client->lock );
+ atomic_thread_fence( memory_order_release );
if ( image == NULL ) {
//logadd( LOG_DEBUG1, "Client requested non-existent image '%s' (rid:%d), rejected\n", image_name, (int)rid );
} else if ( !image->working ) {