[CP] [OPT] thread stack lock

This commit is contained in:
nroskill
2023-12-13 15:18:33 +00:00
committed by ob-robot
parent cb432ec65e
commit 7a2cbf8873
2 changed files with 8 additions and 8 deletions

View File

@ -156,12 +156,12 @@ void StackMgr::insert(ObStackHeader *header)
{
if (header != nullptr) {
abort_unless(header->check_magic());
mutex_.lock();
rwlock_.wrlock(common::ObLatchIds::DEFAULT_SPIN_RWLOCK);
header->prev_ = &dummy_;
header->next_ = dummy_.next_;
dummy_.next_->prev_ = header;
dummy_.next_ = header;
mutex_.unlock();
rwlock_.unlock();
}
}
@ -169,11 +169,11 @@ void StackMgr::erase(ObStackHeader *header)
{
if (header != nullptr) {
abort_unless(header->check_magic());
mutex_.lock();
rwlock_.wrlock(common::ObLatchIds::DEFAULT_SPIN_RWLOCK);
header->prev_->next_ = header->next_;
header->next_->prev_ = header->prev_;
header->prev_ = header->next_ = header;
mutex_.unlock();
rwlock_.unlock();
}
}

View File

@ -15,7 +15,7 @@
#include <stdint.h>
#include <stddef.h>
#include "lib/lock/ob_mutex.h"
#include "lib/lock/ob_latch.h"
namespace oceanbase {
namespace lib {
@ -62,10 +62,10 @@ public:
public:
Guard(StackMgr& mgr) : mgr_(mgr), cur_(nullptr)
{
mgr_.mutex_.lock();
mgr_.rwlock_.rdlock(common::ObLatchIds::DEFAULT_SPIN_RWLOCK);
cur_ = mgr_.dummy_.next_;
}
~Guard() { mgr_.mutex_.unlock(); }
~Guard() { mgr_.rwlock_.unlock(); }
ObStackHeader* operator*() { return (cur_ == &(mgr_.dummy_)) ? nullptr : cur_; }
ObStackHeader* next()
{
@ -86,7 +86,7 @@ private:
ObStackHeader *begin() { return dummy_.next_; }
ObStackHeader *end() { return &dummy_; }
private:
lib::ObMutex mutex_;
common::ObLatch rwlock_;
ObStackHeader dummy_;
};