Skip to content

Commit

Permalink
Improve cv
Browse files Browse the repository at this point in the history
  • Loading branch information
ikbuibui committed Jul 29, 2024
1 parent a75c587 commit 1ce02e8
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions redGrapes/sync/cv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,22 @@ namespace redGrapes
}
}

should_wait.store(true);
should_wait.store(true, std::memory_order_release);
}

bool notify()
{
bool w = true;
should_wait.compare_exchange_strong(w, false, std::memory_order_release);

// TODO: check this optimization
// if( ! busy.test_and_set(std::memory_order_acquire) )
bool expected = true;
if(should_wait
.compare_exchange_strong(expected, false, std::memory_order_release, std::memory_order_relaxed))
{
std::unique_lock<std::mutex> l(m);
// TODO: check this optimization
// if( ! busy.test_and_set(std::memory_order_acquire) )
std::unique_lock<CVMutex> l(m);
cv.notify_all();
return true;
}

return w;
return false;
}
};

Expand Down

0 comments on commit 1ce02e8

Please sign in to comment.