Browse Source

解决几处可能错误使用compare exchange weak的地方

tags/v2.9.7
tearshark 4 years ago
parent
commit
cd8f6adb7e
2 changed files with 4 additions and 4 deletions
  1. 3
    3
      librf/src/event_v2.cpp
  2. 1
    1
      librf/src/spinlock.h

+ 3
- 3
librf/src/event_v2.cpp View File

@@ -23,7 +23,7 @@ RESUMEF_NS
void state_event_t::on_cancel() noexcept
{
bool* oldValue = _value.load(std::memory_order_acquire);
if (oldValue != nullptr && _value.compare_exchange_weak(oldValue, nullptr, std::memory_order_acq_rel))
if (oldValue != nullptr && _value.compare_exchange_strong(oldValue, nullptr, std::memory_order_acq_rel))
{
*oldValue = false;
this->_coro = nullptr;
@@ -33,7 +33,7 @@ RESUMEF_NS
bool state_event_t::on_notify()
{
bool* oldValue = _value.load(std::memory_order_acquire);
if (oldValue != nullptr && _value.compare_exchange_weak(oldValue, nullptr, std::memory_order_acq_rel))
if (oldValue != nullptr && _value.compare_exchange_strong(oldValue, nullptr, std::memory_order_acq_rel))
{
*oldValue = true;

@@ -49,7 +49,7 @@ RESUMEF_NS
bool state_event_t::on_timeout()
{
bool* oldValue = _value.load(std::memory_order_acquire);
if (oldValue != nullptr && _value.compare_exchange_weak(oldValue, nullptr, std::memory_order_acq_rel))
if (oldValue != nullptr && _value.compare_exchange_strong(oldValue, nullptr, std::memory_order_acq_rel))
{
*oldValue = false;


+ 1
- 1
librf/src/spinlock.h View File

@@ -69,7 +69,7 @@ RESUMEF_NS
bool try_lock() noexcept
{
int val = FREE_VALUE;
bool ret = lck.compare_exchange_weak(val, LOCKED_VALUE, std::memory_order_acq_rel);
bool ret = lck.compare_exchange_strong(val, LOCKED_VALUE, std::memory_order_acq_rel);
#if _DEBUG
if (ret) owner_thread_id = std::this_thread::get_id();

Loading…
Cancel
Save