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 {
33 friend class IEventLoop;
35 friend class AConditionVariable;
36 friend void setupUIThread()
noexcept;
42 typedef std::thread::id
id;
93 template <
class Callable>
103 template <
class Callable>
109 const AString& threadName() const noexcept {
120 bool messageQueueEmpty() noexcept;
132 AAbstractThread(const
id&
id) noexcept;
133 void updateThreadName() noexcept;
134 virtual
void processMessagesImpl();
142 AConditionVariable* cv =
nullptr;
163#include "AUI/Common/AObject.h"
169class API_AUI_CORE AThread :
public AAbstractThread,
public AObject {
189 std::thread* mThread =
nullptr;
195 std::function<void()> mFunctor;
200 std::atomic_bool mInterrupted =
false;
203 AThread(std::function<
void()> functor);
226 static
void sleep(std::chrono::milliseconds duration);
250 cur->mThreadName = std::move(name);
251 cur->updateThreadName();
269#include "AConditionVariable.h"
Represents an abstract thread. Not all threads are created through AThread - these are interfaced wit...
Definition AThread.h:32
void enqueue(AMessageQueue<>::Message f)
Delivers task for execution (message) to this thread's event queue. Messages are processed by framewo...
void operator*(Callable fun)
Enqueue message to make. Helper function for async, asyncX, ui, uiX.
Definition AThread.h:104
virtual void interrupt()
Interrupt thread's execution.
virtual bool isInterrupted()
AStacktrace threadStacktrace() const
Retrieve stacktrace of the thread.
IEventLoop * getCurrentEventLoop() const
Get current event loop for this thread.
Definition AThread.h:86
void operator<<(Callable fun)
Enqueue message to make.
Definition AThread.h:94
virtual void resetInterruptFlag()
Reset interruption flag.
id mId
Thread ID.
Definition AThread.h:126
std::thread::id id
Thread ID type.
Definition AThread.h:42
Represents a condition variable.
Definition AConditionVariable.h:24
Universal thread-safe message (callback) queue implementation.
Definition AMessageQueue.h:29
Stacktrace consisting of a collection of stack function frames.
Definition AStacktrace.h:28
Represents a Unicode character string.
Definition AString.h:38
Exception that is thrown by AThread::interruptionPoint(), if interruption is requested for this threa...
Definition AThread.h:175
void needRethrow() const noexcept
Schedules AThread::Interrupted exception to the next interruption point. Sometimes you could not thro...
Definition AThread.h:182
Represents a user-defined thread.
Definition AThread.h:169
void resetInterruptFlag() override
Reset interruption flag.
static void interruptionPoint()
Interruption point.
static void sleep(std::chrono::milliseconds duration)
Sleep for specified duration. Most operation systems guarantee that elasped time will be greater than...
static void setName(AString name) noexcept
Definition AThread.h:248
static void processMessages()
Processes messages from other threads of current thread. Called by framework itself using IEventLoop.
Definition AThread.h:257
static const _< AAbstractThread > & main() noexcept
Returns main thread of the application.
static _< AAbstractThread > current()
void join()
Waits for thread to be finished.
void start()
Start thread execution.
void interrupt() override
Interrupt thread's execution.
bool isInterrupted() override
Definition IEventLoop.h:17
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
Basic syscall-based synchronization primitive.
Definition AMutex.h:33