15#include "AUI/Common/ADeque.h"
17#include "AUI/Common/SharedPtrTypes.h"
18#include "AUI/Common/AString.h"
19#include "AUI/Util/AMessageQueue.h"
20#include <AUI/Platform/AStacktrace.h>
32class API_AUI_CORE AAbstractThread
34 friend class IEventLoop;
36 friend class AConditionVariable;
37 friend void setupUIThread()
noexcept;
43 typedef std::thread::id
id;
57 void enqueue(AMessageQueue<>::Message f);
59 virtual ~AAbstractThread();
84 return mCurrentEventLoop;
93 template <
class Callable>
103 template <
class Callable>
110 const AString& threadName() const noexcept {
118 AStacktrace threadStacktrace()
const;
121 bool messageQueueEmpty() noexcept;
133 AAbstractThread(const
id&
id) noexcept;
134 void updateThreadName() noexcept;
135 virtual
void processMessagesImpl();
145 AConditionVariable* cv =
nullptr;
167#include "AUI/Common/AObject.h"
173class API_AUI_CORE AThread :
public AAbstractThread,
public AObject
197 std::thread* mThread =
nullptr;
204 std::function<void()> mFunctor;
209 std::atomic_bool mInterrupted =
false;
213 AThread(std::function<
void()> functor);
231 static void sleep(std::chrono::milliseconds duration);
247 static void interruptionPoint();
257 cur->mThreadName = std::move(name);
258 cur->updateThreadName();
265 current()->processMessagesImpl();
268 bool isInterrupted()
override;
269 void resetInterruptFlag()
override;
270 void interrupt()
override;
279#include "AConditionVariable.h"
Represents an abstract thread. Not all threads are created through AThread - these are interfaced wit...
Definition AThread.h:33
void enqueue(AMessageQueue<>::Message f)
Delivers task for execution (message) to this thread's event queue. Messages are processed by framewo...
Definition AThread.cpp:228
virtual bool isInterrupted()
Definition AThread.cpp:154
virtual void interrupt()
Interrupt thread's execution.
Definition AThread.cpp:159
void operator*(Callable fun)
Enqueue message to make. Helper function for async, asyncX, ui, uiX.
Definition AThread.h:104
IEventLoop * getCurrentEventLoop() const
Get current event loop for this thread.
Definition AThread.h:83
id getId() const
Definition AThread.cpp:195
void operator<<(Callable fun)
Enqueue message to make.
Definition AThread.h:94
id mId
Thread ID.
Definition AThread.h:127
std::thread::id id
Thread ID type.
Definition AThread.h:43
virtual void resetInterruptFlag()
Reset interruption flag.
Definition AThread.cpp:161
Represents a condition variable.
Definition AConditionVariable.h:24
Universal thread-safe message (callback) queue implementation.
Definition AMessageQueue.h:29
Represents a Unicode character string.
Definition AString.h:37
Exception that is thrown by AThread::interruptionPoint(), if interruption is requested for this threa...
Definition AThread.h:181
void needRethrow() const noexcept
Schedules AThread::Interrupted exception to the next interruption point. Sometimes you could not thro...
Definition AThread.h:188
Represents a user-defined thread.
Definition AThread.h:174
static _< AAbstractThread > current()
Definition AThread.cpp:197
static void setName(AString name) noexcept
Definition AThread.h:255
static void processMessages()
Processes messages from other threads of current thread. Called by framework itself using IEventLoop.
Definition AThread.h:264
Definition IEventLoop.h:17
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:178
Basic syscall-based synchronization primitive.
Definition AMutex.h:33