From 7a2cbf8873f59cfead2aa02e3e8b22fa8ab44493 Mon Sep 17 00:00:00 2001 From: nroskill Date: Wed, 13 Dec 2023 15:18:33 +0000 Subject: [PATCH] [CP] [OPT] thread stack lock --- deps/oblib/src/lib/thread/protected_stack_allocator.cpp | 8 ++++---- deps/oblib/src/lib/thread/protected_stack_allocator.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/deps/oblib/src/lib/thread/protected_stack_allocator.cpp b/deps/oblib/src/lib/thread/protected_stack_allocator.cpp index 20711fcedf..66d4eebc44 100644 --- a/deps/oblib/src/lib/thread/protected_stack_allocator.cpp +++ b/deps/oblib/src/lib/thread/protected_stack_allocator.cpp @@ -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(); } } diff --git a/deps/oblib/src/lib/thread/protected_stack_allocator.h b/deps/oblib/src/lib/thread/protected_stack_allocator.h index 872bb2d4d7..7c88e648be 100644 --- a/deps/oblib/src/lib/thread/protected_stack_allocator.h +++ b/deps/oblib/src/lib/thread/protected_stack_allocator.h @@ -15,7 +15,7 @@ #include #include -#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_; };