Made the lib work with -fno-exceptions (at least for now).

This commit is contained in:
2025-03-02 14:35:37 +01:00
parent 21b3b2c03a
commit ba23cb0c70
5 changed files with 50 additions and 12 deletions

View File

@@ -27,6 +27,18 @@
#include "../debug/stacktrace.hpp"
#endif
#if !defined(MIJIN_COROUTINE_ENABLE_EXCEPTION_HANDLING)
# define MIJIN_COROUTINE_ENABLE_EXCEPTION_HANDLING MIJIN_ENABLE_EXCEPTIONS
#elif !__cpp_exceptions
# error "Coroutine exception handling enabled, but exceptions are disabled."
#endif
#if !defined(MIJIN_COROUTINE_ENABLE_CANCEL)
# define MIJIN_COROUTINE_ENABLE_CANCEL MIJIN_ENABLE_EXCEPTIONS
#elif !__cpp_exceptions
# error "Cancelling tasks requires exceptions to be anbled."
#endif
namespace mijin
{
@@ -56,7 +68,9 @@ class TaskLoop;
template<typename TResult = void>
class TaskBase;
#if MIJIN_COROUTINE_ENABLE_CANCEL
struct TaskCancelled : std::exception {};
#endif
namespace impl
{
@@ -585,10 +599,12 @@ extern thread_local TaskLoop::StoredTask* gCurrentTask;
inline void throwIfCancelled()
{
#if MIJIN_COROUTINE_ENABLE_CANCEL
if (gCurrentTask->task->sharedState()->cancelled_)
{
throw TaskCancelled();
}
#endif
}
}
@@ -657,13 +673,16 @@ inline TaskStatus TaskLoop::tickTask(StoredTask& task)
while (status == TaskStatus::RUNNING);
impl::gCurrentTask = nullptr;
#if MIJIN_COROUTINE_ENABLE_EXCEPTION_HANDLING
if (task.task && task.task->exception())
{
try
{
std::rethrow_exception(task.task->exception());
}
#if MIJIN_COROUTINE_ENABLE_CANCEL
catch(TaskCancelled&) {} // ignore those
#endif
catch(...)
{
if (uncaughtExceptionHandler_)
@@ -679,6 +698,7 @@ inline TaskStatus TaskLoop::tickTask(StoredTask& task)
// TODO: handle the exception somehow, others may be waiting
return TaskStatus::FINISHED;
}
#endif // MIJIN_COROUTINE_ENABLE_EXCEPTION_HANDLING
if (status == TaskStatus::YIELDED || status == TaskStatus::FINISHED)
{
task.setFuture(task);