From 5e1d75de261ce6adfd718556b8115275617fa292 Mon Sep 17 00:00:00 2001 From: Yechi Ma <2662511702@qq.com> Date: Wed, 11 Dec 2024 19:20:36 +0800 Subject: [PATCH] add mutex in bitmap --- db/slotpage.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/db/slotpage.h b/db/slotpage.h index 2662a5a..be08919 100644 --- a/db/slotpage.h +++ b/db/slotpage.h @@ -132,6 +132,7 @@ public: } void dealloc_slot(size_t slot_num) { + mtx.lock(); const size_t byte = slot2byte(slot_num); const size_t off = slot2offset(slot_num); char *target_byte = get_bitmap_byte(byte); @@ -139,9 +140,11 @@ public: RESETBIT(target_byte, off); // set_bitmap_byte(byte, target_byte); first_empty_slot = first_empty_slot < slot_num ? first_empty_slot:slot_num; + mtx.unlock(); } size_t alloc_slot() { + mtx.lock(); size_t target_slot = first_empty_slot; char *start_byte = get_bitmap_byte(slot2byte(first_empty_slot)); const size_t off = slot2offset(first_empty_slot); @@ -166,6 +169,7 @@ public: first_empty_slot = byte2slot(i) + 1; } } + mtx.unlock(); return target_slot; } @@ -195,6 +199,7 @@ private: std::vector bitmaps_; size_t size; size_t first_empty_slot; + std::mutex mtx; }; -- 2.8.3