Commit 91bbb5fc authored by Glitter's avatar Glitter Committed by yiwu-arbug

Replace atomic var by normal var (#39)

Because db is locked when  add/sub  bg_gc_scheduled_, so this variable is no need to be atomic 
parent a38eb0b3
...@@ -239,7 +239,8 @@ class TitanDBImpl : public TitanDB { ...@@ -239,7 +239,8 @@ class TitanDBImpl : public TitanDB {
// pending_gc_ hold column families that already on gc_queue_. // pending_gc_ hold column families that already on gc_queue_.
std::deque<uint32_t> gc_queue_; std::deque<uint32_t> gc_queue_;
std::atomic_int bg_gc_scheduled_{0}; // Guarded by mutex_.
int bg_gc_scheduled_{0};
std::atomic_bool shuting_down_{false}; std::atomic_bool shuting_down_{false};
}; };
......
...@@ -14,11 +14,9 @@ void TitanDBImpl::MaybeScheduleGC() { ...@@ -14,11 +14,9 @@ void TitanDBImpl::MaybeScheduleGC() {
if (shuting_down_.load(std::memory_order_acquire)) return; if (shuting_down_.load(std::memory_order_acquire)) return;
if (bg_gc_scheduled_.load(std::memory_order_acquire) >= if (bg_gc_scheduled_ >= db_options_.max_background_gc) return;
db_options_.max_background_gc)
return;
bg_gc_scheduled_.fetch_add(1, std::memory_order_release); bg_gc_scheduled_++;
env_->Schedule(&TitanDBImpl::BGWorkGC, this, Env::Priority::BOTTOM, this); env_->Schedule(&TitanDBImpl::BGWorkGC, this, Env::Priority::BOTTOM, this);
} }
...@@ -118,7 +116,7 @@ Status TitanDBImpl::BackgroundGC(LogBuffer* log_buffer) { ...@@ -118,7 +116,7 @@ Status TitanDBImpl::BackgroundGC(LogBuffer* log_buffer) {
Status TitanDBImpl::TEST_StartGC(uint32_t column_family_id) { Status TitanDBImpl::TEST_StartGC(uint32_t column_family_id) {
{ {
MutexLock l(&mutex_); MutexLock l(&mutex_);
bg_gc_scheduled_.fetch_add(1, std::memory_order_release); bg_gc_scheduled_++;
} }
// BackgroundCallGC // BackgroundCallGC
Status s; Status s;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment