SharedPtr: use atomic load

Use atomic load to read use count.
pull/9581/head
Kevin Bracey 2019-02-01 12:31:41 +02:00
parent 3d4582bda0
commit 52aac4c756
1 changed files with 2 additions and 6 deletions

View File

@ -177,10 +177,7 @@ public:
uint32_t use_count() const
{
if (_ptr != NULL) {
core_util_critical_section_enter();
uint32_t current_counter = *_counter;
core_util_critical_section_exit();
return current_counter;
return core_util_atomic_load_u32(_counter);
} else {
return 0;
}
@ -230,8 +227,7 @@ private:
void decrement_counter()
{
if (_ptr != NULL) {
uint32_t new_value = core_util_atomic_decr_u32(_counter, 1);
if (new_value == 0) {
if (core_util_atomic_decr_u32(_counter, 1) == 0) {
delete _counter;
_counter = NULL;
delete _ptr;