Skip to content

Commit

Permalink
Merge pull request #289 from stlab/develop
Browse files Browse the repository at this point in the history
Prepare for release
  • Loading branch information
FelixPetriconi authored Oct 29, 2019
2 parents be6928a + 8ce4ac4 commit bd0f6ac
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 132 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@ First, you will need the following tools:
`conan` and `cmake` are available on the Mac via [Homebrew](http://brew.sh). `cmake` is available on Windows via [`scoop`](http://scoop.sh/).

Once they're set up, run either `setup_xcode.sh` or `setup_msvc.bat` for the platform of your choice. It will setup all necessary library dependencies and create the platform-specific project file in the `./build/` directory.

*Microsoft Windows Platform Build Notes*:
- If you are using `conan` for the first time, add `--build missing` to conan command call in `setup_msvc.bat` script
- Use administrator command prompt if you get issues in manifest creation during `setup_msvc.bat` run (ex: `mt : general error c101008d`)

# Upcomming Changes in Version 2
* Currently we are redesigning the interface of the `future` class. We will make the associated executor of a task more explicit by removing the implicit "inheritance" of the executors from the previous future. So a continuation will not get automatically the same executor from its predecessor. If non is provided, then it will be automatically be executed via the `immediate_executor`.
* As well we will remove all `.then()` and `.recover()` functions from the `future` interface. Only the `operator|()` and `operator^()` will remain. So the pipe notation, as it is comming with C++20 ranges, will become the only choice. Obviously this will be a breaking change.
* In parallel we think about changing the then former `recover()` function signature, see issue [#263](https://github.com/stlab/libraries/issues/263).
97 changes: 50 additions & 47 deletions stlab/concurrency/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,81 +12,84 @@
/**************************************************************************************************/

#define STLAB_FEATURE_PRIVATE_OBJC_ARC() 0
#define STLAB_FEATURE_PRIVATE_COROUTINES() 0

#define STLAB_FEATURE(X) (STLAB_FEATURE_PRIVATE_##X())

// __has_feature is a clang specific extension, gcc does not know it
#ifndef __has_feature // Optional.
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
#endif

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

#define STLAB_TASK_SYSTEM_PORTABLE() 0
#define STLAB_TASK_SYSTEM_LIBDISPATCH() 1
#define STLAB_TASK_SYSTEM_EMSCRIPTEN() 2
#define STLAB_TASK_SYSTEM_PNACL() 3
#define STLAB_TASK_SYSTEM_WINDOWS() 4
#define STLAB_TASK_SYSTEM_PRIVATE_PORTABLE() 0
#define STLAB_TASK_SYSTEM_PRIVATE_LIBDISPATCH() 0
#define STLAB_TASK_SYSTEM_PRIVATE_EMSCRIPTEN() 0
#define STLAB_TASK_SYSTEM_PRIVATE_PNACL() 0
#define STLAB_TASK_SYSTEM_PRIVATE_WINDOWS() 0

#if __APPLE__
#define STLAB_TASK_SYSTEM(X) (STLAB_TASK_SYSTEM_PRIVATE_##X())

#ifndef STLAB_TASK_SYSTEM
#define STLAB_TASK_SYSTEM() STLAB_TASK_SYSTEM_LIBDISPATCH()
#define STLAB_CPP_VERSION(X) (STLAB_CPP_VERSION_PRIVATE() == (X))
#define STLAB_CPP_VERSION_LESS_THAN(X) (STLAB_CPP_VERSION_PRIVATE() < (X))
#define STLAB_CPP_VERSION_AT_LEAST(X) (STLAB_CPP_VERSION_PRIVATE() >= (X))

#if __cplusplus >= 201703L
#define STLAB_CPP_VERSION() 17
#endif
#if __APPLE__

#endif
#undef STLAB_TASK_SYSTEM_PRIVATE_LIBDISPATCH
#define STLAB_TASK_SYSTEM_PRIVATE_LIBDISPATCH() 1

#if __has_feature(objc_arc)
#undef STLAB_FEATURE_PRIVATE_OBJC_ARC
#define STLAB_FEATURE_PRIVATE_OBJC_ARC() 1
#endif
#if defined(__has_feature)
#if __has_feature(objc_arc)
#undef STLAB_FEATURE_PRIVATE_OBJC_ARC
#define STLAB_FEATURE_PRIVATE_OBJC_ARC() 1
#endif
#endif

#elif __EMSCRIPTEN__

#ifndef STLAB_TASK_SYSTEM
#define STLAB_TASK_SYSTEM() STLAB_TASK_SYSTEM_EMSCRIPTEN()
#endif
#undef STLAB_TASK_SYSTEM_PRIVATE_EMSCRIPTEN
#define STLAB_TASK_SYSTEM_PRIVATE_EMSCRIPTEN() 1

#elif __pnacl__

#ifndef STLAB_TASK_SYSTEM
#define STLAB_TASK_SYSTEM() STLAB_TASK_SYSTEM_PNACL()
#endif
#undef STLAB_TASK_SYSTEM_PRIVATE_PNACL
#define STLAB_TASK_SYSTEM_PRIVATE_PNACL() 1

#elif _MSC_VER

#ifndef STLAB_TASK_SYSTEM
#define STLAB_TASK_SYSTEM() STLAB_TASK_SYSTEM_WINDOWS()
#endif

#if _MSC_FULL_VER >= 191225830 && _MSVC_LANG >= 201403L
#define STLAB_CPP_VERSION() 17
#endif
#undef STLAB_TASK_SYSTEM_PRIVATE_WINDOWS
#define STLAB_TASK_SYSTEM_PRIVATE_WINDOWS() 1

#endif
#if _MSVC_LANG == 201103L
#define STLAB_CPP_VERSION_PRIVATE() 11
#elif _MSVC_LANG == 201402L
#define STLAB_CPP_VERSION_PRIVATE() 14
#elif _MSC_FULL_VER >= 191225830 && _MSVC_LANG == 201703L
#define STLAB_CPP_VERSION_PRIVATE() 17
#else
#warning Unknown version of C+; assuming C++20.
#define STLAB_CPP_VERSION_PRIVATE() 20
#endif

// Default configuration
#else

#ifndef STLAB_TASK_SYSTEM
#define STLAB_TASK_SYSTEM() STLAB_TASK_SYSTEM_PORTABLE()
#if __cplusplus >= 201703L
#define STLAB_CPP_VERSION() 17
#endif
#endif
#undef STLAB_TASK_SYSTEM_PRIVATE_PORTABLE
#define STLAB_TASK_SYSTEM_PRIVATE_PORTABLE() 1

#ifndef STLAB_CPP_VERSION
#define STLAB_CPP_VERSION() 17
#endif

#ifndef STLAB_FUTURE_COROUTINES
#define STLAB_FUTURE_COROUTINES 0
#if !defined(STLAB_CPP_VERSION_PRIVATE)
#if __cplusplus == 201103L
#define STLAB_CPP_VERSION_PRIVATE() 11
#elif __cplusplus == 201402L
#define STLAB_CPP_VERSION_PRIVATE() 14
#elif __cplusplus == 201703L
#define STLAB_CPP_VERSION_PRIVATE() 17
#else
#warning Unknown version of C+; assuming C++20.
#define STLAB_CPP_VERSION_PRIVATE() 20
#endif
#endif

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

#endif
#endif // STLAB_CONCURRENCY_CONFIG_HPP

/**************************************************************************************************/
36 changes: 22 additions & 14 deletions stlab/concurrency/default_executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@
#include <chrono>
#include <functional>

#if STLAB_TASK_SYSTEM () == STLAB_TASK_SYSTEM_LIBDISPATCH()
#if STLAB_TASK_SYSTEM(LIBDISPATCH)
#include <dispatch/dispatch.h>
#elif STLAB_TASK_SYSTEM() == STLAB_TASK_SYSTEM_EMSCRIPTEN()
#elif STLAB_TASK_SYSTEM(EMSCRIPTEN)
#include <emscripten.h>
#elif STLAB_TASK_SYSTEM() == STLAB_TASK_SYSTEM_PNACL()
#elif STLAB_TASK_SYSTEM(PNACL)
#include <ppapi/cpp/completion_callback.h>
#include <ppapi/cpp/core.h>
#include <ppapi/cpp/module.h>
#elif STLAB_TASK_SYSTEM() == STLAB_TASK_SYSTEM_WINDOWS()
#elif STLAB_TASK_SYSTEM(WINDOWS)
#include <Windows.h>
#include <memory>
#elif STLAB_TASK_SYSTEM() == STLAB_TASK_SYSTEM_PORTABLE()
#elif STLAB_TASK_SYSTEM(PORTABLE)

#include <array>
#include <algorithm>
#include <atomic>
Expand All @@ -51,6 +52,7 @@ namespace stlab {
/**************************************************************************************************/

inline namespace v1 {

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

namespace detail {
Expand All @@ -66,7 +68,7 @@ enum class executor_priority

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

#if STLAB_TASK_SYSTEM() == STLAB_TASK_SYSTEM_LIBDISPATCH()
#if STLAB_TASK_SYSTEM(LIBDISPATCH)

constexpr auto platform_priority(executor_priority p)
{
Expand Down Expand Up @@ -117,7 +119,9 @@ struct executor_type {
}
};

#elif STLAB_TASK_SYSTEM() == STLAB_TASK_SYSTEM_EMSCRIPTEN()
/**************************************************************************************************/

#elif STLAB_TASK_SYSTEM(EMSCRIPTEN)

template <executor_priority P = executor_priority::medium>
struct executor_type {
Expand All @@ -138,7 +142,9 @@ struct executor_type {
}
};

#elif STLAB_TASK_SYSTEM() == STLAB_TASK_SYSTEM_PNACL()
/**************************************************************************************************/

#elif STLAB_TASK_SYSTEM(PNACL)

template <executor_priority P = executor_priority::medium>
struct executor_type {
Expand All @@ -160,7 +166,9 @@ struct executor_type {
}
};

#elif STLAB_TASK_SYSTEM() == STLAB_TASK_SYSTEM_WINDOWS()
/**************************************************************************************************/

#elif STLAB_TASK_SYSTEM(WINDOWS)

constexpr auto platform_priority(executor_priority p)
{
Expand Down Expand Up @@ -230,10 +238,8 @@ class task_system {
};

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

#elif STLAB_TASK_SYSTEM() == STLAB_TASK_SYSTEM_PORTABLE()

#elif STLAB_TASK_SYSTEM(PORTABLE)

class notification_queue {
using lock_t = std::unique_lock<std::mutex>;
Expand Down Expand Up @@ -385,8 +391,9 @@ struct task_system

#endif

#if (STLAB_TASK_SYSTEM() == STLAB_TASK_SYSTEM_PORTABLE()) || \
(STLAB_TASK_SYSTEM() == STLAB_TASK_SYSTEM_WINDOWS())
/**************************************************************************************************/

#if STLAB_TASK_SYSTEM(WINDOWS) || STLAB_TASK_SYSTEM(PORTABLE)

template <executor_priority P = executor_priority::medium>
struct executor_type {
Expand Down Expand Up @@ -422,3 +429,4 @@ constexpr auto high_executor = detail::executor_type<detail::executor_priority::

#endif // STLAB_CONCURRENCY_DEFAULT_EXECUTOR_HPP

/**************************************************************************************************/
79 changes: 50 additions & 29 deletions stlab/concurrency/optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,85 @@

#include <stlab/concurrency/config.hpp>

#define STLAB_STD_OPTIONAL() 1
#define STLAB_STD_EXPERIMENTAL_OPTIONAL() 2
#define STLAB_BOOST_OPTIONAL() 3
/**************************************************************************************************/

// The library can be used with boost::optinal, std::experimental::optional or std::optional.
// Without any additional define, it uses the versions from the standard, if it is available.
//
// If using of boost::optional shall be enforced, set the define STLAB_FORCE_BOOST_OPTIONAL
#define STLAB_OPTIONAL_PRIVATE_STD() 0
#define STLAB_OPTIONAL_PRIVATE_STD_EXPERIMENTAL() 1
#define STLAB_OPTIONAL_PRIVATE_BOOST() 2

#ifdef STLAB_FORCE_BOOST_OPTIONAL
#include <boost/optional.hpp>
#define STLAB_OPTIONAL() STLAB_BOOST_OPTIONAL()
#endif
/**************************************************************************************************/

#ifndef STLAB_OPTIONAL
#ifdef __has_include // Check if __has_include is present
#if __has_include(<optional>) && STLAB_CPP_VERSION() == 17 // Check for a standard library
#include <optional>
#define STLAB_OPTIONAL STLAB_STD_OPTIONAL
#elif __has_include(<experimental/optional>) // Check for an experimental version
#include <experimental/optional>
#define STLAB_OPTIONAL() STLAB_STD_EXPERIMENTAL_OPTIONAL()
#endif
#endif
#if defined(STLAB_FORCE_BOOST_OPTIONAL)
#define STLAB_OPTIONAL_PRIVATE_SELECTION() STLAB_OPTIONAL_PRIVATE_BOOST()
#elif defined(__has_include) // Check if __has_include is present
#if __has_include(<optional>) && STLAB_CPP_VERSION_AT_LEAST(17)
#include <optional>
#define STLAB_OPTIONAL_PRIVATE_SELECTION() STLAB_OPTIONAL_PRIVATE_STD()
#elif __has_include(<experimental/optional>)
#include <experimental/optional>
#define STLAB_OPTIONAL_PRIVATE_SELECTION() STLAB_OPTIONAL_PRIVATE_STD_EXPERIMENTAL()
#endif
#else
#define STLAB_OPTIONAL_PRIVATE_SELECTION() STLAB_OPTIONAL_PRIVATE_BOOST()
#endif

#ifndef STLAB_OPTIONAL
#include <boost/optional.hpp>
#define STLAB_OPTIONAL() STLAB_BOOST_OPTIONAL()
#define STLAB_OPTIONAL(X) (STLAB_OPTIONAL_PRIVATE_SELECTION() == STLAB_OPTIONAL_PRIVATE_##X())

/**************************************************************************************************/
// The library can be used with boost::optional, std::experimental::optional or std::optional.
// Without any additional define, it uses the versions from the standard, if it is available.
//
// If using of boost::optional shall be enforced, define STLAB_FORCE_BOOST_OPTIONAL.

#if STLAB_OPTIONAL(BOOST)
#include <boost/optional.hpp>
#endif

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

namespace stlab {

#if STLAB_OPTIONAL() == STLAB_STD_OPTIONAL()
/**************************************************************************************************/

#if STLAB_OPTIONAL(STD)

template <typename T>
using optional = std::optional<T>;

constexpr std::nullopt_t nullopt{std::nullopt};

#elif STLAB_OPTIONAL() == STLAB_STD_EXPERIMENTAL_OPTIONAL()
/**************************************************************************************************/

#elif STLAB_OPTIONAL(STD_EXPERIMENTAL)

template <typename T>
using optional = std::experimental::optional<T>;

constexpr std::experimental::nullopt_t nullopt{std::experimental::nullopt};

#elif STLAB_OPTIONAL() == STLAB_BOOST_OPTIONAL()
/**************************************************************************************************/

#elif STLAB_OPTIONAL(BOOST)

template <typename T>
using optional = boost::optional<T>;

const boost::none_t nullopt((boost::none_t::init_tag()));

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

#else
#error "No optional!"

#error `optional` variant not specified

#endif

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

} // namespace stlab

#endif
/**************************************************************************************************/

#endif

/**************************************************************************************************/
Loading

0 comments on commit bd0f6ac

Please sign in to comment.