From a36358190b0fefc5274d3fb379e3ac8329f65fe1 Mon Sep 17 00:00:00 2001 From: def Date: Thu, 11 Sep 2014 21:38:23 +0200 Subject: [PATCH] Mac OS X compilation --- src/base/system.c | 142 ++++++++++++++++++----------------- src/base/system.h | 2 + src/engine/client/client.cpp | 2 + src/engine/server/server.cpp | 2 + 4 files changed, 79 insertions(+), 69 deletions(-) diff --git a/src/base/system.c b/src/base/system.c index 9c17868b9..7d30535dd 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -88,6 +88,7 @@ void dbg_break() *((volatile unsigned*)0) = 0x0; } +#if !defined(CONF_PLATFORM_MACOSX) #define QUEUE_SIZE 16 typedef struct @@ -113,75 +114,6 @@ int queue_full(Queue *q) return ((q->end+1) % QUEUE_SIZE) == q->begin; } -void dbg_msg(const char *sys, const char *fmt, ...) -{ - va_list args; - char *msg; - int len; - int e; - - //str_format(str, sizeof(str), "[%08x][%s]: ", (int)time(0), sys); - time_t rawtime; - struct tm* timeinfo; - char timestr [80]; - - time ( &rawtime ); - timeinfo = localtime ( &rawtime ); - - strftime (timestr,sizeof(timestr),"%y-%m-%d %H:%M:%S",timeinfo); - - if(dbg_msg_threaded) - { - semaphore_wait(&log_queue.notfull); - semaphore_wait(&log_queue.mutex); - e = queue_empty(&log_queue); - - str_format(log_queue.q[log_queue.end], sizeof(log_queue.q[log_queue.end]), "[%s][%s]: ", timestr, sys); - - len = strlen(log_queue.q[log_queue.end]); - msg = (char *)log_queue.q[log_queue.end] + len; - - va_start(args, fmt); -#if defined(CONF_FAMILY_WINDOWS) - _vsnprintf(msg, sizeof(log_queue.q[log_queue.end])-len, fmt, args); -#else - vsnprintf(msg, sizeof(log_queue.q[log_queue.end])-len, fmt, args); -#endif - va_end(args); - - log_queue.end = (log_queue.end + 1) % QUEUE_SIZE; - - if(e) - semaphore_signal(&log_queue.notempty); - - if(!queue_full(&log_queue)) - semaphore_signal(&log_queue.notfull); - - semaphore_signal(&log_queue.mutex); - } - else - { - char str[1024*4]; - int i; - - str_format(str, sizeof(str), "[%s][%s]: ", timestr, sys); - - len = strlen(str); - msg = (char *)str + len; - - va_start(args, fmt); -#if defined(CONF_FAMILY_WINDOWS) - _vsnprintf(msg, sizeof(str)-len, fmt, args); -#else - vsnprintf(msg, sizeof(str)-len, fmt, args); -#endif - va_end(args); - - for(i = 0; i < num_loggers; i++) - loggers[i](str); - } -} - void dbg_msg_thread(void *v) { char str[1024*4]; @@ -231,6 +163,78 @@ void dbg_enable_threaded() pthread_detach((pthread_t)Thread); #endif } +#endif + +void dbg_msg(const char *sys, const char *fmt, ...) +{ + va_list args; + char *msg; + int len; + int e; + + //str_format(str, sizeof(str), "[%08x][%s]: ", (int)time(0), sys); + time_t rawtime; + struct tm* timeinfo; + char timestr [80]; + + time ( &rawtime ); + timeinfo = localtime ( &rawtime ); + + strftime (timestr,sizeof(timestr),"%y-%m-%d %H:%M:%S",timeinfo); + +#if !defined(CONF_PLATFORM_MACOSX) + if(dbg_msg_threaded) + { + semaphore_wait(&log_queue.notfull); + semaphore_wait(&log_queue.mutex); + e = queue_empty(&log_queue); + + str_format(log_queue.q[log_queue.end], sizeof(log_queue.q[log_queue.end]), "[%s][%s]: ", timestr, sys); + + len = strlen(log_queue.q[log_queue.end]); + msg = (char *)log_queue.q[log_queue.end] + len; + + va_start(args, fmt); +#if defined(CONF_FAMILY_WINDOWS) + _vsnprintf(msg, sizeof(log_queue.q[log_queue.end])-len, fmt, args); +#else + vsnprintf(msg, sizeof(log_queue.q[log_queue.end])-len, fmt, args); +#endif + va_end(args); + + log_queue.end = (log_queue.end + 1) % QUEUE_SIZE; + + if(e) + semaphore_signal(&log_queue.notempty); + + if(!queue_full(&log_queue)) + semaphore_signal(&log_queue.notfull); + + semaphore_signal(&log_queue.mutex); + } + else +#endif + { + char str[1024*4]; + int i; + + str_format(str, sizeof(str), "[%s][%s]: ", timestr, sys); + + len = strlen(str); + msg = (char *)str + len; + + va_start(args, fmt); +#if defined(CONF_FAMILY_WINDOWS) + _vsnprintf(msg, sizeof(str)-len, fmt, args); +#else + vsnprintf(msg, sizeof(str)-len, fmt, args); +#endif + va_end(args); + + for(i = 0; i < num_loggers; i++) + loggers[i](str); + } +} static void logger_stdout(const char *line) { diff --git a/src/base/system.h b/src/base/system.h index 7a71c6d50..4f445b596 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -1176,7 +1176,9 @@ void swap_endian(void *data, unsigned elem_size, unsigned num); typedef void (*DBG_LOGGER)(const char *line); void dbg_logger(DBG_LOGGER logger); +#if !defined(CONF_PLATFORM_MACOSX) void dbg_enable_threaded(); +#endif void dbg_logger_stdout(); void dbg_logger_debugger(); void dbg_logger_file(const char *filename); diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 430601f6e..2a188d62c 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -3045,7 +3045,9 @@ int main(int argc, const char **argv) // ignore_convention } #endif +#if !defined(CONF_PLATFORM_MACOSX) dbg_enable_threaded(); +#endif CClient *pClient = CreateClient(); IKernel *pKernel = IKernel::Create(); diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 28dc301f0..4ba27c309 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -1964,7 +1964,9 @@ static CServer *CreateServer() { return new CServer(); } int main(int argc, const char **argv) // ignore_convention { +#if !defined(CONF_PLATFORM_MACOSX) dbg_enable_threaded(); +#endif #if defined(CONF_FAMILY_WINDOWS) for(int i = 1; i < argc; i++) // ignore_convention {