summaryrefslogtreecommitdiffstats
path: root/package/libupnpp/0001-Check-for-std-future.patch
blob: 73193953d8c5124c3ef8b35fcd2b0952b78154ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
From 3bfcb171026c4fd5c7caf807f79184a81c8af5b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rg=20Krause?= <joerg.krause@embedded.rocks>
Date: Sun, 11 Sep 2016 21:09:22 +0200
Subject: [PATCH] Check for std::future
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

std::future is not available for all architectures, e.g. it is missing
for ARMv5 (soft-float).

The problem is that libstdc++ only enables `std::future` if
`ATOMIC_INT_LOCK_FREE > 1` which is not true for the ARMv5 target.

As the future functionality is not used for much we just ifdef out the
parts from `std::future`.

Upstream-status: https://github.com/medoc92/libupnpp/issues/8

This patch is squashed from two upstream commits:
1/ d3e3cada667cca5b70693b351e5865231275dd82
2/ 90407dcc206987c8e58d61c64db539489f0717d2

Signed-off-by: Jörg Krause <joerg.krause@embedded.rocks>
---
 configure.ac         | 17 +++++++++++++++++
 libupnpp/config.h.in |  3 +++
 libupnpp/workqueue.h | 14 +++++++++++++-
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 877a773..9ff2058 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,6 +47,23 @@ AC_DEFINE([_FILE_OFFSET_BITS], [64], [File Offset size])
 AC_CHECK_LIB([rt], [clock_gettime], [], [])
 AC_CHECK_LIB([pthread], [pthread_create], [], [])
 
+# Check that std::future is available.
+AC_LANG_PUSH([C++])
+CXXFLAGS="-std=c++11 $CXXFLAGS"
+AC_MSG_CHECKING([whether std::future is available])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <future>]],
+		[[std::future<int> f;]])],
+	[ AC_DEFINE([HAVE_STD_FUTURE], [1],
+		[Define to 1 if you have the `std::future`.])
+	  have_std_future=yes
+	],
+	[
+	  have_std_future=no
+	]
+)
+AC_MSG_RESULT([$have_std_future])
+AC_LANG_POP
+
 # The 2 following checks for libthreadutil and libixml are normally
 # unnecessary and even problematic. libupnpp does not use them directly,
 # and they should be used automatically because libupnpp is linked with them.
diff --git a/libupnpp/config.h.in b/libupnpp/config.h.in
index 39fa410..4471855 100644
--- a/libupnpp/config.h.in
+++ b/libupnpp/config.h.in
@@ -36,6 +36,9 @@
 /* Define to 1 if you have the <stdlib.h> header file. */
 #undef HAVE_STDLIB_H
 
+/* Define to 1 if you have the `std::future`. */
+#undef HAVE_STD_FUTURE
+
 /* Define to 1 if you have the <strings.h> header file. */
 #undef HAVE_STRINGS_H
 
diff --git a/libupnpp/workqueue.h b/libupnpp/workqueue.h
index 52a6138..9c0ec02 100644
--- a/libupnpp/workqueue.h
+++ b/libupnpp/workqueue.h
@@ -18,7 +18,9 @@
 #define _WORKQUEUE_H_INCLUDED_
 
 #include <thread>
+#if HAVE_STD_FUTURE
 #include <future>
+#endif
 #include <string>
 #include <queue>
 #include <list>
@@ -76,10 +78,14 @@ public:
     bool start(int nworkers, void *(workproc)(void *), void *arg) {
         std::unique_lock<std::mutex> lock(m_mutex);
         for (int i = 0; i < nworkers; i++) {
-            std::packaged_task<void *(void *)> task(workproc);
             Worker w;
+#if HAVE_STD_FUTURE
+            std::packaged_task<void *(void *)> task(workproc);
             w.res = task.get_future();
             w.thr = std::thread(std::move(task), arg);
+#else
+            w.thr = std::thread(workproc, arg);
+#endif
             m_worker_threads.push_back(std::move(w));
         }
         return true;
@@ -189,7 +195,11 @@ public:
         // Workers return (void*)1 if ok
         void *statusall = (void*)1;
         while (!m_worker_threads.empty()) {
+#if HAVE_STD_FUTURE
             void *status = m_worker_threads.front().res.get();
+#else
+            void *status = (void*) 1;
+#endif
             m_worker_threads.front().thr.join();
             if (status == (void *)0) {
                 statusall = status;
@@ -305,7 +315,9 @@ private:
 
     struct Worker {
         std::thread         thr;
+#if HAVE_STD_FUTURE
         std::future<void *> res;
+#endif
     };
     
     // Configuration
-- 
2.9.3

OpenPOWER on IntegriCloud