-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor OS::Mutex in CMake selection #2790
Conversation
delete reinterpret_cast<pthread_mutex_t*>(this->m_handle); | ||
} | ||
PosixMutex::Status PosixMutex::release() { | ||
PlatformIntType status = pthread_mutex_unlock(&this->m_handle.m_mutex_descriptor); |
Check notice
Code scanning / CodeQL
Use of basic integral type Note
this->m_handle = reinterpret_cast<POINTER_CAST>(handle); | ||
} | ||
PosixMutex::Status PosixMutex::take() { | ||
PlatformIntType status = pthread_mutex_lock(&this->m_handle.m_mutex_descriptor); |
Check notice
Code scanning / CodeQL
Use of basic integral type Note
stat = pthread_mutex_init(handle,&attr); | ||
FW_ASSERT(stat == 0,stat); | ||
PosixMutex::~PosixMutex() { | ||
PlatformIntType status = pthread_mutex_destroy(&this->m_handle.m_mutex_descriptor); |
Check notice
Code scanning / CodeQL
Use of basic integral type Note
@@ -70,5 +70,23 @@ | |||
return status; | |||
} | |||
|
|||
Mutex::Status posix_status_to_mutex_status(PlatformIntType posix_status){ |
Check notice
Code scanning / CodeQL
Use of basic integral type Note
Status release() override; //!< unlock the mutex and get return status | ||
void lock() override; //!< lock the mutex | ||
void unLock() override; //!< unlock the mutex | ||
void unlock() { this->unLock(); } //!< alias for unLock to meet BasicLockable requirements |
Check notice
Code scanning / CodeQL
More than one statement per line Note
namespace Posix { | ||
namespace Mutex { | ||
|
||
struct PosixMutexHandle : public MutexHandle { |
Check notice
Code scanning / CodeQL
More than one statement per line Note
@@ -70,5 +70,23 @@ | |||
return status; | |||
} | |||
|
|||
Mutex::Status posix_status_to_mutex_status(PlatformIntType posix_status){ |
Check notice
Code scanning / CodeQL
Long function without assertion Note
@@ -70,5 +70,23 @@ | |||
return status; | |||
} | |||
|
|||
Mutex::Status posix_status_to_mutex_status(PlatformIntType posix_status){ | |||
Mutex::Status status = Mutex::Status::ERROR_OTHER; | |||
switch (posix_status) { |
Check warning
Code scanning / CodeQL
Unchecked function argument Warning
@LeStarch ready for review when you are - no rush |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Peer review comments
Os/Posix/CMakeLists.txt
Outdated
set(SOURCE_FILES | ||
"${CMAKE_CURRENT_LIST_DIR}/Mutex.cpp" | ||
# "${CMAKE_CURRENT_LIST_DIR}/DefaultMutex.cpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct - delete and make sure it's not in other modules as well
} | ||
|
||
Mutex::Status Mutex::take() { | ||
FW_ASSERT(&this->m_delegate == reinterpret_cast<MutexInterface*>(&this->m_handle_storage[0])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implement take/release calling the others here
Os/Posix/test/ut/PosixMutexTests.cpp
Outdated
Os::Test::Mutex::Tester::LockMutex lock_rule; | ||
Os::Test::Mutex::Tester::UnlockMutex unlock_rule; | ||
lock_rule.apply(*tester); | ||
ASSERT_DEATH_IF_SUPPORTED(delete tester.release(), Os::Test::Mutex::Tester::ASSERT_IN_MUTEX_CPP); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why tester.release()
and not just tester ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tester
is a std::unique_ptr
. The .release()
call here is that of the unique_ptr, not Mutex::release(). I will add a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But actually, since the deletion is not expected to succeed... maybe we should get()
instead so that the destructor can be called again and the unique_ptr and underlying Mutex does get destroyed successfully?
Os/test/ut/mutex/MutexRules.cpp
Outdated
state.m_mutex.lock(); | ||
state.m_state = Os::Test::Mutex::Tester::MutexState::LOCKED; | ||
|
||
state.m_value = 42; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use STest random number here instead
PosixMutex::PosixMutex() : Os::MutexInterface(), m_handle() { | ||
// set attributes | ||
pthread_mutexattr_t attribute; | ||
PlatformIntType status = pthread_mutexattr_init(&attribute); |
Check notice
Code scanning / CodeQL
Use of basic integral type Note
Mutex::Mutex() { | ||
pthread_mutex_t* handle = new(std::nothrow) pthread_mutex_t; | ||
FW_ASSERT(handle != nullptr); | ||
PosixMutex::PosixMutex() : Os::MutexInterface(), m_handle() { |
Check notice
Code scanning / CodeQL
Long function without assertion Note
Change Description
Refactor the Mutex part of the OSAL layer to use the new system!
Rationale
See #2722