|
|
@ -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<char *> bitmaps_; |
|
|
|
size_t size; |
|
|
|
size_t first_empty_slot; |
|
|
|
std::mutex mtx; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|