summaryrefslogtreecommitdiffstats
path: root/src/server/memlog.c
diff options
context:
space:
mode:
authorsr2013-07-17 12:10:01 +0200
committersr2013-07-17 12:10:01 +0200
commit3fd89450610679c6b777767632d2af5751773295 (patch)
treefdf63e0555bba9601f012ad5ce3eff631941bc4f /src/server/memlog.c
parentAdd debug-lock functions that will helpt to spot deadlocks etc. while developing (diff)
downloaddnbd3-3fd89450610679c6b777767632d2af5751773295.tar.gz
dnbd3-3fd89450610679c6b777767632d2af5751773295.tar.xz
dnbd3-3fd89450610679c6b777767632d2af5751773295.zip
Replace all pthread_spin_* calls with spin_*, so that all locking can be tracked and debugged
Fix compilation of kernel module
Diffstat (limited to 'src/server/memlog.c')
-rw-r--r--src/server/memlog.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/server/memlog.c b/src/server/memlog.c
index 6d4ec09..f159d96 100644
--- a/src/server/memlog.c
+++ b/src/server/memlog.c
@@ -25,6 +25,7 @@
#include <string.h>
#include <stdio.h>
#include <stdint.h>
+#include "locks.h"
#define MAX(a,b) (a > b ? a : b)
@@ -48,7 +49,7 @@ void initmemlog()
{
// Use main spinlock to make sure we really init only once
if (logBuffer) return;
- pthread_spin_init(&logLock, PTHREAD_PROCESS_PRIVATE);
+ spin_init(&logLock, PTHREAD_PROCESS_PRIVATE);
logBuffer = (LogLine *)calloc(LINE_COUNT, sizeof(LogLine));
}
@@ -61,7 +62,7 @@ void memlogf(const char *fmt, ...)
struct tm *timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
- pthread_spin_lock(&logLock);
+ spin_lock(&logLock);
LogLine *const line = (LogLine *)&(logBuffer[bufferPos % LINE_COUNT]);
const size_t offset = strftime(line->text, LINE_LEN, "[%d.%m. %H:%M:%S] ", timeinfo);
if (offset == 0) *line->text = '\0';
@@ -75,7 +76,7 @@ void memlogf(const char *fmt, ...)
// so to be safe either way, let strlen do the job
line->len = strlen(line->text);
if (ret > 0 || line->len > 0) ++bufferPos;
- pthread_spin_unlock(&logLock);
+ spin_unlock(&logLock);
puts(line->text);
}
@@ -86,7 +87,7 @@ char *fetchlog(int maxlines)
const int start = MAX(0, bufferPos - maxlines);
int len = 1, i;
//printf("Outputting log from %d to %d\n", start, bufferPos);
- pthread_spin_lock(&logLock);
+ spin_lock(&logLock);
// Determine required buffer space for all log lines
for (i = start; i < bufferPos; ++i)
{
@@ -113,6 +114,6 @@ char *fetchlog(int maxlines)
}
*pos = '\0';
endFunction:
- pthread_spin_unlock(&logLock);
+ spin_unlock(&logLock);
return retval;
}