libobs: Update compare-exchange pattern

Use function that updates previous value automatically.

Also load initial value seq_cst to be safe.
This commit is contained in:
jpark37 2021-02-02 22:41:20 -08:00 committed by Jim
parent 5cf40bf818
commit d48e77385c
2 changed files with 8 additions and 8 deletions

View file

@ -543,12 +543,12 @@ static inline bool obs_weak_ref_release(struct obs_weak_ref *ref)
static inline bool obs_weak_ref_get_ref(struct obs_weak_ref *ref)
{
long owners = ref->refs;
long owners = os_atomic_load_long(&ref->refs);
while (owners > -1) {
if (os_atomic_compare_swap_long(&ref->refs, owners, owners + 1))
if (os_atomic_compare_exchange_long(&ref->refs, &owners,
owners + 1)) {
return true;
owners = ref->refs;
}
}
return false;

View file

@ -1532,12 +1532,12 @@ void obs_scene_enum_items(obs_scene_t *scene,
static obs_sceneitem_t *sceneitem_get_ref(obs_sceneitem_t *si)
{
long owners = si->ref;
long owners = os_atomic_load_long(&si->ref);
while (owners > 0) {
if (os_atomic_compare_swap_long(&si->ref, owners, owners + 1))
if (os_atomic_compare_exchange_long(&si->ref, &owners,
owners + 1)) {
return si;
owners = si->ref;
}
}
return NULL;
}