mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-15 07:44:10 +00:00
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:
parent
5cf40bf818
commit
d48e77385c
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue