Parcourir la source

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

tags/v2.9.7
tearshark il y a 4 ans
Parent
révision
cd8f6adb7e
2 fichiers modifiés avec 4 ajouts et 4 suppressions
  1. 3
    3
      librf/src/event_v2.cpp
  2. 1
    1
      librf/src/spinlock.h

+ 3
- 3
librf/src/event_v2.cpp Voir le fichier

@@ -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 Voir le fichier

@@ -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();

Chargement…
Annuler
Enregistrer