-
Notifications
You must be signed in to change notification settings - Fork 98
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
Updated ReadWriteSpinlock to be atomically upgrade-able from Reader to #129
Conversation
0037f02
to
43f4958
Compare
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.
Looks good overall. I'm still not a fan of the semantics of a ReadGuard owning a write lock, but this looks solid.
60b389c
to
6bc5e26
Compare
a54bed5
to
e96cf02
Compare
Writer. Signed-off-by: Alexander Damian <[email protected]>
e96cf02
to
b2c57b9
Compare
} | ||
|
||
inline | ||
bool ReadWriteMutex::ReadGuard::ownsLock() const | ||
void ReadWriteMutex::Guard::lock() |
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.
I think we should have a lockRead() and a lockWrite() here.
ReadWriteMutex& lock) : | ||
_mutex(&lock), | ||
_ownsLock(true) | ||
bool ReadWriteMutex::Guard::tryLock() |
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.
likewise tryLockRead() & tryLockWrite() instead of lock()
ReadWriteSpinLock::WriteGuard::WriteGuard(ReadWriteSpinLock& lock) : | ||
_spinlock(lock), | ||
_ownsLock(true) | ||
void ReadWriteSpinLock::Guard::lock() |
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.
Same comment as on ReadWriteMutex::Guard; we need lockRead() & lockWrite() rather than lock().
quantum/quantum_read_write_mutex.h
Outdated
|
||
class ReadGuard | ||
class Guard | ||
{ | ||
public: | ||
/// @brief Construct this object and lock the passed-in mutex as a reader. |
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.
Delete 'as a reader' here.
quantum/quantum_read_write_mutex.h
Outdated
ReadWriteMutex::AdoptLock); | ||
/// @note Does not block. | ||
Guard(ReadWriteMutex& lock, | ||
LockTraits::AdoptLock); | ||
|
||
/// @brief Destroy this object and unlock the underlying mutex if this object owns it. |
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.
Rephrase this as "unlock the underlying mutex if this object still owns a lock state on it" or something similar. That is, the object doesn't really give up ownership of the Mutex object (unless we implement release() again). It always owns the Mutex, what it may or may not own is the locked state.
quantum/quantum_read_write_mutex.h
Outdated
|
||
/// @brief Releases the write lock on the underlying mutex. | ||
/// @brief Releases the read lock on the underlying mutex. | ||
/// @note Also releases ownership of the underlying mutex. |
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.
This comment isn't quite right (I expect it's replicated on others); see comments above on destructor.
Signed-off-by: Alexander Damian <[email protected]>
92bbf98
to
2866a8e
Compare
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.
Looks good.
Description of changes
Updated
ReadWriteSpinlock
to be atomically upgrade-able from Reader to Writer.Signed-off-by: Alexander Damian [email protected]