SWDEV-501403 - Switch to std::shared_mutex for streamSetLock

Shared mutex allows to have access to the list of streams  from
multiple threads at the same time.

Change-Id: Ibee64b846cde03321d5b17dbee2829c0bab7e7d6


[ROCm/clr commit: efd3ea4b30]
Этот коммит содержится в:
German Andryeyev
2024-11-28 18:26:27 -05:00
родитель 5bc1cfa2d9
Коммит 6933aa7c29
2 изменённых файлов: 8 добавлений и 8 удалений
+7 -7
Просмотреть файл
@@ -220,19 +220,19 @@ void Device::WaitActiveStreams(hip::Stream* blocking_stream, bool wait_null_stre
// ================================================================================================
void Device::AddStream(Stream* stream) {
amd::ScopedLock lock(streamSetLock);
std::unique_lock lock(streamSetLock);
streamSet.insert(stream);
}
// ================================================================================================
void Device::RemoveStream(Stream* stream){
amd::ScopedLock lock(streamSetLock);
std::unique_lock lock(streamSetLock);
streamSet.erase(stream);
}
// ================================================================================================
bool Device::StreamExists(Stream* stream){
amd::ScopedLock lock(streamSetLock);
std::shared_lock lock(streamSetLock);
if (streamSet.find(stream) != streamSet.end()) {
return true;
}
@@ -243,7 +243,7 @@ bool Device::StreamExists(Stream* stream){
void Device::destroyAllStreams() {
std::vector<Stream*> toBeDeleted;
{
amd::ScopedLock lock(streamSetLock);
std::shared_lock lock(streamSetLock);
for (auto& it : streamSet) {
if (it->Null() == false ) {
toBeDeleted.push_back(it);
@@ -262,7 +262,7 @@ void Device::SyncAllStreams(bool cpu_wait, bool wait_blocking_streams_only) {
std::vector<hip::Stream*> streams;
streams.reserve(streamSet.size());
{
amd::ScopedLock lock(streamSetLock);
std::shared_lock lock(streamSetLock);
if (wait_blocking_streams_only) {
auto null_stream = GetNullStream();
for (auto it : streamSet) {
@@ -293,7 +293,7 @@ void Device::SyncAllStreams(bool cpu_wait, bool wait_blocking_streams_only) {
// ================================================================================================
bool Device::StreamCaptureBlocking() {
amd::ScopedLock lock(streamSetLock);
std::shared_lock lock(streamSetLock);
for (auto& it : streamSet) {
if (it->GetCaptureStatus() == hipStreamCaptureStatusActive && it->Flags() != hipStreamNonBlocking) {
return true;
@@ -304,7 +304,7 @@ bool Device::StreamCaptureBlocking() {
// ================================================================================================
bool Device::existsActiveStreamForDevice() {
amd::ScopedLock lock(streamSetLock);
std::shared_lock lock(streamSetLock);
for (const auto& active_stream : streamSet) {
if (active_stream->GetQueueStatus()) {
return true;
+1 -1
Просмотреть файл
@@ -488,7 +488,7 @@ public:
// Device lock
amd::Monitor lock_{true};
// Guards device stream set
amd::Monitor streamSetLock{};
std::shared_mutex streamSetLock;
std::unordered_set<hip::Stream*> streamSet;
/// ROCclr context
amd::Context* context_;