18 #ifndef UTHREADS_UTHREAD_H_ 19 #define UTHREADS_UTHREAD_H_ 23 #include "../generic/basics.h" 24 #include "../generic/IntrusiveContainers.h" 26 #include "BlockingSync.h" 68 friend class IOHandler;
69 friend class Scheduler;
122 inline void waitOrSignal(
bool caller){
124 if(joinWait.
empty()){
125 joinWait.
wait(joinMtx);
127 if(caller) afterJoin.
V();
131 if(!caller) afterJoin.
P();
138 enum class State : std::uint8_t {
149 enum class JState : std::uint8_t {
166 stackPointer(vaddr(this)), stackBottom(sb), stackSize(ss), state(
167 State::INITIALIZED), uThreadID(uThreadMasterID++), currentCluster(
168 nullptr), jState(JState::DETACHED), homekThread(nullptr), utvar(nullptr) {
173 static vaddr createStack(
size_t);
187 static std::atomic_ulong totalNumberofUTs;
188 static std::atomic_ulong uThreadMasterID;
202 virtual void destory(
bool);
217 void suspend(funcvoid2_t,
void*);
220 static void invoke(funcvoid3_t, ptr_t, ptr_t, ptr_t) __noreturn;
246 return create(defaultStackSize, joinable);
260 void start(
const Cluster& cluster, ptr_t func, ptr_t arg1 =
nullptr,
261 ptr_t arg2 =
nullptr, ptr_t arg3 =
nullptr);
312 return *currentCluster;
322 return totalNumberofUTs.load();
static void migrate(Cluster *)
Move the uThread to the provided cluster.
Definition: uThread.cpp:111
void release()
release the Mutex
Definition: BlockingSync.h:191
static void yield()
Causes uThread to yield.
Definition: uThread.cpp:103
static uThread * currentUThread()
Get a pointer to the current running uThread.
Definition: uThread.cpp:170
static void terminate()
Terminates the uThread.
Definition: uThread.cpp:138
uThread(vaddr sb, size_t ss)
Definition: uThread.h:165
A user-level Semaphore.
Definition: BlockingSync.h:294
bool P()
Decrement the value of the Semaphore.
Definition: BlockingSync.h:321
static uThread * create(size_t ss, bool joinable=false)
Create a uThread with a given stack size.
Definition: uThread.cpp:71
A user-level Mutex.
Definition: BlockingSync.h:123
void resume()
Resumes the uThread. If uThread is blocked or is waiting on IO it will be placed back on the ReadyQue...
Definition: uThread.cpp:127
static uThread * create(bool joinable=false)
Create a uThread with default stack size.
Definition: uThread.h:245
static uint64_t getTotalNumberofUTs()
Definition: uThread.h:321
Object to represent kernel threads.
Definition: kThread.h:54
Data structure to cache uThreads.
Definition: uThreadCache.h:33
bool acquire()
acquire the mutex
Definition: BlockingSync.h:182
bool empty()
Whether the waiting list is empty or not.
Definition: BlockingSync.h:284
void V()
increment the value of the Semaphore
Definition: BlockingSync.h:334
Cluster & getCurrentCluster() const
return the current Cluster uThread is executed on
Definition: uThread.h:311
user-level threads (fiber)
Definition: uThread.h:63
Scheduler and Cluster of kThreads.
Definition: Cluster.h:61
void start(const Cluster &cluster, ptr_t func, ptr_t arg1=nullptr, ptr_t arg2=nullptr, ptr_t arg3=nullptr)
start the uThread by calling the function passed to it
Definition: uThread.cpp:94
bool join()
Wait for uThread to finish execution and exit.
Definition: uThread.cpp:150
A queue used to keep track of blocked uThreads.
Definition: BlockingSync.h:36
void detach()
Detach a joinable thread.
Definition: uThread.cpp:161
void wait(Mutex &mutex)
Block uThread on the condition variable using the provided mutex.
Definition: BlockingSync.h:262
const uThread & operator=(const uThread &)=delete
uint64_t getID() const
get the ID of this uThread
Definition: uThread.h:329
A user level condition variable.
Definition: BlockingSync.h:254
void signal(Mutex &mutex)
Unblock one uThread waiting on the condition variable.
Definition: BlockingSync.h:271