#2 add mutex in bitmap

Merged
王雪飞 merged 1 commits from mayechi into master 9 months ago
  1. +5
    -0
      db/slotpage.h

+ 5
- 0
db/slotpage.h View File

@ -132,6 +132,7 @@ public:
} }
void dealloc_slot(size_t slot_num) { void dealloc_slot(size_t slot_num) {
mtx.lock();
const size_t byte = slot2byte(slot_num); const size_t byte = slot2byte(slot_num);
const size_t off = slot2offset(slot_num); const size_t off = slot2offset(slot_num);
char *target_byte = get_bitmap_byte(byte); char *target_byte = get_bitmap_byte(byte);
@ -139,9 +140,11 @@ public:
RESETBIT(target_byte, off); RESETBIT(target_byte, off);
// set_bitmap_byte(byte, target_byte); // set_bitmap_byte(byte, target_byte);
first_empty_slot = first_empty_slot < slot_num ? first_empty_slot:slot_num; first_empty_slot = first_empty_slot < slot_num ? first_empty_slot:slot_num;
mtx.unlock();
} }
size_t alloc_slot() { size_t alloc_slot() {
mtx.lock();
size_t target_slot = first_empty_slot; size_t target_slot = first_empty_slot;
char *start_byte = get_bitmap_byte(slot2byte(first_empty_slot)); char *start_byte = get_bitmap_byte(slot2byte(first_empty_slot));
const size_t off = slot2offset(first_empty_slot); const size_t off = slot2offset(first_empty_slot);
@ -166,6 +169,7 @@ public:
first_empty_slot = byte2slot(i) + 1; first_empty_slot = byte2slot(i) + 1;
} }
} }
mtx.unlock();
return target_slot; return target_slot;
} }
@ -195,6 +199,7 @@ private:
std::vector<char *> bitmaps_; std::vector<char *> bitmaps_;
size_t size; size_t size;
size_t first_empty_slot; size_t first_empty_slot;
std::mutex mtx;
}; };

Loading…
Cancel
Save