-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Os::Queue into CMake selection (#2895)
* Initial interface tests * Initial working rules tests * Moving MaxHeap to Types; Fixing minor bugs * Basic ConditionVariables, Queue blocking, and UTs * Queue updates for Ref * Queue build all WIP * UTs compile * Passing UTs * Removing unupdated linux queue implementations * Fixing linux specific build issues * Fixing task regression * Fixing queue test memory leak * Spelling, comments, formating, and todos * Condition variable tests * Minor edits from review * Condition variable interface tests, fixes * sp * ci fixes * Minor condition variable fix * Fixing post merge issues * Final review fixes * Fixing FS stubs * Fixing max heap failures * Linux fixes * Fixing issues w.r.t. CI
- Loading branch information
Showing
113 changed files
with
4,548 additions
and
3,555 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "Os/Condition.hpp" | ||
#include "Fw/Types/Assert.hpp" | ||
|
||
namespace Os { | ||
ConditionVariable::ConditionVariable() : m_delegate(*ConditionVariableInterface::getDelegate(m_handle_storage)) {} | ||
|
||
ConditionVariable::~ConditionVariable() { | ||
m_delegate.~ConditionVariableInterface(); | ||
} | ||
|
||
void ConditionVariable::wait(Os::Mutex& mutex) { | ||
FW_ASSERT(&this->m_delegate == reinterpret_cast<ConditionVariableInterface*>(&this->m_handle_storage[0])); | ||
FW_ASSERT(this->m_lock == nullptr || this->m_lock == &mutex); // Confirm the same mutex used across waits | ||
this->m_lock = &mutex; | ||
// Attempt to lock the mutex and ensure that this was successful or the lock was already held | ||
Mutex::Status lock_status = this->m_lock->take(); | ||
FW_ASSERT(lock_status == Mutex::Status::OP_OK || lock_status == Mutex::Status::ERROR_DEADLOCK); | ||
this->m_delegate.wait(mutex); | ||
} | ||
void ConditionVariable::notify() { | ||
FW_ASSERT(&this->m_delegate == reinterpret_cast<ConditionVariableInterface*>(&this->m_handle_storage[0])); | ||
this->m_delegate.notify(); | ||
} | ||
void ConditionVariable::notifyAll() { | ||
FW_ASSERT(&this->m_delegate == reinterpret_cast<ConditionVariableInterface*>(&this->m_handle_storage[0])); | ||
this->m_delegate.notifyAll(); | ||
} | ||
|
||
ConditionVariableHandle* ConditionVariable::getHandle(){ | ||
FW_ASSERT(&this->m_delegate == reinterpret_cast<const ConditionVariableInterface*>(&this->m_handle_storage[0])); | ||
return this->m_delegate.getHandle(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// ====================================================================== | ||
// \title Os/Condition.hpp | ||
// \brief common function definitions for Os::ConditionVariables | ||
// ====================================================================== | ||
#include "Os/Mutex.hpp" | ||
#include "Os/Os.hpp" | ||
|
||
#ifndef OS_CONDITION_HPP_ | ||
#define OS_CONDITION_HPP_ | ||
|
||
namespace Os { | ||
|
||
//! \brief Condition variable handle parent | ||
class ConditionVariableHandle {}; | ||
|
||
//! \brief interface for condition variables | ||
//! | ||
//! Condition variables allow a program to block on a condition while atomically releasing an Os::Mutex and atomically | ||
//! reacquiring the mutex once the condition has been notified. | ||
class ConditionVariableInterface { | ||
public: | ||
//! Default constructor | ||
ConditionVariableInterface() = default; | ||
//! Default destructor | ||
virtual ~ConditionVariableInterface() = default; | ||
|
||
//! \brief copy constructor is forbidden | ||
ConditionVariableInterface(const ConditionVariableInterface& other) = delete; | ||
|
||
//! \brief assignment operator is forbidden | ||
virtual ConditionVariableInterface& operator=(const ConditionVariableInterface& other) = delete; | ||
|
||
//! \brief wait on a condition variable | ||
//! | ||
//! Wait on a condition variable. This function will atomically unlock the provided mutex and block on the condition | ||
//! in one step. Blocking will occur until a future `notify` or `notifyAll` call is made to this variable on another | ||
//! thread of execution. | ||
//! | ||
//! \param mutex: mutex to unlock as part of this operation | ||
virtual void wait(Os::Mutex& mutex) = 0; | ||
|
||
//! \brief notify a single waiter on this condition variable | ||
//! | ||
//! Notify a single waiter on this condition variable. It is not necessary to hold the mutex supplied by the waiters | ||
//! and it is advantageous not to hold the lock to prevent immediate re-blocking. | ||
virtual void notify() = 0; | ||
|
||
//! \brief notify all waiters on this condition variable | ||
//! | ||
//! Notify all waiters on this condition variable. It is not necessary to hold the mutex supplied by the waiters | ||
//! and it is advantageous not to hold the lock to prevent immediate re-blocking. | ||
virtual void notifyAll() = 0; | ||
|
||
//! \brief return the underlying condition variable handle (implementation specific). | ||
//! \return internal task handle representation | ||
virtual ConditionVariableHandle* getHandle() = 0; | ||
|
||
//! \brief provide a pointer to a Mutex delegate object | ||
static ConditionVariableInterface* getDelegate(ConditionVariableHandleStorage& aligned_new_memory); | ||
}; | ||
|
||
//! \brief condition variable implementation | ||
//! | ||
//! Condition variables allow a program to block on a condition while atomically releasing an Os::Mutex and atomically | ||
//! reacquiring the mutex once the condition has been notified. | ||
class ConditionVariable final : public ConditionVariableInterface { | ||
public: | ||
//! \brief default constructor | ||
ConditionVariable(); | ||
|
||
//! \brief default virtual destructor | ||
~ConditionVariable() final; | ||
|
||
//! \brief copy constructor is forbidden | ||
ConditionVariable(const ConditionVariableInterface& other) = delete; | ||
|
||
//! \brief copy constructor is forbidden | ||
ConditionVariable(const ConditionVariableInterface* other) = delete; | ||
|
||
//! \brief assignment operator is forbidden | ||
ConditionVariableInterface& operator=(const ConditionVariableInterface& other) override = delete; | ||
|
||
//! \brief wait on a condition variable | ||
//! | ||
//! Wait on a condition variable. This function will atomically unlock the provided mutex and block on the condition | ||
//! in one step. Blocking will occur until a future `notify` or `notifyAll` call is made to this variable on another | ||
//! thread of execution. This function delegates to the underlying implementation. | ||
//! | ||
//! \warning it is invalid to supply a mutex different from those supplied by others | ||
//! \warning conditions *must* be rechecked after the condition variable unlocks | ||
//! \note unlocked mutexes will be locked before waiting and will be relocked before this function returns | ||
//! | ||
//! \param mutex: mutex to unlock as part of this operation | ||
void wait(Os::Mutex& mutex) override; | ||
|
||
//! \brief notify a single waiter on this condition variable | ||
//! | ||
//! Notify a single waiter on this condition variable. It is not necessary to hold the mutex supplied by the waiters | ||
//! and it is advantageous not to hold the lock to prevent immediate re-blocking. This function delegates to the | ||
//! underlying implementation. | ||
void notify() override; | ||
|
||
//! \brief notify all waiters on this condition variable | ||
//! | ||
//! Notify all waiters on this condition variable. It is not necessary to hold the mutex supplied by the waiters | ||
//! and it is advantageous not to hold the lock to prevent immediate re-blocking. This function delegates to the | ||
//! underlying implementation. | ||
void notifyAll() override; | ||
|
||
//! \brief return the underlying condition variable handle (implementation specific). Delegates to implementation. | ||
//! \return internal task handle representation | ||
ConditionVariableHandle* getHandle() override; | ||
|
||
private: | ||
//! Pointer to mutex object previously used | ||
Os::Mutex* m_lock = nullptr; | ||
|
||
// This section is used to store the implementation-defined file handle. To Os::File and fprime, this type is | ||
// opaque and thus normal allocation cannot be done. Instead, we allow the implementor to store then handle in | ||
// the byte-array here and set `handle` to that address for storage. | ||
alignas(FW_HANDLE_ALIGNMENT) ConditionVariableHandleStorage m_handle_storage; //!< Storage for aligned FileHandle data | ||
ConditionVariableInterface& m_delegate; //!< Delegate for the real implementation | ||
}; | ||
} | ||
#endif //OS_CONDITION_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.