From aac187d3a04daa4a80a0de912783a40a52addefb Mon Sep 17 00:00:00 2001 From: lisr Date: Fri, 19 Nov 2021 10:55:43 +0800 Subject: [PATCH 1/3] fix aix compile error --- include/spdlog/details/os-inl.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/spdlog/details/os-inl.h b/include/spdlog/details/os-inl.h index 0575d811..b32eb85b 100644 --- a/include/spdlog/details/os-inl.h +++ b/include/spdlog/details/os-inl.h @@ -230,8 +230,8 @@ SPDLOG_INLINE size_t filesize(FILE *f) # endif #else // unix -// OpenBSD doesn't compile with :: before the fileno(..) -# if defined(__OpenBSD__) +// OpenBSD and AIX doesn't compile with :: before the fileno(..) +# if defined(__OpenBSD__) || defined(_AIX) int fd = fileno(f); # else int fd = ::fileno(f); @@ -336,7 +336,9 @@ SPDLOG_INLINE size_t _thread_id() SPDLOG_NOEXCEPT # define SYS_gettid __NR_gettid # endif return static_cast(::syscall(SYS_gettid)); -#elif defined(_AIX) || defined(__DragonFly__) || defined(__FreeBSD__) +#elif defined(_AIX) + return static_cast(::pthread_self()); +#elif defined(__DragonFly__) || defined(__FreeBSD__) return static_cast(::pthread_getthreadid_np()); #elif defined(__NetBSD__) return static_cast(::_lwp_self()); From 232df72b82c8645b06a36d71496062d550603ba7 Mon Sep 17 00:00:00 2001 From: lisr Date: Sat, 20 Nov 2021 09:48:14 +0800 Subject: [PATCH 2/3] use pthread_getthrds_np for AIX --- include/spdlog/details/os-inl.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/spdlog/details/os-inl.h b/include/spdlog/details/os-inl.h index b32eb85b..a7cd37f7 100644 --- a/include/spdlog/details/os-inl.h +++ b/include/spdlog/details/os-inl.h @@ -46,7 +46,7 @@ # include //Use gettid() syscall under linux to get thread id # elif defined(_AIX) -# include // for pthread_getthreadid_np +# include // for pthread_getthrds_np # elif defined(__DragonFly__) || defined(__FreeBSD__) # include // for pthread_getthreadid_np @@ -337,7 +337,12 @@ SPDLOG_INLINE size_t _thread_id() SPDLOG_NOEXCEPT # endif return static_cast(::syscall(SYS_gettid)); #elif defined(_AIX) - return static_cast(::pthread_self()); + struct __pthrdsinfo buf; + int reg_size = 0; + pthread_t pt = pthread_self(); + int retval = pthread_getthrds_np(&pt, PTHRDSINFO_QUERY_TID, &buf, sizeof(buf), NULL, ®_size); + int tid = (!retval) ? buf.__pi_tid : 0; + return static_cast(tid); #elif defined(__DragonFly__) || defined(__FreeBSD__) return static_cast(::pthread_getthreadid_np()); #elif defined(__NetBSD__) From 569b851b8093ca33c7966b732c817b6e948b015d Mon Sep 17 00:00:00 2001 From: lisr Date: Sat, 20 Nov 2021 22:48:18 +0800 Subject: [PATCH 3/3] aix - reference to 'thread' is ambiguous, sys/thread.h vs std::thread --- bench/async_bench.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/async_bench.cpp b/bench/async_bench.cpp index ce2c9281..cf4d9754 100644 --- a/bench/async_bench.cpp +++ b/bench/async_bench.cpp @@ -162,7 +162,7 @@ void thread_fun(std::shared_ptr logger, int howmany) void bench_mt(int howmany, std::shared_ptr logger, int thread_count) { using std::chrono::high_resolution_clock; - vector threads; + vector threads; auto start = high_resolution_clock::now(); int msgs_per_thread = howmany / thread_count;