Skip to content

Commit 2e6ec7f

Browse files
committed
spdlog: backport support for more Unices
gabime/spdlog@53b2308 gabime/spdlog@8d57823
1 parent a82c3d5 commit 2e6ec7f

File tree

1 file changed

+23
-7
lines changed
  • Source/GmmLib/Utility/GmmLog/spdlog/details

1 file changed

+23
-7
lines changed

Source/GmmLib/Utility/GmmLog/spdlog/details/os.h

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,20 @@
3939
#include <unistd.h>
4040
#include <chrono>
4141

42-
#elif __FreeBSD__
43-
#include <sys/thr.h> //Use thr_self() syscall under FreeBSD to get thread id
42+
#elif defined(_AIX)
43+
#include <pthread.h> // for pthread_getthreadid_np
44+
45+
#elif defined(__DragonFly__) || defined(__FreeBSD__)
46+
#include <pthread_np.h> // for pthread_getthreadid_np
47+
48+
#elif defined(__NetBSD__)
49+
#include <lwp.h> // for _lwp_self
50+
51+
#elif defined(__OpenBSD__)
52+
#include <unistd.h> // for getthrid
53+
54+
#elif defined(__sun)
55+
#include <thread.h> // for thr_self
4456

4557
#else
4658
#include <thread>
@@ -213,7 +225,7 @@ inline size_t filesize(FILE *f)
213225
#else // unix
214226
int fd = fileno(f);
215227
//64 bits(but not in osx, where fstat64 is deprecated)
216-
#if !defined(__FreeBSD__) && !defined(__APPLE__) && (defined(__x86_64__) || defined(__ppc64__))
228+
#if (defined(__linux__) || defined(__sun) || defined(_AIX)) && (defined(__LP64__) || defined(_LP64))
217229
struct stat64 st;
218230
if (fstat64(fd, &st) == 0)
219231
return static_cast<size_t>(st.st_size);
@@ -302,10 +314,14 @@ inline size_t thread_id()
302314
# define SYS_gettid __NR_gettid
303315
# endif
304316
return static_cast<size_t>(syscall(SYS_gettid));
305-
#elif __FreeBSD__
306-
long tid;
307-
thr_self(&tid);
308-
return static_cast<size_t>(tid);
317+
#elif defined(_AIX) || defined(__DragonFly__) || defined(__FreeBSD__)
318+
return static_cast<size_t>(pthread_getthreadid_np());
319+
#elif defined(__NetBSD__)
320+
return static_cast<size_t>(_lwp_self());
321+
#elif defined(__OpenBSD__)
322+
return static_cast<size_t>(getthrid());
323+
#elif defined(__sun)
324+
return static_cast<size_t>(thr_self());
309325
#else //Default to standard C++11 (OSX and other Unix)
310326
return static_cast<size_t>(std::hash<std::thread::id>()(std::this_thread::get_id()));
311327
#endif

0 commit comments

Comments
 (0)