Skip to content

Commit df1500b

Browse files
committed
change detection of apple OS's
also undef RMW_THREAD_LOCAL to cause compiler error in the case that pthread must be used
1 parent 2c80634 commit df1500b

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

rmw/include/rmw/macros.h

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,36 @@
1515
#ifndef RMW__MACROS_H_
1616
#define RMW__MACROS_H_
1717

18+
// This block either sets RMW_THREAD_LOCAL or RMW_THREAD_LOCAL_PTHREAD.
1819
#if defined _WIN32 || defined __CYGWIN__
20+
// Windows or Cygwin
1921
#define RMW_THREAD_LOCAL __declspec(thread)
2022
#elif defined __APPLE__
21-
#include <Availability.h>
22-
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
23-
// iOS 10 added support for thread local storage
24-
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 100000
25-
#define RMW_THREAD_LOCAL_PTHREAD 1
26-
#define RMW_THREAD_LOCAL
23+
// Apple OS's
24+
#include <TargetConditionals.h>
25+
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
26+
// iOS Simulator or iOS device
27+
#include <Availability.h>
28+
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
29+
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
30+
// iOS >= 10, thread local storage was added in iOS 10
31+
#define RMW_THREAD_LOCAL _Thread_local
32+
#else
33+
// iOS < 10, no thread local storage, so use pthread instead
34+
#define RMW_THREAD_LOCAL_PTHREAD 1
35+
#undef RMW_THREAD_LOCAL
36+
#endif
37+
#else
38+
#error "Unknown iOS version"
2739
#endif
28-
#endif
29-
30-
#ifndef RMW_THREAD_LOCAL_PTHREAD
40+
#elif TARGET_OS_MAC
41+
// macOS
3142
#define RMW_THREAD_LOCAL _Thread_local
43+
#else
44+
#error "Unknown Apple platform"
3245
#endif
3346
#else
47+
// Some other non-Windows, non-cygwin, non-apple OS
3448
#define RMW_THREAD_LOCAL _Thread_local
3549
#endif
3650

0 commit comments

Comments
 (0)