Improve branch elimination in ScopedAcquire.
GCC can't reasonably be told that the lock ptr isn't null. Adding a private bool
allows the branch to be eliminated, along with the bool.
Change-Id: I0605d69474d6a6e6951be93c0af1d8caf3f77124
[ROCm/ROCR-Runtime commit: 9dfdce5b3c]
Dieser Commit ist enthalten in:
@@ -56,20 +56,22 @@ class ScopedAcquire {
|
||||
public:
|
||||
/// @brief: When constructing, acquire the lock.
|
||||
/// @param: lock(Input), pointer to an existing lock.
|
||||
explicit ScopedAcquire(LockType* lock) : lock_(lock) { lock_->Acquire(); }
|
||||
explicit ScopedAcquire(LockType* lock) : lock_(lock), doRelease(true) { lock_->Acquire(); }
|
||||
|
||||
/// @brief: when destructing, release the lock.
|
||||
~ScopedAcquire() {
|
||||
if (lock_ != nullptr) lock_->Release();
|
||||
if (doRelease) lock_->Release();
|
||||
}
|
||||
|
||||
/// @brief: Release the lock early. Avoid using when possible.
|
||||
void Release() {
|
||||
lock_->Release();
|
||||
lock_ = nullptr;
|
||||
doRelease = false;
|
||||
}
|
||||
|
||||
private:
|
||||
LockType* lock_;
|
||||
bool doRelease;
|
||||
/// @brief: Disable copiable and assignable ability.
|
||||
DISALLOW_COPY_AND_ASSIGN(ScopedAcquire);
|
||||
};
|
||||
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren