|
15 | 15 | #ifndef RMW__MACROS_H_ |
16 | 16 | #define RMW__MACROS_H_ |
17 | 17 |
|
| 18 | +// This block either sets RMW_THREAD_LOCAL or RMW_THREAD_LOCAL_PTHREAD. |
18 | 19 | #if defined _WIN32 || defined __CYGWIN__ |
| 20 | +// Windows or Cygwin |
19 | 21 | #define RMW_THREAD_LOCAL __declspec(thread) |
20 | 22 | #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" |
27 | 39 | #endif |
28 | | - #endif |
29 | | - |
30 | | - #ifndef RMW_THREAD_LOCAL_PTHREAD |
| 40 | + #elif TARGET_OS_MAC |
| 41 | +// macOS |
31 | 42 | #define RMW_THREAD_LOCAL _Thread_local |
| 43 | + #else |
| 44 | + #error "Unknown Apple platform" |
32 | 45 | #endif |
33 | 46 | #else |
| 47 | +// Some other non-Windows, non-cygwin, non-apple OS |
34 | 48 | #define RMW_THREAD_LOCAL _Thread_local |
35 | 49 | #endif |
36 | 50 |
|
|
0 commit comments