Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/runtime/hexagon/hexagon_buffer_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class HexagonBufferManager {
CHECK(it != hexagon_buffer_map_.end())
<< "Attempt made to free unknown or already freed dataspace allocation";
CHECK(it->second != nullptr);
hexagon_buffer_map_.erase(it);
{
std::lock_guard<std::mutex> lock(map_mutex_);
hexagon_buffer_map_.erase(it);
}
}
/*!
* \brief Allocate a HexagonBuffer.
Expand All @@ -53,25 +56,41 @@ class HexagonBufferManager {
void* AllocateHexagonBuffer(Args&&... args) {
auto buf = std::make_unique<HexagonBuffer>(std::forward<Args>(args)...);
void* ptr = buf->GetPointer();
hexagon_buffer_map_.insert({ptr, std::move(buf)});
{
std::lock_guard<std::mutex> lock(map_mutex_);
hexagon_buffer_map_.insert({ptr, std::move(buf)});
}
return ptr;
}

//! \brief Returns whether the HexagonBuffer is in the map.
size_t count(void* ptr) { return hexagon_buffer_map_.count(ptr); }
size_t count(void* ptr) {
std::lock_guard<std::mutex> lock(map_mutex_);
return hexagon_buffer_map_.count(ptr);
}

//! \brief Returns an iterator to the HexagonBuffer within the map.
HexagonBuffer* find(void* ptr) {
std::lock_guard<std::mutex> lock(map_mutex_);
auto it = hexagon_buffer_map_.find(ptr);
if (it != hexagon_buffer_map_.end()) {
return it->second.get();
}
return nullptr;
}

//! \brief Returns whether the HexagonBufferManager has any allocations.
bool empty() {
std::lock_guard<std::mutex> lock(map_mutex_);
return hexagon_buffer_map_.empty();
}

private:
//! \brief Contains the HexagonBuffer objects managed by this class.
std::unordered_map<void*, std::unique_ptr<HexagonBuffer>> hexagon_buffer_map_;

//! \brief Protects updates to the map.
std::mutex map_mutex_;
};

} // namespace hexagon
Expand Down