Skip to content

Commit 2a436c0

Browse files
author
KolKir
committed
Change thread and exception propagation to std
1 parent 29676d2 commit 2a436c0

10 files changed

Lines changed: 69 additions & 340 deletions

File tree

‎include/cpptask/Unix/thread.h‎

Lines changed: 0 additions & 142 deletions
This file was deleted.

‎include/cpptask/Win/thread.h‎

Lines changed: 0 additions & 147 deletions
This file was deleted.

‎include/cpptask/exception.h‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,7 @@ class Exception: public std::exception
6363
return *this;
6464
}
6565

66-
virtual Exception* Clone() const
67-
{
68-
return new Exception(*this);
69-
}
70-
71-
virtual void Throw() const
72-
{
73-
throw *this;
74-
}
75-
76-
virtual const char* what() const throw()
66+
virtual const char* what() const
7767
{
7868
return message.c_str();
7969
}

‎include/cpptask/parallelfor.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void ParallelForBase(RANGES ranges, Functor functor, TaskManager& manager)
117117
{
118118
if ((*it)->GetLastException() != 0)
119119
{
120-
(*it)->GetLastException()->Throw();
120+
std::rethrow_exception((*it)->GetLastException());
121121
}
122122
}
123123
}

‎include/cpptask/parallelinvoke.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ inline void ParallelInvoke(Functor1 func1, Functor2 func2)
7272

7373
if (task1.GetLastException() != 0)
7474
{
75-
task1.GetLastException()->Throw();
75+
std::rethrow_exception(task1.GetLastException());
7676
}
7777
if (task2.GetLastException() != 0)
7878
{
79-
task2.GetLastException()->Throw();
79+
std::rethrow_exception(task2.GetLastException());
8080
}
8181
}
8282
else

‎include/cpptask/parallelreduce.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class ReduceTask : public Task
101101
{
102102
if (tasks[i]->GetLastException() != 0)
103103
{
104-
tasks[i]->GetLastException()->Throw();
104+
std::rethrow_exception(tasks[i]->GetLastException());
105105
}
106106
};
107107

@@ -143,7 +143,7 @@ inline void ParallelReduce(Iterator start, Iterator end, Functor& functor, size_
143143
manager->WaitTask(*task);
144144
if (task->GetLastException() != 0)
145145
{
146-
task->GetLastException()->Throw();
146+
std::rethrow_exception(task->GetLastException());
147147
}
148148
}
149149
else

‎include/cpptask/task.h‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,15 @@ class alignas(_CPP_TASK_CACHE_LINE_SIZE_) Task
6868
{
6969
Execute();
7070
}
71-
catch(Exception& err)
72-
{
73-
ScopedLock<Mutex> lock(exceptionGuard);
74-
lastException.reset(err.Clone());
75-
}
7671
catch(...)
7772
{
78-
lastException.reset(new Exception("Unknown exception"));
73+
lastException = std::current_exception();
7974
}
8075
}
8176

82-
const Exception* GetLastException() const
77+
std::exception_ptr GetLastException() const
8378
{
84-
if (!lastException)
85-
{
86-
return 0;
87-
}
88-
return lastException.get();
79+
return lastException;
8980
}
9081

9182
bool CheckFinished()
@@ -125,7 +116,7 @@ class alignas(_CPP_TASK_CACHE_LINE_SIZE_) Task
125116
Task(const Task&) = delete;
126117
const Task& operator=(const Task&) = delete;
127118
private:
128-
std::unique_ptr<Exception> lastException;
119+
std::exception_ptr lastException;
129120
Mutex exceptionGuard;
130121
Event waitEvent;
131122
};

‎include/cpptask/taskthreadimpl.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ inline TaskThread::TaskThread(TaskThreadPool& threadPool, Semaphore& newTaskEven
4646
inline TaskThread::~TaskThread()
4747
{
4848
Stop();
49-
Wait();
49+
Join();
5050
}
5151

5252
inline void TaskThread::Run()

0 commit comments

Comments
 (0)