Skip to content

Commit

Permalink
Revert "Add -fno-exceptions support (#53)"
Browse files Browse the repository at this point in the history
This reverts commit 8ba714a.
  • Loading branch information
alxvasilev committed Sep 10, 2019
1 parent 8ba714a commit 55a5e49
Show file tree
Hide file tree
Showing 7 changed files with 841 additions and 933 deletions.
8 changes: 3 additions & 5 deletions mingw.condition_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

#include "mingw.mutex.h"
#include "mingw.shared_mutex.h"
#include "mingw.throw.h"

#if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0501)
#error To use the MinGW-std-threads library, you will need to define the macro _WIN32_WINNT to be 0x0501 (Windows XP) or higher.
Expand Down Expand Up @@ -79,12 +78,12 @@ class condition_variable_any
: mSemaphore(CreateSemaphoreA(NULL, 0, 0xFFFF, NULL))
{
if (mSemaphore == NULL)
throw_error<std::system_error>(GetLastError(), std::generic_category());
throw std::system_error(GetLastError(), std::generic_category());
mWakeEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (mWakeEvent == NULL)
{
CloseHandle(mSemaphore);
throw_error<std::system_error>(GetLastError(), std::generic_category());
throw std::system_error(GetLastError(), std::generic_category());
}
}
~condition_variable_any()
Expand Down Expand Up @@ -124,9 +123,8 @@ class condition_variable_any
else
{
using namespace std;
throw_error<std::system_error>(make_error_code(errc::protocol_error));
throw system_error(make_error_code(errc::protocol_error));
}
return false;
}
public:
template <class M>
Expand Down
38 changes: 9 additions & 29 deletions mingw.future.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
// Mutexes and condition variables are used explicitly.
#include "mingw.mutex.h"
#include "mingw.condition_variable.h"
#include "mingw.throw.h"

#include <synchapi.h>
#include <handleapi.h>
Expand Down Expand Up @@ -178,7 +177,7 @@ struct FutureBase : public FutureStatic<true>
{
#if !defined(NDEBUG)
if (!valid())
throw_error<future_error>(future_errc::no_state);
throw future_error(future_errc::no_state);
#endif
// If there's already a value or exception, don't do any extraneous
// synchronization. The `get()` method will do that for us.
Expand All @@ -194,7 +193,7 @@ struct FutureBase : public FutureStatic<true>
{
#if !defined(NDEBUG)
if (!valid())
throw_error<future_error>(future_errc::no_state);
throw future_error(future_errc::no_state);
#endif
auto current_state = mState->mType.load(std::memory_order_relaxed);
if (current_state & kReadyFlag)
Expand Down Expand Up @@ -469,9 +468,9 @@ class promise : mingw_stdthread::detail::FutureBase
void check_before_set (void) const
{
if (!valid())
mingw_stdthread::throw_error<future_error>(future_errc::no_state);
throw future_error(future_errc::no_state);
if (mState->mType.load(std::memory_order_relaxed) & kSetFlag)
mingw_stdthread::throw_error<future_error>(future_errc::promise_already_satisfied);
throw future_error(future_errc::promise_already_satisfied);
}

void check_abandon (void)
Expand All @@ -496,13 +495,11 @@ class promise : mingw_stdthread::detail::FutureBase
FALSE, // No need for this to be inherited.
DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
if (!success)
mingw_stdthread::throw_error<std::runtime_error>("MinGW STD Threads library failed to make a promise ready after thread exit.");
throw std::runtime_error("MinGW STD Threads library failed to make a promise ready after thread exit.");

mState->increment_references();
bool handle_handled = false;
#if !MINGW_STDTHREAD_NO_EXCEPTIONS
try {
#endif
state_type * ptr = static_cast<state_type *>(mState);
mingw_stdthread::thread watcher_thread ([ptr, thread_handle, &handle_handled](void)
{
Expand Down Expand Up @@ -531,27 +528,24 @@ class promise : mingw_stdthread::detail::FutureBase
});
}
watcher_thread.detach();
#if !MINGW_STDTHREAD_NO_EXCEPTIONS
}
catch (...)
{
// Because the original promise is still alive, this can't be the decrement
// that destroys it.
// destroys it.
mState->decrement_references();
if (!handle_handled)
CloseHandle(thread_handle);
mingw_stdthread::throw_error<std::runtime_error>("MinGW STD Threads library failed to make a promise ready after thread exit.");
}
#endif
}

template<class U>
future<U> make_future (void)
{
if (!valid())
mingw_stdthread::throw_error<future_error>(future_errc::no_state);
throw future_error(future_errc::no_state);
if (mRetrieved)
mingw_stdthread::throw_error<future_error>(future_errc::future_already_retrieved);
throw future_error(future_errc::future_already_retrieved);
mState->increment_references();
mRetrieved = true;
return future<U>(static_cast<state_type *>(mState));
Expand Down Expand Up @@ -935,15 +929,11 @@ struct StorageHelper
template<class Func, class ... Args>
static void store_deferred (FutureState<Ret> * state_ptr, Func && func, Args&&... args)
{
#if MINGW_STDTHREAD_NO_EXCEPTIONS
state_ptr->set_value(invoke(std::forward<Func>(func), std::forward<Args>(args)...));
#else
try {
state_ptr->set_value(invoke(std::forward<Func>(func), std::forward<Args>(args)...));
} catch (...) {
state_ptr->set_exception(std::current_exception());
}
#endif
}
template<class Func, class ... Args>
static void store (FutureState<Ret> * state_ptr, Func && func, Args&&... args)
Expand All @@ -962,18 +952,13 @@ struct StorageHelper<Ref&>
template<class Func, class ... Args>
static void store_deferred (FutureState<void*> * state_ptr, Func && func, Args&&... args)
{
using Ref_non_cv = typename std::remove_cv<Ref>::type;
#if MINGW_STDTHREAD_NO_EXCEPTIONS
Ref & rf = invoke(std::forward<Func>(func), std::forward<Args>(args)...);
state_ptr->set_value(const_cast<Ref_non_cv *>(std::addressof(rf)));
#else
try {
typedef typename std::remove_cv<Ref>::type Ref_non_cv;
Ref & rf = invoke(std::forward<Func>(func), std::forward<Args>(args)...);
state_ptr->set_value(const_cast<Ref_non_cv *>(std::addressof(rf)));
} catch (...) {
state_ptr->set_exception(std::current_exception());
}
#endif
}
template<class Func, class ... Args>
static void store (FutureState<void*> * state_ptr, Func && func, Args&&... args)
Expand All @@ -992,17 +977,12 @@ struct StorageHelper<void>
template<class Func, class ... Args>
static void store_deferred (FutureState<Empty> * state_ptr, Func && func, Args&&... args)
{
#if MINGW_STDTHREAD_NO_EXCEPTIONS
invoke(std::forward<Func>(func), std::forward<Args>(args)...);
state_ptr->set_value(Empty{});
#else
try {
invoke(std::forward<Func>(func), std::forward<Args>(args)...);
state_ptr->set_value(Empty{});
} catch (...) {
state_ptr->set_exception(std::current_exception());
}
#endif
}
template<class Func, class ... Args>
static void store (FutureState<Empty> * state_ptr, Func && func, Args&&... args)
Expand Down
Loading

0 comments on commit 55a5e49

Please sign in to comment.