From fe2d4ff780c2ea9641dc9ac928b0c9fd04decb9d Mon Sep 17 00:00:00 2001 From: yuqing Date: Thu, 10 May 2018 11:24:02 +0800 Subject: [PATCH] fix get thread id in mac OS --- src/sf_util.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/sf_util.c b/src/sf_util.c index e322082..70b9850 100644 --- a/src/sf_util.c +++ b/src/sf_util.c @@ -1,6 +1,11 @@ + +#ifdef OS_LINUX #include +#endif + #include #include +#include #include "sf_util.h" int64_t getticks() @@ -15,32 +20,43 @@ void log_plus(const int priority, const char* file, { char buf[2048]; int hlen; + va_list ap; +#ifdef DEBUG_FLAG + long tid; +#endif + if (g_log_context.log_level < priority) { return; } + #ifdef DEBUG_FLAG - hlen = snprintf(buf, sizeof(buf), "%s:%d %ld ", file, line, (long)syscall(SYS_gettid)); + +#ifdef OS_LINUX + tid = (long)syscall(SYS_gettid); +#else + tid = (long)pthread_self(); +#endif + hlen = snprintf(buf, sizeof(buf), "%s:%d %ld ", file, line, tid); + #else hlen = snprintf(buf, sizeof(buf), "%s:%d ", file, line); #endif - va_list ap; va_start(ap, fmt); hlen += vsnprintf(buf+hlen, sizeof(buf)-hlen, fmt, ap); va_end(ap); log_it_ex1(&g_log_context, priority, buf, hlen); } + int sf_printbuffer(char* buffer,int32_t len) { int i; - if(buffer==NULL) - { + if(buffer == NULL) { fprintf(stderr, "common-utils parameter is fail"); return(-1); } - for(i=0;i