From 01504084a83bfdb9c3b10d30519e81703b34e367 Mon Sep 17 00:00:00 2001 From: gombasg Date: Tue, 14 Apr 2009 13:54:38 +0000 Subject: [PATCH] Add locking around the server-side logging code to make it usable from multi-threaded applications. The rest of the DC-API (and the underlying grid code) is still not thread-safe though. git-svn-id: svn+ssh://cvs.lpds.sztaki.hu/var/lib/svn/szdg/dcapi/trunk@2176 a7169a2c-3604-0410-bc95-c702d8d87f7a --- dcapi/common/logger.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/dcapi/common/logger.c b/dcapi/common/logger.c index c1125febad..17d54cbf1d 100644 --- a/dcapi/common/logger.c +++ b/dcapi/common/logger.c @@ -17,14 +17,20 @@ #include #include -#if CLIENT +#ifdef CLIENT #include +#else +#include #endif /* Set the log level to -1 so the first call to DC_log() will call init_log() */ static int loglevel = -1; static FILE *logfile; +#ifndef CLIENT +G_LOCK_DEFINE_STATIC(logfile); +#endif + /* Stupid Visual C compiler */ #ifdef _MSC_VER #define INIT(x, y) y @@ -156,8 +162,14 @@ void DC_vlog(int level, const char *fmt, va_list ap) tm = localtime(&now); strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm); +#ifndef CLIENT + G_LOCK(logfile); +#endif fprintf(logfile, "%s [%s] ", timebuf, levstr); vfprintf(logfile, fmt, ap); fprintf(logfile, "\n"); fflush(logfile); +#ifndef CLIENT + G_UNLOCK(logfile); +#endif }