Skip to content

Commit

Permalink
Merge pull request #9581 from kjbracey-arm/sharedptr_atomic
Browse files Browse the repository at this point in the history
SharedPtr: use atomic load
  • Loading branch information
0xc0170 committed Feb 4, 2019
2 parents b4e09cf + 52aac4c commit b433efe
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions platform/SharedPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,7 @@ class SharedPtr {
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;
}
Expand Down Expand Up @@ -230,8 +227,7 @@ class SharedPtr {
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;
Expand Down

0 comments on commit b433efe

Please sign in to comment.