Skip to content

Commit 2f4037b

Browse files
authored
namespace version bump (#541)
Bumping the inline namespace version to v2 to avoid ODR violations. The pre_exit code remains at v1 (it must be bumped more carefully). The portable default executor is moving to v2 - which may lead to more than one thread pool for the portable instance. Pinning the version here is more difficult. Removed dead reset() operations in future shared_base Documented (and assert) precondition that future::exception() is only invoked on a ready exception. Made more of the tuple meta-facilities public to avoid detail:: namespace usage in unit tests. Restructured unit tests to avoid sleep-wait-loops.
1 parent 3409d0e commit 2f4037b

31 files changed

+405
-462
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ cmake -S . -B ../BUILD -GNinja -DCMAKE_CXX_STANDARD=17 -DCMAKE_BUILD_TYPE=Releas
7474
If you organize the build directory into subdirectories you can support multiple configurations.
7575

7676
```
77+
rm -rf ../builds/portable
7778
cmake -S . -B ../builds/portable -GXcode -DCMAKE_CXX_STANDARD=17 -DBUILD_TESTING=ON -DSTLAB_TASK_SYSTEM=portable -DCMAKE_OSX_DEPLOYMENT_TARGET=14.4 -DCMAKE_OSX_DEPLOYMENT_TARGET=macosx14.4
7879
```
7980

stlab/concurrency/await.hpp

+5-10
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@
3131
/**************************************************************************************************/
3232

3333
namespace stlab {
34-
35-
/**************************************************************************************************/
36-
37-
inline namespace v1 {
34+
inline namespace STLAB_VERSION_NAMESPACE() {
3835

3936
/**************************************************************************************************/
4037

@@ -203,18 +200,16 @@ template <class T>
203200
}
204201

205202
template <class T>
206-
[[deprecated("Use await_for instead.")]] auto blocking_get(future<T> x,
207-
const std::chrono::nanoseconds& timeout)
208-
-> decltype(x.get_try()) {
203+
[[deprecated("Use await_for instead.")]] auto blocking_get(
204+
future<T> x, const std::chrono::nanoseconds& timeout) -> decltype(x.get_try()) {
209205
return blocking_get_for(std::move(x), timeout).get_try();
210206
}
211207

212208
/**************************************************************************************************/
213209

214-
} // namespace v1
210+
} // namespace STLAB_VERSION_NAMESPACE()
211+
} // namespace stlab
215212

216213
/**************************************************************************************************/
217214

218-
} // namespace stlab
219-
220215
#endif // STLAB_CONCURRENCY_AWAIT_HPP

stlab/concurrency/channel.hpp

+11-15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef STLAB_CONCURRENCY_CHANNEL_HPP
1010
#define STLAB_CONCURRENCY_CHANNEL_HPP
1111

12+
#include <stlab/config.hpp>
13+
1214
#include <algorithm>
1315
#include <array>
1416
#include <atomic>
@@ -33,10 +35,7 @@
3335
/**************************************************************************************************/
3436

3537
namespace stlab {
36-
37-
/**************************************************************************************************/
38-
39-
inline namespace v1 {
38+
inline namespace STLAB_VERSION_NAMESPACE() {
4039

4140
/**************************************************************************************************/
4241

@@ -192,7 +191,9 @@ using avoid = std::conditional_t<std::is_same<void, T>::value, avoid_, T>;
192191
/**************************************************************************************************/
193192

194193
template <typename F, std::size_t... I, typename... T>
195-
auto invoke_(F&& f, std::tuple<std::variant<T, std::exception_ptr>...>& t, std::index_sequence<I...>) {
194+
auto invoke_(F&& f,
195+
std::tuple<std::variant<T, std::exception_ptr>...>& t,
196+
std::index_sequence<I...>) {
196197
return std::forward<F>(f)(std::move(std::get<I>(t))...);
197198
}
198199

@@ -484,14 +485,12 @@ struct round_robin_queue_strategy {
484485
queue_t _queue;
485486

486487
bool empty() const {
487-
return get_i(
488-
_queue, _index, [](const auto& c) { return c.empty(); }, true);
488+
return get_i(_queue, _index, [](const auto& c) { return c.empty(); }, true);
489489
}
490490

491491
auto front() {
492492
assert(!empty() && "front on an empty container is a very bad idea!");
493-
return std::make_tuple(get_i(
494-
_queue, _index, [](auto& c) { return c.front(); }, item_t{}));
493+
return std::make_tuple(get_i(_queue, _index, [](auto& c) { return c.front(); }, item_t{}));
495494
}
496495

497496
void pop_front() {
@@ -546,8 +545,8 @@ struct unordered_queue_strategy {
546545
auto front() {
547546
assert(!empty() && "front on an empty container is a very bad idea!");
548547
_index = tuple_find(_queue, [](const auto& c) { return !c.empty(); });
549-
return std::make_tuple(get_i(
550-
_queue, _index, [](auto& c) { return std::move(c.front()); }, item_t{}));
548+
return std::make_tuple(
549+
get_i(_queue, _index, [](auto& c) { return std::move(c.front()); }, item_t{}));
551550
}
552551

553552
void pop_front() {
@@ -1705,10 +1704,7 @@ struct function_process<R(Args...)> {
17051704

17061705
/**************************************************************************************************/
17071706

1708-
} // namespace v1
1709-
1710-
/**************************************************************************************************/
1711-
1707+
} // namespace STLAB_VERSION_NAMESPACE()
17121708
} // namespace stlab
17131709

17141710
/**************************************************************************************************/

stlab/concurrency/default_executor.hpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@
4040
/**************************************************************************************************/
4141

4242
namespace stlab {
43-
44-
/**************************************************************************************************/
45-
46-
inline namespace v1 {
43+
inline namespace STLAB_VERSION_NAMESPACE() {
4744

4845
/**************************************************************************************************/
4946

@@ -500,10 +497,7 @@ constexpr auto high_executor = detail::executor_type<detail::executor_priority::
500497

501498
/**************************************************************************************************/
502499

503-
} // namespace v1
504-
505-
/**************************************************************************************************/
506-
500+
} // namespace STLAB_VERSION_NAMESPACE()
507501
} // namespace stlab
508502

509503
/**************************************************************************************************/

stlab/concurrency/executor_base.hpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef STLAB_CONCURRENCY_EXECUTOR_BASE_HPP
1010
#define STLAB_CONCURRENCY_EXECUTOR_BASE_HPP
1111

12+
#include <stlab/config.hpp>
13+
1214
#include <chrono>
1315
#include <functional>
1416

@@ -18,12 +20,10 @@
1820
/**************************************************************************************************/
1921

2022
namespace stlab {
23+
inline namespace STLAB_VERSION_NAMESPACE() {
2124

2225
/**************************************************************************************************/
2326

24-
inline namespace v1 {
25-
/**************************************************************************************************/
26-
2727
using executor_t = std::function<void(stlab::task<void() noexcept>)>;
2828

2929
/*
@@ -82,10 +82,7 @@ executor_task_pair<F> operator&(F&& f, executor e) {
8282

8383
/**************************************************************************************************/
8484

85-
} // namespace v1
86-
87-
/**************************************************************************************************/
88-
85+
} // namespace STLAB_VERSION_NAMESPACE()
8986
} // namespace stlab
9087

9188
/**************************************************************************************************/

stlab/concurrency/future.hpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@
3838
/**************************************************************************************************/
3939

4040
namespace stlab {
41-
42-
/**************************************************************************************************/
43-
44-
inline namespace v1 {
41+
inline namespace STLAB_VERSION_NAMESPACE() {
4542

4643
/**************************************************************************************************/
4744

@@ -274,8 +271,6 @@ struct shared_base<T, enable_if_copyable<T>> : std::enable_shared_from_this<shar
274271

275272
explicit shared_base(executor_t s) : _executor(std::move(s)) {}
276273

277-
void reset() { _then.clear(); } // NEEDS MUTEX
278-
279274
template <typename F>
280275
auto recover(future<T>&& p, F&& f) {
281276
return recover(std::move(p), _executor, std::forward<F>(f));
@@ -389,8 +384,6 @@ struct shared_base<T, enable_if_not_copyable<T>> : std::enable_shared_from_this<
389384

390385
explicit shared_base(executor_t s) : _executor(std::move(s)) {}
391386

392-
void reset() { _then.second = task<void() noexcept>{}; }
393-
394387
template <typename F>
395388
auto recover(future<T>&& p, F&& f) {
396389
return recover(std::move(p), _executor, std::forward<F>(f));
@@ -474,8 +467,6 @@ struct shared_base<void> : std::enable_shared_from_this<shared_base<void>> {
474467

475468
explicit shared_base(executor_t s) : _executor(std::move(s)) {}
476469

477-
void reset() { _then.clear(); }
478-
479470
template <typename F>
480471
auto recover(future<result_type>&& p, F&& f) {
481472
return recover(std::move(p), _executor, std::forward<F>(f));
@@ -750,7 +741,11 @@ class STLAB_NODISCARD() future<T, enable_if_copyable<T>> {
750741
return _p->_exception ? std::optional<std::exception_ptr>{_p->_exception} : std::nullopt;
751742
}
752743

753-
std::exception_ptr exception() const& { return _p->_exception; }
744+
// Precondition: is_ready()
745+
std::exception_ptr exception() const& {
746+
assert(is_ready());
747+
return _p->_exception;
748+
}
754749
};
755750

756751
/**************************************************************************************************/
@@ -897,7 +892,11 @@ class STLAB_NODISCARD() future<void, void> {
897892
return _p->_exception ? std::optional<std::exception_ptr>{_p->_exception} : std::nullopt;
898893
}
899894

900-
std::exception_ptr exception() const& { return _p->_exception; }
895+
// Precondition: is_ready()
896+
std::exception_ptr exception() const& {
897+
assert(is_ready());
898+
return _p->_exception;
899+
}
901900
};
902901

903902
/**************************************************************************************************/
@@ -1001,7 +1000,11 @@ class STLAB_NODISCARD() future<T, enable_if_not_copyable<T>> {
10011000
return _p->_exception ? std::optional<std::exception_ptr>{_p->_exception} : std::nullopt;
10021001
}
10031002

1004-
std::exception_ptr exception() const& { return _p->_exception; }
1003+
// Precondition: is_ready()
1004+
std::exception_ptr exception() const& {
1005+
assert(is_ready());
1006+
return _p->_exception;
1007+
}
10051008
};
10061009

10071010
template <typename Sig, typename E, typename F>
@@ -1233,7 +1236,7 @@ template <typename E, typename F, typename... Ts>
12331236
auto when_all(E executor, F f, future<Ts>... args) {
12341237
using vt_t = voidless_tuple<Ts...>;
12351238
using opt_t = optional_placeholder_tuple<Ts...>;
1236-
using result_t = decltype(detail::apply_tuple(std::declval<F>(), std::declval<vt_t>()));
1239+
using result_t = decltype(apply_ignore_placeholders(std::declval<F>(), std::declval<vt_t>()));
12371240

12381241
auto shared = std::make_shared<detail::when_all_shared<F, opt_t>>();
12391242
auto p = package<result_t()>(
@@ -1816,10 +1819,7 @@ auto shared_base<void>::recover(future<result_type>&& p, E executor, F&& f) {
18161819

18171820
/**************************************************************************************************/
18181821

1819-
} // namespace v1
1820-
1821-
/**************************************************************************************************/
1822-
1822+
} // namespace STLAB_VERSION_NAMESPACE()
18231823
} // namespace stlab
18241824

18251825
/**************************************************************************************************/

stlab/concurrency/immediate_executor.hpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
#ifndef STLAB_CONCURRENCY_IMMEDIATE_EXECUTOR_HPP
1010
#define STLAB_CONCURRENCY_IMMEDIATE_EXECUTOR_HPP
1111

12+
#include <stlab/config.hpp>
13+
1214
#include <type_traits>
1315

1416
/**************************************************************************************************/
1517

1618
namespace stlab {
19+
inline namespace STLAB_VERSION_NAMESPACE() {
1720

1821
/**************************************************************************************************/
1922

20-
inline namespace v1 {
21-
/**************************************************************************************************/
22-
2323
namespace detail {
2424

2525
/**************************************************************************************************/
@@ -41,10 +41,7 @@ constexpr auto immediate_executor = detail::immediate_executor_type{};
4141

4242
/**************************************************************************************************/
4343

44-
} // namespace v1
45-
46-
/**************************************************************************************************/
47-
44+
} // namespace STLAB_VERSION_NAMESPACE()
4845
} // namespace stlab
4946

5047
/**************************************************************************************************/

stlab/concurrency/main_executor.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@
3535
/**************************************************************************************************/
3636

3737
namespace stlab {
38-
39-
/**************************************************************************************************/
40-
41-
inline namespace v1 {
38+
inline namespace STLAB_VERSION_NAMESPACE() {
4239

4340
/**************************************************************************************************/
4441

@@ -170,8 +167,11 @@ struct main_executor_type {
170167

171168
constexpr auto main_executor = detail::main_executor_type{};
172169

173-
} // namespace v1
170+
/**************************************************************************************************/
174171

172+
} // namespace STLAB_VERSION_NAMESPACE()
175173
} // namespace stlab
176174

175+
/**************************************************************************************************/
176+
177177
#endif // STLAB_CONCURRENCY_MAIN_EXECUTOR_HPP

stlab/concurrency/ready_future.hpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef STLAB_CONCURRENCY_READY_FUTURE_HPP
1010
#define STLAB_CONCURRENCY_READY_FUTURE_HPP
1111

12+
#include <stlab/config.hpp>
13+
1214
#include <exception>
1315
#include <type_traits>
1416
#include <utility>
@@ -18,10 +20,7 @@
1820
/**************************************************************************************************/
1921

2022
namespace stlab {
21-
22-
/**************************************************************************************************/
23-
24-
inline namespace v1 {
23+
inline namespace STLAB_VERSION_NAMESPACE() {
2524

2625
/**************************************************************************************************/
2726

@@ -72,10 +71,9 @@ future<T> make_exceptional_future(std::exception_ptr error, E executor) {
7271

7372
/**************************************************************************************************/
7473

75-
} // namespace v1
74+
} // namespace STLAB_VERSION_NAMESPACE()
75+
} // namespace stlab
7676

7777
/**************************************************************************************************/
7878

79-
} // namespace stlab
80-
8179
#endif // STLAB_CONCURRENCY_READY_FUTURE_HPP

stlab/concurrency/serial_queue.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
/**************************************************************************************************/
1313

14+
#include <stlab/config.hpp>
15+
1416
#include <deque>
1517
#include <mutex>
1618
#include <tuple>
@@ -29,7 +31,7 @@
2931
/**************************************************************************************************/
3032

3133
namespace stlab {
32-
inline namespace v1 {
34+
inline namespace STLAB_VERSION_NAMESPACE() {
3335

3436
/**************************************************************************************************/
3537

@@ -164,7 +166,7 @@ class serial_queue_t {
164166

165167
/**************************************************************************************************/
166168

167-
} // namespace v1
169+
} // namespace STLAB_VERSION_NAMESPACE()
168170
} // namespace stlab
169171

170172
/**************************************************************************************************/

0 commit comments

Comments
 (0)