Skip to content

Commit

Permalink
namespace version bump (#541)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sean-parent authored Mar 15, 2024
1 parent 3409d0e commit 2f4037b
Show file tree
Hide file tree
Showing 31 changed files with 405 additions and 462 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ cmake -S . -B ../BUILD -GNinja -DCMAKE_CXX_STANDARD=17 -DCMAKE_BUILD_TYPE=Releas
If you organize the build directory into subdirectories you can support multiple configurations.

```
rm -rf ../builds/portable
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
```

Expand Down
15 changes: 5 additions & 10 deletions stlab/concurrency/await.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
/**************************************************************************************************/

namespace stlab {

/**************************************************************************************************/

inline namespace v1 {
inline namespace STLAB_VERSION_NAMESPACE() {

/**************************************************************************************************/

Expand Down Expand Up @@ -203,18 +200,16 @@ template <class T>
}

template <class T>
[[deprecated("Use await_for instead.")]] auto blocking_get(future<T> x,
const std::chrono::nanoseconds& timeout)
-> decltype(x.get_try()) {
[[deprecated("Use await_for instead.")]] auto blocking_get(
future<T> x, const std::chrono::nanoseconds& timeout) -> decltype(x.get_try()) {
return blocking_get_for(std::move(x), timeout).get_try();
}

/**************************************************************************************************/

} // namespace v1
} // namespace STLAB_VERSION_NAMESPACE()
} // namespace stlab

/**************************************************************************************************/

} // namespace stlab

#endif // STLAB_CONCURRENCY_AWAIT_HPP
26 changes: 11 additions & 15 deletions stlab/concurrency/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef STLAB_CONCURRENCY_CHANNEL_HPP
#define STLAB_CONCURRENCY_CHANNEL_HPP

#include <stlab/config.hpp>

#include <algorithm>
#include <array>
#include <atomic>
Expand All @@ -33,10 +35,7 @@
/**************************************************************************************************/

namespace stlab {

/**************************************************************************************************/

inline namespace v1 {
inline namespace STLAB_VERSION_NAMESPACE() {

/**************************************************************************************************/

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

template <typename F, std::size_t... I, typename... T>
auto invoke_(F&& f, std::tuple<std::variant<T, std::exception_ptr>...>& t, std::index_sequence<I...>) {
auto invoke_(F&& f,
std::tuple<std::variant<T, std::exception_ptr>...>& t,
std::index_sequence<I...>) {
return std::forward<F>(f)(std::move(std::get<I>(t))...);
}

Expand Down Expand Up @@ -484,14 +485,12 @@ struct round_robin_queue_strategy {
queue_t _queue;

bool empty() const {
return get_i(
_queue, _index, [](const auto& c) { return c.empty(); }, true);
return get_i(_queue, _index, [](const auto& c) { return c.empty(); }, true);
}

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

void pop_front() {
Expand Down Expand Up @@ -546,8 +545,8 @@ struct unordered_queue_strategy {
auto front() {
assert(!empty() && "front on an empty container is a very bad idea!");
_index = tuple_find(_queue, [](const auto& c) { return !c.empty(); });
return std::make_tuple(get_i(
_queue, _index, [](auto& c) { return std::move(c.front()); }, item_t{}));
return std::make_tuple(
get_i(_queue, _index, [](auto& c) { return std::move(c.front()); }, item_t{}));
}

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

/**************************************************************************************************/

} // namespace v1

/**************************************************************************************************/

} // namespace STLAB_VERSION_NAMESPACE()
} // namespace stlab

/**************************************************************************************************/
Expand Down
10 changes: 2 additions & 8 deletions stlab/concurrency/default_executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@
/**************************************************************************************************/

namespace stlab {

/**************************************************************************************************/

inline namespace v1 {
inline namespace STLAB_VERSION_NAMESPACE() {

/**************************************************************************************************/

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

/**************************************************************************************************/

} // namespace v1

/**************************************************************************************************/

} // namespace STLAB_VERSION_NAMESPACE()
} // namespace stlab

/**************************************************************************************************/
Expand Down
11 changes: 4 additions & 7 deletions stlab/concurrency/executor_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef STLAB_CONCURRENCY_EXECUTOR_BASE_HPP
#define STLAB_CONCURRENCY_EXECUTOR_BASE_HPP

#include <stlab/config.hpp>

#include <chrono>
#include <functional>

Expand All @@ -18,12 +20,10 @@
/**************************************************************************************************/

namespace stlab {
inline namespace STLAB_VERSION_NAMESPACE() {

/**************************************************************************************************/

inline namespace v1 {
/**************************************************************************************************/

using executor_t = std::function<void(stlab::task<void() noexcept>)>;

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

/**************************************************************************************************/

} // namespace v1

/**************************************************************************************************/

} // namespace STLAB_VERSION_NAMESPACE()
} // namespace stlab

/**************************************************************************************************/
Expand Down
36 changes: 18 additions & 18 deletions stlab/concurrency/future.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@
/**************************************************************************************************/

namespace stlab {

/**************************************************************************************************/

inline namespace v1 {
inline namespace STLAB_VERSION_NAMESPACE() {

/**************************************************************************************************/

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

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

void reset() { _then.clear(); } // NEEDS MUTEX

template <typename F>
auto recover(future<T>&& p, F&& f) {
return recover(std::move(p), _executor, std::forward<F>(f));
Expand Down Expand Up @@ -389,8 +384,6 @@ struct shared_base<T, enable_if_not_copyable<T>> : std::enable_shared_from_this<

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

void reset() { _then.second = task<void() noexcept>{}; }

template <typename F>
auto recover(future<T>&& p, F&& f) {
return recover(std::move(p), _executor, std::forward<F>(f));
Expand Down Expand Up @@ -474,8 +467,6 @@ struct shared_base<void> : std::enable_shared_from_this<shared_base<void>> {

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

void reset() { _then.clear(); }

template <typename F>
auto recover(future<result_type>&& p, F&& f) {
return recover(std::move(p), _executor, std::forward<F>(f));
Expand Down Expand Up @@ -750,7 +741,11 @@ class STLAB_NODISCARD() future<T, enable_if_copyable<T>> {
return _p->_exception ? std::optional<std::exception_ptr>{_p->_exception} : std::nullopt;
}

std::exception_ptr exception() const& { return _p->_exception; }
// Precondition: is_ready()
std::exception_ptr exception() const& {
assert(is_ready());
return _p->_exception;
}
};

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

std::exception_ptr exception() const& { return _p->_exception; }
// Precondition: is_ready()
std::exception_ptr exception() const& {
assert(is_ready());
return _p->_exception;
}
};

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

std::exception_ptr exception() const& { return _p->_exception; }
// Precondition: is_ready()
std::exception_ptr exception() const& {
assert(is_ready());
return _p->_exception;
}
};

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

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

/**************************************************************************************************/

} // namespace v1

/**************************************************************************************************/

} // namespace STLAB_VERSION_NAMESPACE()
} // namespace stlab

/**************************************************************************************************/
Expand Down
11 changes: 4 additions & 7 deletions stlab/concurrency/immediate_executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
#ifndef STLAB_CONCURRENCY_IMMEDIATE_EXECUTOR_HPP
#define STLAB_CONCURRENCY_IMMEDIATE_EXECUTOR_HPP

#include <stlab/config.hpp>

#include <type_traits>

/**************************************************************************************************/

namespace stlab {
inline namespace STLAB_VERSION_NAMESPACE() {

/**************************************************************************************************/

inline namespace v1 {
/**************************************************************************************************/

namespace detail {

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

/**************************************************************************************************/

} // namespace v1

/**************************************************************************************************/

} // namespace STLAB_VERSION_NAMESPACE()
} // namespace stlab

/**************************************************************************************************/
Expand Down
10 changes: 5 additions & 5 deletions stlab/concurrency/main_executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@
/**************************************************************************************************/

namespace stlab {

/**************************************************************************************************/

inline namespace v1 {
inline namespace STLAB_VERSION_NAMESPACE() {

/**************************************************************************************************/

Expand Down Expand Up @@ -170,8 +167,11 @@ struct main_executor_type {

constexpr auto main_executor = detail::main_executor_type{};

} // namespace v1
/**************************************************************************************************/

} // namespace STLAB_VERSION_NAMESPACE()
} // namespace stlab

/**************************************************************************************************/

#endif // STLAB_CONCURRENCY_MAIN_EXECUTOR_HPP
12 changes: 5 additions & 7 deletions stlab/concurrency/ready_future.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef STLAB_CONCURRENCY_READY_FUTURE_HPP
#define STLAB_CONCURRENCY_READY_FUTURE_HPP

#include <stlab/config.hpp>

#include <exception>
#include <type_traits>
#include <utility>
Expand All @@ -18,10 +20,7 @@
/**************************************************************************************************/

namespace stlab {

/**************************************************************************************************/

inline namespace v1 {
inline namespace STLAB_VERSION_NAMESPACE() {

/**************************************************************************************************/

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

/**************************************************************************************************/

} // namespace v1
} // namespace STLAB_VERSION_NAMESPACE()
} // namespace stlab

/**************************************************************************************************/

} // namespace stlab

#endif // STLAB_CONCURRENCY_READY_FUTURE_HPP
6 changes: 4 additions & 2 deletions stlab/concurrency/serial_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

/**************************************************************************************************/

#include <stlab/config.hpp>

#include <deque>
#include <mutex>
#include <tuple>
Expand All @@ -29,7 +31,7 @@
/**************************************************************************************************/

namespace stlab {
inline namespace v1 {
inline namespace STLAB_VERSION_NAMESPACE() {

/**************************************************************************************************/

Expand Down Expand Up @@ -164,7 +166,7 @@ class serial_queue_t {

/**************************************************************************************************/

} // namespace v1
} // namespace STLAB_VERSION_NAMESPACE()
} // namespace stlab

/**************************************************************************************************/
Expand Down
Loading

0 comments on commit 2f4037b

Please sign in to comment.