1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-03-14 22:29:15 +01:00

[util] Add unlikely() around COM ref counting code

Improves code generation for the common case.
This commit is contained in:
Philip Rebohle 2019-06-02 23:34:53 +02:00
parent 818704d413
commit 19adccea8f

View File

@ -3,6 +3,8 @@
#include <atomic> #include <atomic>
#include "com_include.h" #include "com_include.h"
#include "../util_likely.h"
namespace dxvk { namespace dxvk {
@ -30,15 +32,15 @@ namespace dxvk {
virtual ~ComObject() { } virtual ~ComObject() { }
ULONG STDMETHODCALLTYPE AddRef() { ULONG STDMETHODCALLTYPE AddRef() {
ULONG refCount = m_refCount++; uint32_t refCount = m_refCount++;
if (refCount == 0ul) if (unlikely(!refCount))
AddRefPrivate(); AddRefPrivate();
return refCount + 1; return refCount + 1;
} }
ULONG STDMETHODCALLTYPE Release() { ULONG STDMETHODCALLTYPE Release() {
ULONG refCount = --m_refCount; uint32_t refCount = --m_refCount;
if (refCount == 0ul) if (unlikely(!refCount))
ReleasePrivate(); ReleasePrivate();
return refCount; return refCount;
} }
@ -50,7 +52,8 @@ namespace dxvk {
void ReleasePrivate() { void ReleasePrivate() {
if (--m_refPrivate == 0ul) { uint32_t refPrivate = --m_refPrivate;
if (unlikely(!refPrivate)) {
m_refPrivate += 0x80000000; m_refPrivate += 0x80000000;
delete this; delete this;
} }