BitMap: Change the size param to the number of entries (bits)

This commit is contained in:
Dr. Chat 2015-12-27 13:33:26 -06:00 committed by Ben Vanik
parent eee0bb070c
commit d4da8cab4e
3 changed files with 15 additions and 16 deletions

View File

@ -17,13 +17,13 @@ namespace xe {
BitMap::BitMap() = default; BitMap::BitMap() = default;
BitMap::BitMap(size_t size) { Resize(size); } BitMap::BitMap(size_t size_bits) { Resize(size_bits); }
BitMap::BitMap(uint32_t* data, size_t size) { BitMap::BitMap(uint32_t* data, size_t size_bits) {
assert_true(size % 4 == 0); assert_true(size_bits % 32 == 0);
data_.resize(size / 4); data_.resize(size_bits / 32);
std::memcpy(data_.data(), data, size); std::memcpy(data_.data(), data, size_bits / 32);
} }
size_t BitMap::Acquire() { size_t BitMap::Acquire() {
@ -74,10 +74,10 @@ void BitMap::Release(size_t index) {
} while (!atomic_cas(entry, new_entry, &data_[slot])); } while (!atomic_cas(entry, new_entry, &data_[slot]));
} }
void BitMap::Resize(size_t new_size) { void BitMap::Resize(size_t new_size_bits) {
auto old_size = data_.size(); auto old_size = data_.size();
assert_true(new_size % 4 == 0); assert_true(new_size_bits % 32 == 0);
data_.resize(new_size / 4); data_.resize(new_size_bits / 32);
// Initialize new entries. // Initialize new entries.
if (data_.size() > old_size) { if (data_.size() > old_size) {

View File

@ -20,13 +20,13 @@ class BitMap {
public: public:
BitMap(); BitMap();
// Size is the number of 8-bit entries, must be a multiple of 4. // Size is the number of entries, must be a multiple of 32.
BitMap(size_t size); BitMap(size_t size_bits);
// Data does not have to be aligned to a 4-byte boundary, but it is // Data does not have to be aligned to a 4-byte boundary, but it is
// preferable. // preferable.
// Size is the number of 8-bit entries, must be a multiple of 4. // Size is the number of entries, must be a multiple of 32.
BitMap(uint32_t* data, size_t size); BitMap(uint32_t* data, size_t size_bits);
// (threadsafe) Acquires an entry and returns its index. Returns -1 if there // (threadsafe) Acquires an entry and returns its index. Returns -1 if there
// are no more free entries. // are no more free entries.
@ -35,9 +35,8 @@ class BitMap {
// (threadsafe) Releases an entry by an index. // (threadsafe) Releases an entry by an index.
void Release(size_t index); void Release(size_t index);
// Resize the bitmap. Size is the number of 8-bit entries, must be a multiple // Resize the bitmap. Size is the number of entries, must be a multiple of 32.
// of 4. void Resize(size_t new_size_bits);
void Resize(size_t new_size);
// Sets all entries to free. // Sets all entries to free.
void Reset(); void Reset();

View File

@ -80,7 +80,7 @@ KernelState::KernelState(Emulator* emulator)
pib->unk_54 = pib->unk_58 = 0; pib->unk_54 = pib->unk_58 = 0;
// Hardcoded maximum of 2048 TLS slots. // Hardcoded maximum of 2048 TLS slots.
tls_bitmap_.Resize(64 * 4); tls_bitmap_.Resize(2048);
xam::AppManager::RegisterApps(this, app_manager_.get()); xam::AppManager::RegisterApps(this, app_manager_.get());
} }