From ae726f65b10b0cdafd4362c4c79fb73126b01d39 Mon Sep 17 00:00:00 2001 From: Terraneo Federico <fede.tft@miosix.org> Date: Sun, 30 Apr 2023 12:28:04 +0200 Subject: [PATCH] Encapsulate WaitToken --- miosix/kernel/sync.h | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/miosix/kernel/sync.h b/miosix/kernel/sync.h index bc991312..cadae7c7 100644 --- a/miosix/kernel/sync.h +++ b/miosix/kernel/sync.h @@ -391,12 +391,12 @@ private: * variable or on a semaphore. It is used by the kernel, and should not be used * by end users. */ -class WaitToken : public IntrusiveListItem -{ -public: - WaitToken(Thread *thread) : thread(thread) {} - Thread *thread; ///<\internal Thread that is waiting -}; +// class WaitToken : public IntrusiveListItem +// { +// public: +// WaitToken(Thread *thread) : thread(thread) {} +// Thread *thread; ///<\internal Thread that is waiting +// }; /** * A condition variable class for thread synchronization, available from @@ -521,7 +521,21 @@ public: if(doBroadcast()) Thread::yield(); } + //Unwanted methods + ConditionVariable(const ConditionVariable&) = delete; + ConditionVariable& operator= (const ConditionVariable&) = delete; + private: + /** + * \internal Element of a thread waiting list + */ + class WaitToken : public IntrusiveListItem + { + public: + WaitToken(Thread *thread) : thread(thread) {} + Thread *thread; ///<\internal Waiting thread + }; + /** * Wakeup one waiting thread. * Currently implemented policy is fifo. @@ -536,10 +550,6 @@ private: */ bool doBroadcast(); - //Unwanted methods - ConditionVariable(const ConditionVariable&) = delete; - ConditionVariable& operator= (const ConditionVariable&) = delete; - friend int ::pthread_cond_destroy(pthread_cond_t *); //Needs condList friend int ::pthread_cond_signal(pthread_cond_t *); //Needs doSignal() friend int ::pthread_cond_broadcast(pthread_cond_t *); //Needs doBroadcast() @@ -636,11 +646,21 @@ public: */ unsigned int getCount() { return count; } -private: // Disallow copies Semaphore(const Semaphore&) = delete; Semaphore& operator= (const Semaphore&) = delete; +private: + /** + * \internal Element of a thread waiting list + */ + class WaitToken : public IntrusiveListItem + { + public: + WaitToken(Thread *thread) : thread(thread) {} + Thread *thread; ///<\internal Waiting thread and spurious wakeup token + }; + /** * \internal * Internal method that signals the semaphore without triggering a -- GitLab