diff options
-rw-r--r-- | Alc/alc.cpp | 12 | ||||
-rw-r--r-- | Alc/hrtf.cpp | 4 | ||||
-rw-r--r-- | OpenAL32/alAuxEffectSlot.cpp | 6 | ||||
-rw-r--r-- | common/atomic.h | 17 |
4 files changed, 17 insertions, 22 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 24783510..6bb632f7 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -2476,15 +2476,13 @@ ALCdevice_struct::~ALCdevice_struct() void ALCdevice_IncRef(ALCdevice *device) { - uint ref; - ref = IncrementRef(&device->ref); + auto ref = IncrementRef(&device->ref); TRACEREF("%p increasing refcount to %u\n", device, ref); } void ALCdevice_DecRef(ALCdevice *device) { - uint ref; - ref = DecrementRef(&device->ref); + auto ref = DecrementRef(&device->ref); TRACEREF("%p decreasing refcount to %u\n", device, ref); if(ref == 0) delete device; } @@ -2728,20 +2726,20 @@ static bool ReleaseContext(ALCcontext *context, ALCdevice *device) static void ALCcontext_IncRef(ALCcontext *context) { - uint ref = IncrementRef(&context->ref); + auto ref = IncrementRef(&context->ref); TRACEREF("%p increasing refcount to %u\n", context, ref); } void ALCcontext_DecRef(ALCcontext *context) { - uint ref = DecrementRef(&context->ref); + auto ref = DecrementRef(&context->ref); TRACEREF("%p decreasing refcount to %u\n", context, ref); if(ref == 0) delete context; } static void ReleaseThreadCtx(ALCcontext *context) { - uint ref = DecrementRef(&context->ref); + auto ref = DecrementRef(&context->ref); TRACEREF("%p decreasing refcount to %u\n", context, ref); ERR("Context %p current for thread being destroyed, possible leak!\n", context); } diff --git a/Alc/hrtf.cpp b/Alc/hrtf.cpp index 0393da65..034d5a49 100644 --- a/Alc/hrtf.cpp +++ b/Alc/hrtf.cpp @@ -1257,13 +1257,13 @@ struct Hrtf *GetLoadedHrtf(struct HrtfEntry *entry) void Hrtf_IncRef(struct Hrtf *hrtf) { - uint ref = IncrementRef(&hrtf->ref); + auto ref = IncrementRef(&hrtf->ref); TRACEREF("%p increasing refcount to %u\n", hrtf, ref); } void Hrtf_DecRef(struct Hrtf *hrtf) { - uint ref = DecrementRef(&hrtf->ref); + auto ref = DecrementRef(&hrtf->ref); TRACEREF("%p decreasing refcount to %u\n", hrtf, ref); if(ref == 0) { diff --git a/OpenAL32/alAuxEffectSlot.cpp b/OpenAL32/alAuxEffectSlot.cpp index 037c99dd..9c11720e 100644 --- a/OpenAL32/alAuxEffectSlot.cpp +++ b/OpenAL32/alAuxEffectSlot.cpp @@ -545,15 +545,13 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect static void ALeffectState_IncRef(ALeffectState *state) { - uint ref; - ref = IncrementRef(&state->Ref); + auto ref = IncrementRef(&state->Ref); TRACEREF("%p increasing refcount to %u\n", state, ref); } void ALeffectState_DecRef(ALeffectState *state) { - uint ref; - ref = DecrementRef(&state->Ref); + auto ref = DecrementRef(&state->Ref); TRACEREF("%p decreasing refcount to %u\n", state, ref); if(ref == 0) DELETE_OBJ(state); } diff --git a/common/atomic.h b/common/atomic.h index 5e46436f..d1557ffb 100644 --- a/common/atomic.h +++ b/common/atomic.h @@ -74,17 +74,16 @@ using std::atomic_thread_fence; ATOMIC_COMPARE_EXCHANGE_WEAK(_val, _oldval, _newval, almemory_order_seq_cst, almemory_order_seq_cst) -typedef unsigned int uint; -typedef ATOMIC(uint) RefCount; +using RefCount = std::atomic<unsigned int>; -inline void InitRef(RefCount *ptr, uint value) +inline void InitRef(RefCount *ptr, unsigned int value) { ATOMIC_INIT(ptr, value); } -inline uint ReadRef(RefCount *ptr) -{ return ATOMIC_LOAD(ptr, almemory_order_acquire); } -inline uint IncrementRef(RefCount *ptr) -{ return ATOMIC_ADD(ptr, 1u, almemory_order_acq_rel)+1; } -inline uint DecrementRef(RefCount *ptr) -{ return ATOMIC_SUB(ptr, 1u, almemory_order_acq_rel)-1; } +inline unsigned int ReadRef(RefCount *ptr) +{ return ptr->load(std::memory_order_acquire); } +inline unsigned int IncrementRef(RefCount *ptr) +{ return ptr->fetch_add(1u, std::memory_order_acq_rel)+1u; } +inline unsigned int DecrementRef(RefCount *ptr) +{ return ptr->fetch_sub(1u, std::memory_order_acq_rel)-1u; } /* WARNING: A livelock is theoretically possible if another thread keeps |