diff --git a/miosix/kernel/pthread.cpp b/miosix/kernel/pthread.cpp index f91bfa805ba9de39085a62668c1f8ad8f467aacd..99cf76131105591a935781cef4b5782d9d78f24d 100644 --- a/miosix/kernel/pthread.cpp +++ b/miosix/kernel/pthread.cpp @@ -313,11 +313,10 @@ int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) auto *condList=reinterpret_cast<IntrusiveList<CondData>*>(cond); FastInterruptDisableLock dLock; - Thread *p=Thread::IRQgetCurrentThread(); - CondData listItem; - listItem.thread=p; + Thread *t=Thread::IRQgetCurrentThread(); + CondData listItem(t); condList->push_back(&listItem); //Putting this thread last on the list (lifo policy) - p->flags.IRQsetCondWait(true); + t->flags.IRQsetCondWait(true); unsigned int depth=IRQdoMutexUnlockAllDepthLevels(mutex); { @@ -452,15 +451,14 @@ int pthreadCondTimedWaitImpl(pthread_cond_t *cond, pthread_mutex_t *mutex, long //side effect, very shor sleeps done very early at boot will be extended. absTime=std::max(absTime,100000LL); FastInterruptDisableLock dLock; - Thread *p=Thread::IRQgetCurrentThread(); - CondData listItem; - listItem.thread=p; + Thread *t=Thread::IRQgetCurrentThread(); + CondData listItem(t); condList->push_back(&listItem); //Putting this thread last on the list (lifo policy) SleepData sleepData; - sleepData.p=p; + sleepData.p=t; sleepData.wakeupTime=absTime; IRQaddToSleepingList(&sleepData); //Putting this thread on the sleeping list too - p->flags.IRQsetCondWait(true); + t->flags.IRQsetCondWait(true); unsigned int depth=IRQdoMutexUnlockAllDepthLevels(mutex); { diff --git a/miosix/kernel/sync.cpp b/miosix/kernel/sync.cpp index 8a7d425666776393080047dceac8ca258249cf2d..b6aef8c2bb23b7d9a60bc8c02dabc82dcae16cbd 100644 --- a/miosix/kernel/sync.cpp +++ b/miosix/kernel/sync.cpp @@ -372,8 +372,7 @@ void ConditionVariable::wait(Mutex& m) { PauseKernelLock dLock; Thread *t=Thread::getCurrentThread(); - CondData listItem; - listItem.thread=t; + CondData listItem(t); condList.push_back(&listItem); //Add entry to tail of list //Unlock mutex and wait @@ -400,8 +399,7 @@ TimedWaitResult ConditionVariable::timedWait(Mutex& m, long long absTime) PauseKernelLock dLock; Thread *t=Thread::getCurrentThread(); - CondData listItem; - listItem.thread=t; + CondData listItem(t); condList.push_back(&listItem); //Add entry to tail of list SleepData sleepData; sleepData.p=t; diff --git a/miosix/kernel/sync.h b/miosix/kernel/sync.h index 7bb97449a6ca33cfa48e996266c204cecf423e68..bc48521513cda8f897e8e61dbb11b9df42223f0f 100644 --- a/miosix/kernel/sync.h +++ b/miosix/kernel/sync.h @@ -386,18 +386,19 @@ private: /** * \internal - * \struct CondData - * This struct is used to make a list of threads that are waiting on a condition + * This class is used to make a list of threads that are waiting on a condition * variable. It is used by the kernel, and should not be used by end users. */ -struct CondData : public IntrusiveListItem +class CondData : public IntrusiveListItem { +public: + CondData(Thread *thread) : thread(thread) {} Thread *thread; ///<\internal Thread that is waiting }; /** - * Possible return values of timedWait - */ + * Possible return values of timedWait + */ enum class TimedWaitResult { NoTimeout,