Skip to content

Commit

Permalink
Merge pull request #140 from uPiscium/develop
Browse files Browse the repository at this point in the history
develop
  • Loading branch information
uPiscium authored Sep 6, 2024
2 parents a647993 + 5d057fc commit f7a2b06
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions includes/deps/TerreateCore/bitflag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ template <enumtype T> class BitFlag {
}
Bool operator!=(Flag const &flag) const { return mFlag != flag; }

operator T() const { return static_cast<T>(mFlag); }
operator Flag() const { return mFlag; }
explicit operator T() const { return static_cast<T>(mFlag); }
explicit operator Flag() const { return mFlag; }
operator Bool() const { return mFlag != static_cast<Flag>(0); }
};

Expand Down
1 change: 1 addition & 0 deletions includes/deps/TerreateCore/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ template <typename T> using Function = std::function<T>;
typedef std::mutex Mutex;
typedef std::condition_variable ConditionVariable;
typedef std::thread Thread;
typedef std::exception_ptr ExceptionPtr;

template <typename T, typename Container = std::deque<T>>
using Queue = std::queue<T, Container>;
Expand Down
13 changes: 9 additions & 4 deletions includes/deps/TerreateCore/executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class TaskHandle : public Core::TerreateObjectBase {
TaskHandle(SharedFuture<void> const &future) : mFuture(future) {}
~TaskHandle() override {}

SharedFuture<void> const &GetFuture() const { return mFuture; }
Uint const &GetExecutionIndex() const { return mExecutionIndex; }

void SetExecutionIndex(Uint const &index) { mExecutionIndex = index; }
Expand All @@ -36,11 +37,10 @@ class Task : public Core::TerreateObjectBase {

public:
Task() {}
Task(Function<void()> const &target) : mTarget(target) {
mHandle = new TaskHandle(mTarget.get_future().share());
}
Task(Function<void()> const &target);
Task(Task &&other) noexcept
: mTarget(std::move(other.mTarget)),
: Core::TerreateObjectBase(std::move(other)),
mTarget(std::move(other.mTarget)),
mDependencies(std::move(other.mDependencies)), mHandle(other.mHandle) {
other.mHandle = nullptr;
}
Expand All @@ -58,6 +58,9 @@ class Task : public Core::TerreateObjectBase {

class Executor : public Core::TerreateObjectBase {
private:
Vec<ExceptionPtr> mExceptions;
Mutex mExceptionMutex;

Queue<Task> mTaskQueue;
Mutex mQueueMutex;

Expand All @@ -76,6 +79,8 @@ class Executor : public Core::TerreateObjectBase {
Uint const &numWorkers = std::thread::hardware_concurrency());
~Executor() override;

Vec<ExceptionPtr> const &GetExceptions() const { return mExceptions; }

void Schedule(Task &&task);

void WaitForAll() const { mComplete.wait(false); }
Expand Down
6 changes: 4 additions & 2 deletions includes/deps/TerreateCore/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ class TerreateObjectBase {
TerreateObjectBase() : mUUID() {}
TerreateObjectBase(UUID const &uuid) : mUUID(uuid) {}
TerreateObjectBase(TerreateObjectBase const &other) : mUUID(other.mUUID) {}
TerreateObjectBase(TerreateObjectBase &&other) noexcept
: mUUID(std::move(other.mUUID)) {}
virtual ~TerreateObjectBase() {}

UUID const &GetUUID() const { return mUUID; }
UUID const &GetUUID() const noexcept { return mUUID; }

virtual bool operator==(TerreateObjectBase const &other) const {
return mUUID == other.mUUID;
Expand All @@ -37,7 +39,7 @@ class TerreateObjectBase {
}

virtual TerreateObjectBase &operator=(TerreateObjectBase const &other);
virtual TerreateObjectBase &operator=(TerreateObjectBase &&other);
virtual TerreateObjectBase &operator=(TerreateObjectBase &&other) noexcept;

virtual operator Str() const { return mUUID.ToString(); }
virtual operator Byte const *() const { return mUUID.Raw(); }
Expand Down
5 changes: 3 additions & 2 deletions includes/deps/TerreateCore/uuid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ class UUID {
UUID(Str const &uuid) { std::memcpy(mUUID, uuid.c_str(), sizeof(char) * 16); }

public:
UUID() { GenerateUUID(); }
UUID(const UUID &other) {
UUID() { this->GenerateUUID(); }
UUID(UUID const &other) {
std::memcpy(mUUID, other.mUUID, sizeof(char) * 16);
}
UUID(UUID &&other) { std::memcpy(mUUID, other.mUUID, sizeof(char) * 16); }

Byte const *Raw() const { return mUUID; }

Expand Down

0 comments on commit f7a2b06

Please sign in to comment.