mirror of https://github.com/BOINC/boinc.git
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
This commit is contained in:
parent
356ce8fe3f
commit
01504084a8
|
@ -17,14 +17,20 @@
|
|||
#include <dc_common.h>
|
||||
#include <dc_internal.h>
|
||||
|
||||
#if CLIENT
|
||||
#ifdef CLIENT
|
||||
#include <dc_client.h>
|
||||
#else
|
||||
#include <glib.h>
|
||||
#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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue