fix get thread id in mac OS
parent
6b69e90016
commit
fe2d4ff780
|
|
@ -1,6 +1,11 @@
|
|||
|
||||
#ifdef OS_LINUX
|
||||
#include <sys/syscall.h>
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#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<len;i++)
|
||||
{
|
||||
if(i%16 == 0)
|
||||
{
|
||||
|
||||
for(i=0; i<len; i++) {
|
||||
if(i % 16 == 0) {
|
||||
fprintf(stderr,"\n");
|
||||
}
|
||||
fprintf(stderr,"[%02x]", (unsigned char)buffer[i]);
|
||||
|
|
@ -49,4 +65,3 @@ int sf_printbuffer(char* buffer,int32_t len)
|
|||
return(0);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue