Skip to content

Commit 83f361e

Browse files
mergify[bot]MiguelCompanyYour Name
authored
Fix build on QNX (#5871) (#5882)
* Refs #23339. Update QNX patches * Refs #23339. Fix threading_pthread.ipp --------- (cherry picked from commit 14dc063) Signed-off-by: Miguel Company <[email protected]> Signed-off-by: Miguel Company <[email protected]> Co-authored-by: Miguel Company <[email protected]> Co-authored-by: Your Name <[email protected]>
1 parent 70b7daa commit 83f361e

File tree

3 files changed

+153
-18
lines changed

3 files changed

+153
-18
lines changed
Lines changed: 128 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,138 @@
1+
diff --git a/asio/include/asio/detail/impl/posix_thread.ipp b/asio/include/asio/detail/impl/posix_thread.ipp
2+
index 760237733..71077b33c 100644
3+
--- a/asio/include/asio/detail/impl/posix_thread.ipp
4+
+++ b/asio/include/asio/detail/impl/posix_thread.ipp
5+
@@ -47,6 +47,11 @@ std::size_t posix_thread::hardware_concurrency()
6+
{
7+
#if defined(_SC_NPROCESSORS_ONLN)
8+
long result = sysconf(_SC_NPROCESSORS_ONLN);
9+
+
10+
+#if defined(__QNX__)
11+
+ result &= 0xFFFFFFFF;
12+
+#endif //defined(__QNX__)
13+
+
14+
if (result > 0)
15+
return result;
16+
#endif // defined(_SC_NPROCESSORS_ONLN)
17+
diff --git a/asio/include/asio/detail/socket_types.hpp b/asio/include/asio/detail/socket_types.hpp
18+
index cf4f746a4..634591534 100644
19+
--- a/asio/include/asio/detail/socket_types.hpp
20+
+++ b/asio/include/asio/detail/socket_types.hpp
21+
@@ -411,7 +411,13 @@ const int max_iov_len = IOV_MAX;
22+
// POSIX platforms are not required to define IOV_MAX.
23+
const int max_iov_len = 16;
24+
# endif
25+
-# define ASIO_OS_DEF_SA_RESTART SA_RESTART
26+
+// Note: QNX does not support SA_RESTART
27+
+// Therefore they are specifically excluded here.
28+
+# if defined(__QNX__)
29+
+# define ASIO_OS_DEF_SA_RESTART 0
30+
+# else
31+
+# define ASIO_OS_DEF_SA_RESTART SA_RESTART
32+
+# endif
33+
# define ASIO_OS_DEF_SA_NOCLDSTOP SA_NOCLDSTOP
34+
# define ASIO_OS_DEF_SA_NOCLDWAIT SA_NOCLDWAIT
35+
#endif
136
diff --git a/asio/src/Makefile.am b/asio/src/Makefile.am
2-
index e9b20e60..94f13506 100644
37+
index 587bb4935..e86a61ad2 100644
338
--- a/asio/src/Makefile.am
439
+++ b/asio/src/Makefile.am
5-
@@ -14,10 +14,6 @@ if HAVE_CXX17
6-
EXAMPLES_CPP17 = examples/cpp17
40+
@@ -14,20 +14,6 @@ if HAVE_CXX20
41+
EXAMPLES_CPP20 = examples/cpp20
742
endif
843

9-
-SUBDIRS = $(EXAMPLES_CPP03) $(EXAMPLES_CPP11) $(EXAMPLES_CPP14) $(EXAMPLES_CPP17) tests
44+
-SUBDIRS = \
45+
- $(EXAMPLES_CPP11) \
46+
- $(EXAMPLES_CPP14) \
47+
- $(EXAMPLES_CPP17) \
48+
- $(EXAMPLES_CPP20) \
49+
- tests
1050
-
11-
-DIST_SUBDIRS = examples/cpp03 examples/cpp11 examples/cpp14 examples/cpp17 tests
51+
-DIST_SUBDIRS = \
52+
- examples/cpp11 \
53+
- examples/cpp14 \
54+
- examples/cpp17 \
55+
- examples/cpp20 \
56+
- tests
1257
-
1358
EXTRA_DIST = \
1459
Makefile.mgw \
1560
Makefile.msc \
61+
diff --git a/asio/src/examples/cpp11/local/fd_passing_stream_client.cpp b/asio/src/examples/cpp11/local/fd_passing_stream_client.cpp
62+
index 229509f1c..6982507b0 100644
63+
--- a/asio/src/examples/cpp11/local/fd_passing_stream_client.cpp
64+
+++ b/asio/src/examples/cpp11/local/fd_passing_stream_client.cpp
65+
@@ -23,6 +23,14 @@
66+
#include <sys/types.h>
67+
#include <sys/socket.h>
68+
69+
+#if defined(__QNX__)
70+
+ #undef CMSG_ALIGN
71+
+ #define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1))
72+
+
73+
+ #undef CMSG_SPACE
74+
+ #define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr)))
75+
+#endif //defined(__QNX__)
76+
+
77+
using asio::local::stream_protocol;
78+
79+
constexpr std::size_t max_length = 1024;
80+
diff --git a/asio/src/examples/cpp11/local/fd_passing_stream_server.cpp b/asio/src/examples/cpp11/local/fd_passing_stream_server.cpp
81+
index 5082185e7..840646613 100644
82+
--- a/asio/src/examples/cpp11/local/fd_passing_stream_server.cpp
83+
+++ b/asio/src/examples/cpp11/local/fd_passing_stream_server.cpp
84+
@@ -22,6 +22,14 @@
85+
86+
#if defined(ASIO_HAS_LOCAL_SOCKETS)
87+
88+
+#if defined(__QNX__)
89+
+ #undef CMSG_ALIGN
90+
+ #define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1))
91+
+
92+
+ #undef CMSG_SPACE
93+
+ #define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr)))
94+
+#endif //defined(__QNX__)
95+
+
96+
using asio::local::stream_protocol;
97+
98+
class session
99+
diff --git a/asio/src/tests/unit/ip/multicast.cpp b/asio/src/tests/unit/ip/multicast.cpp
100+
index 4f0b3f45e..ced8d1e78 100644
101+
--- a/asio/src/tests/unit/ip/multicast.cpp
102+
+++ b/asio/src/tests/unit/ip/multicast.cpp
103+
@@ -146,17 +146,20 @@ void test()
104+
#if (defined(__MACH__) && defined(__APPLE__)) \
105+
|| defined(__FreeBSD__) \
106+
|| defined(__NetBSD__) \
107+
- || defined(__OpenBSD__)
108+
+ || defined(__OpenBSD__) \
109+
+ || defined(__QNX__)
110+
const ip::address multicast_address_v6 = ip::make_address("ff02::1%lo0", ec);
111+
#else // (defined(__MACH__) && defined(__APPLE__))
112+
// || defined(__FreeBSD__)
113+
// || defined(__NetBSD__)
114+
// || defined(__OpenBSD__)
115+
+ // || defined(__QNX__)
116+
const ip::address multicast_address_v6 = ip::make_address("ff01::1", ec);
117+
#endif // (defined(__MACH__) && defined(__APPLE__))
118+
// || defined(__FreeBSD__)
119+
// || defined(__NetBSD__)
120+
// || defined(__OpenBSD__)
121+
+ // || defined(__QNX__)
122+
ASIO_CHECK(!have_v6 || !ec);
123+
124+
// join_group class.
125+
@@ -207,11 +210,11 @@ void test()
126+
127+
if (have_v6)
128+
{
129+
-#if defined(__hpux)
130+
+#if defined(__hpux) || defined(__QNX__)
131+
ip::multicast::outbound_interface outbound_interface(if_nametoindex("lo0"));
132+
#else
133+
ip::multicast::outbound_interface outbound_interface(1);
134+
-#endif
135+
+#endif // defined(__hpux) || defined(__QNX__)
136+
sock_v6.set_option(outbound_interface, ec);
137+
ASIO_CHECK_MESSAGE(!ec, ec.value() << ", " << ec.message());
138+
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt
2-
index dcbf7ab..9cad45f 100644
2+
index 3b8f886..2d44055 100644
33
--- a/src/cpp/CMakeLists.txt
44
+++ b/src/cpp/CMakeLists.txt
5-
@@ -63,6 +63,10 @@ elseif(NOT EPROSIMA_INSTALLER)
6-
$<$<STREQUAL:$<TARGET_PROPERTY:${PROJECT_NAME},TYPE>,SHARED_LIBRARY>:${PROJECT_NAME_UPPER}_DYN_LINK>
7-
)
5+
@@ -63,6 +63,10 @@ target_compile_definitions(${PROJECT_NAME}
6+
$<$<TARGET_EXISTS:${PROJECT_NAME}>:$<$<STREQUAL:$<TARGET_PROPERTY:${PROJECT_NAME},TYPE>,SHARED_LIBRARY>:${PROJECT_NAME_UPPER}_DYN_LINK>>
7+
)
88

9-
+ if(QNX)
10-
+ target_compile_definitions(${PROJECT_NAME} PRIVATE _QNX_SOURCE)
11-
+ endif()
9+
+if(QNX)
10+
+ target_compile_definitions(${PROJECT_NAME} PRIVATE _QNX_SOURCE)
11+
+endif()
1212
+
13-
# Define public headers
14-
target_include_directories(${PROJECT_NAME} PUBLIC
15-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
13+
# Define public headers
14+
target_include_directories(${PROJECT_NAME} PUBLIC
15+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>

src/cpp/utils/threading/threading_pthread.ipp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
#include <pthread.h>
2121
#include <sys/resource.h>
22+
#if !defined(__QNX__)
2223
#include <sys/sysinfo.h>
24+
#endif //!defined(__QNX__)
2325
#include <sys/time.h>
2426
#include <sys/types.h>
2527

@@ -96,9 +98,12 @@ static void configure_current_thread_scheduler(
9698
// Set Scheduler Class and Priority
9799
//
98100

99-
if ((sched_class == SCHED_OTHER) ||
100-
(sched_class == SCHED_BATCH) ||
101-
(sched_class == SCHED_IDLE))
101+
if ((sched_class == SCHED_OTHER)
102+
#if !defined(__QNX__)
103+
|| (sched_class == SCHED_BATCH)
104+
|| (sched_class == SCHED_IDLE)
105+
#endif // !defined(__QNX__)
106+
)
102107
{
103108
//
104109
// BATCH and IDLE do not have explicit priority values.
@@ -146,6 +151,12 @@ static void configure_current_thread_affinity(
146151
const char* thread_name,
147152
uint64_t affinity_mask)
148153
{
154+
#if defined(__QNX__)
155+
if (affinity_mask > 0)
156+
{
157+
THREAD_EPROSIMA_LOG_ERROR(thread_name, "Setting thread affinity not supported on QNX");
158+
}
159+
#else
149160
int a;
150161
int result;
151162
int cpu_count;
@@ -196,6 +207,7 @@ static void configure_current_thread_affinity(
196207
THREAD_EPROSIMA_LOG_ERROR(thread_name, "Problem to set affinity of thread with id [" << self_tid << "," << thread_name << "] to value " << affinity_mask << ". Error '" << strerror(
197208
result) << "'");
198209
}
210+
#endif // defined(__QNX__)
199211
}
200212

201213
void apply_thread_settings_to_current_thread(

0 commit comments

Comments
 (0)