refactoring

This commit is contained in:
Devaev Maxim
2019-03-18 21:43:23 +03:00
parent 73ceba77a8
commit 7fbeca41fa
2 changed files with 8 additions and 6 deletions

View File

@@ -25,16 +25,12 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <errno.h> #include <errno.h>
#include <time.h> #include <time.h>
#include <assert.h> #include <assert.h>
#include <pthread.h> #include <pthread.h>
#include <sys/types.h>
#include <sys/syscall.h>
#include "tools.h" #include "tools.h"
@@ -72,7 +68,7 @@ pthread_mutex_t log_mutex;
} }
#define LOG_PRINTF_NOLOCK(_label, _msg, ...) { \ #define LOG_PRINTF_NOLOCK(_label, _msg, ...) { \
printf("-- " _label " [%.03Lf tid=%ld] -- " _msg "\n", get_now_monotonic(), syscall(SYS_gettid), ##__VA_ARGS__); \ printf("-- " _label " [%.03Lf tid=%d] -- " _msg "\n", get_now_monotonic(), get_thread_id(), ##__VA_ARGS__); \
fflush(stdout); \ fflush(stdout); \
} }
@@ -86,7 +82,7 @@ pthread_mutex_t log_mutex;
char _buf[1024] = ""; \ char _buf[1024] = ""; \
char *_ptr = strerror_r(errno, _buf, 1024); \ char *_ptr = strerror_r(errno, _buf, 1024); \
LOGGING_LOCK; \ LOGGING_LOCK; \
printf("-- ERROR [%.03Lf tid=%ld] -- " _msg ": %s\n", get_now_monotonic(), syscall(SYS_gettid), ##__VA_ARGS__, _ptr); \ printf("-- ERROR [%.03Lf tid=%d] -- " _msg ": %s\n", get_now_monotonic(), get_thread_id(), ##__VA_ARGS__, _ptr); \
fflush(stdout); \ fflush(stdout); \
LOGGING_UNLOCK; \ LOGGING_UNLOCK; \
} }

View File

@@ -25,12 +25,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <unistd.h>
#include <errno.h> #include <errno.h>
#include <math.h> #include <math.h>
#include <pthread.h> #include <pthread.h>
#include <time.h> #include <time.h>
#include <assert.h> #include <assert.h>
#include <sys/types.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/syscall.h> #include <sys/syscall.h>
@@ -102,3 +104,7 @@ INLINE long double get_now_real(void) {
get_now(CLOCK_REALTIME, &sec, &msec); get_now(CLOCK_REALTIME, &sec, &msec);
return (long double)sec + ((long double)msec) / 1000; return (long double)sec + ((long double)msec) / 1000;
} }
INLINE pid_t get_thread_id(void) {
return syscall(SYS_gettid);
}