mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-07-31 13:17:23 +02:00
Use a relaxed load before test_and_set to not lock cache line on contention (AMD spinlock recommendation per <https://probablydance.com/2019/12/30/measuring-mutexes-spinlocks-and-how-bad-the-linux-scheduler-really-is/>)
This commit is contained in:
@ -7,13 +7,9 @@
|
|||||||
# pragma once
|
# pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//
|
// Copyright 2008, 2020 Peter Dimov
|
||||||
// Copyright (c) 2008 Peter Dimov
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
//
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <boost/smart_ptr/detail/yield_k.hpp>
|
#include <boost/smart_ptr/detail/yield_k.hpp>
|
||||||
|
|
||||||
@ -40,8 +36,7 @@ public:
|
|||||||
|
|
||||||
bool try_lock()
|
bool try_lock()
|
||||||
{
|
{
|
||||||
int r = __atomic_test_and_set( &v_, __ATOMIC_ACQUIRE );
|
return __atomic_load_n( &v_, __ATOMIC_RELAXED ) == 0 && __atomic_test_and_set( &v_, __ATOMIC_ACQUIRE ) == 0;
|
||||||
return r == 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lock()
|
void lock()
|
||||||
|
Reference in New Issue
Block a user