summaryrefslogtreecommitdiffstats
path: root/src/server/integrity.c
diff options
context:
space:
mode:
authorSimon Rettberg2014-12-31 20:44:32 +0100
committerSimon Rettberg2014-12-31 20:44:32 +0100
commit5b322c5d9ba4c0706c66055be980a814de837002 (patch)
treea71282a7896e28bfaeef038cbd04ed32f24ff0a7 /src/server/integrity.c
parent[SERVER] Create compilation unit for wait/signalling logic (using eventfd) (diff)
downloaddnbd3-5b322c5d9ba4c0706c66055be980a814de837002.tar.gz
dnbd3-5b322c5d9ba4c0706c66055be980a814de837002.tar.xz
dnbd3-5b322c5d9ba4c0706c66055be980a814de837002.zip
[SERVER] Minor tweaks and improvements
Diffstat (limited to 'src/server/integrity.c')
-rw-r--r--src/server/integrity.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/server/integrity.c b/src/server/integrity.c
index 16bc9eb..245d394 100644
--- a/src/server/integrity.c
+++ b/src/server/integrity.c
@@ -28,8 +28,8 @@ static pthread_t thread;
static queue_entry checkQueue[CHECK_QUEUE_SIZE];
static pthread_mutex_t integrityQueueLock;
static pthread_cond_t queueSignal;
-static int queueLen = -1;
-static int bRunning = FALSE;
+static volatile int queueLen = -1;
+static volatile int bRunning = FALSE;
static void* integrity_main(void *data);
@@ -103,6 +103,7 @@ static void* integrity_main(void *data)
uint8_t *buffer = NULL;
size_t bufferSize = 0;
setThreadName( "image-check" );
+ blockNoncriticalSignals();
#if defined(linux) || defined(__linux)
// Setting nice of this thread - this is not POSIX conforming, so check if other platforms support this.
// POSIX says that setpriority() should set the nice value of all threads belonging to the current process,
@@ -112,7 +113,11 @@ static void* integrity_main(void *data)
#endif
pthread_mutex_lock( &integrityQueueLock );
while ( !_shutdown ) {
+ if ( queueLen == 0 ) {
+ pthread_cond_wait( &queueSignal, &integrityQueueLock );
+ }
for (i = queueLen - 1; i >= 0; --i) {
+ if ( _shutdown ) break;
if ( checkQueue[i].image == NULL ) continue;
dnbd3_image_t * const image = image_lock( checkQueue[i].image );
checkQueue[i].image = NULL;
@@ -149,9 +154,6 @@ static void* integrity_main(void *data)
// Release :-)
image_release( image );
}
- if ( queueLen == 0 ) {
- pthread_cond_wait( &queueSignal, &integrityQueueLock );
- }
}
pthread_mutex_unlock( &integrityQueueLock );
if ( buffer != NULL ) free( buffer );