Use macros for the likely/unlikely attributes

The syntax parser for GCC 8 (and earlier?) fails when these attributes are in
certain places.
This commit is contained in:
Chris Robinson 2023-03-01 11:35:39 -08:00
parent ec9c421d31
commit fde74453a6
33 changed files with 558 additions and 546 deletions

View File

@ -90,10 +90,10 @@ inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id) noexcept
const size_t lidx{(id-1) >> 6}; const size_t lidx{(id-1) >> 6};
const ALuint slidx{(id-1) & 0x3f}; const ALuint slidx{(id-1) & 0x3f};
if(lidx >= context->mEffectSlotList.size()) [[unlikely]] if(lidx >= context->mEffectSlotList.size()) UNLIKELY
return nullptr; return nullptr;
EffectSlotSubList &sublist{context->mEffectSlotList[lidx]}; EffectSlotSubList &sublist{context->mEffectSlotList[lidx]};
if(sublist.FreeMask & (1_u64 << slidx)) [[unlikely]] if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr; return nullptr;
return sublist.EffectSlots + slidx; return sublist.EffectSlots + slidx;
} }
@ -103,10 +103,10 @@ inline ALeffect *LookupEffect(ALCdevice *device, ALuint id) noexcept
const size_t lidx{(id-1) >> 6}; const size_t lidx{(id-1) >> 6};
const ALuint slidx{(id-1) & 0x3f}; const ALuint slidx{(id-1) & 0x3f};
if(lidx >= device->EffectList.size()) [[unlikely]] if(lidx >= device->EffectList.size()) UNLIKELY
return nullptr; return nullptr;
EffectSubList &sublist = device->EffectList[lidx]; EffectSubList &sublist = device->EffectList[lidx];
if(sublist.FreeMask & (1_u64 << slidx)) [[unlikely]] if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr; return nullptr;
return sublist.Effects + slidx; return sublist.Effects + slidx;
} }
@ -116,10 +116,10 @@ inline ALbuffer *LookupBuffer(ALCdevice *device, ALuint id) noexcept
const size_t lidx{(id-1) >> 6}; const size_t lidx{(id-1) >> 6};
const ALuint slidx{(id-1) & 0x3f}; const ALuint slidx{(id-1) & 0x3f};
if(lidx >= device->BufferList.size()) [[unlikely]] if(lidx >= device->BufferList.size()) UNLIKELY
return nullptr; return nullptr;
BufferSubList &sublist = device->BufferList[lidx]; BufferSubList &sublist = device->BufferList[lidx];
if(sublist.FreeMask & (1_u64 << slidx)) [[unlikely]] if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr; return nullptr;
return sublist.Buffers + slidx; return sublist.Buffers + slidx;
} }
@ -159,7 +159,7 @@ void AddActiveEffectSlots(const al::span<ALeffectslot*> auxslots, ALCcontext *co
/* Reallocate newarray if the new size ended up smaller from duplicate /* Reallocate newarray if the new size ended up smaller from duplicate
* removal. * removal.
*/ */
if(newcount < newarray->size()) [[unlikely]] if(newcount < newarray->size()) UNLIKELY
{ {
curarray = newarray; curarray = newarray;
newarray = EffectSlot::CreatePtrArray(newcount); newarray = EffectSlot::CreatePtrArray(newcount);
@ -197,7 +197,7 @@ void RemoveActiveEffectSlots(const al::span<ALeffectslot*> auxslots, ALCcontext
/* Reallocate with the new size. */ /* Reallocate with the new size. */
auto newsize = static_cast<size_t>(std::distance(newarray->begin(), new_end)); auto newsize = static_cast<size_t>(std::distance(newarray->begin(), new_end));
if(newsize != newarray->size()) [[likely]] if(newsize != newarray->size()) LIKELY
{ {
curarray = newarray; curarray = newarray;
newarray = EffectSlot::CreatePtrArray(newsize); newarray = EffectSlot::CreatePtrArray(newsize);
@ -251,7 +251,7 @@ bool EnsureEffectSlots(ALCcontext *context, size_t needed)
while(needed > count) while(needed > count)
{ {
if(context->mEffectSlotList.size() >= 1<<25) [[unlikely]] if(context->mEffectSlotList.size() >= 1<<25) UNLIKELY
return false; return false;
context->mEffectSlotList.emplace_back(); context->mEffectSlotList.emplace_back();
@ -259,7 +259,7 @@ bool EnsureEffectSlots(ALCcontext *context, size_t needed)
sublist->FreeMask = ~0_u64; sublist->FreeMask = ~0_u64;
sublist->EffectSlots = static_cast<ALeffectslot*>( sublist->EffectSlots = static_cast<ALeffectslot*>(
al_calloc(alignof(ALeffectslot), sizeof(ALeffectslot)*64)); al_calloc(alignof(ALeffectslot), sizeof(ALeffectslot)*64));
if(!sublist->EffectSlots) [[unlikely]] if(!sublist->EffectSlots) UNLIKELY
{ {
context->mEffectSlotList.pop_back(); context->mEffectSlotList.pop_back();
return false; return false;
@ -320,11 +320,11 @@ AL_API void AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(n < 0) [[unlikely]] if(n < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Generating %d effect slots", n); context->setError(AL_INVALID_VALUE, "Generating %d effect slots", n);
if(n <= 0) [[unlikely]] return; if(n <= 0) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mEffectSlotLock}; std::lock_guard<std::mutex> _{context->mEffectSlotLock};
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
@ -364,22 +364,22 @@ AL_API void AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, const ALuint *ef
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(n < 0) [[unlikely]] if(n < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Deleting %d effect slots", n); context->setError(AL_INVALID_VALUE, "Deleting %d effect slots", n);
if(n <= 0) [[unlikely]] return; if(n <= 0) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mEffectSlotLock}; std::lock_guard<std::mutex> _{context->mEffectSlotLock};
if(n == 1) if(n == 1)
{ {
ALeffectslot *slot{LookupEffectSlot(context.get(), effectslots[0])}; ALeffectslot *slot{LookupEffectSlot(context.get(), effectslots[0])};
if(!slot) [[unlikely]] if(!slot) UNLIKELY
{ {
context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslots[0]); context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslots[0]);
return; return;
} }
if(ReadRef(slot->ref) != 0) [[unlikely]] if(ReadRef(slot->ref) != 0) UNLIKELY
{ {
context->setError(AL_INVALID_OPERATION, "Deleting in-use effect slot %u", context->setError(AL_INVALID_OPERATION, "Deleting in-use effect slot %u",
effectslots[0]); effectslots[0]);
@ -394,12 +394,12 @@ START_API_FUNC
for(size_t i{0};i < slots.size();++i) for(size_t i{0};i < slots.size();++i)
{ {
ALeffectslot *slot{LookupEffectSlot(context.get(), effectslots[i])}; ALeffectslot *slot{LookupEffectSlot(context.get(), effectslots[i])};
if(!slot) [[unlikely]] if(!slot) UNLIKELY
{ {
context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslots[i]); context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslots[i]);
return; return;
} }
if(ReadRef(slot->ref) != 0) [[unlikely]] if(ReadRef(slot->ref) != 0) UNLIKELY
{ {
context->setError(AL_INVALID_OPERATION, "Deleting in-use effect slot %u", context->setError(AL_INVALID_OPERATION, "Deleting in-use effect slot %u",
effectslots[i]); effectslots[i]);
@ -428,7 +428,7 @@ AL_API ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(context) [[likely]] if(context) LIKELY
{ {
std::lock_guard<std::mutex> _{context->mEffectSlotLock}; std::lock_guard<std::mutex> _{context->mEffectSlotLock};
if(LookupEffectSlot(context.get(), effectslot) != nullptr) if(LookupEffectSlot(context.get(), effectslot) != nullptr)
@ -443,11 +443,11 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotPlaySOFT(ALuint slotid)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mEffectSlotLock}; std::lock_guard<std::mutex> _{context->mEffectSlotLock};
ALeffectslot *slot{LookupEffectSlot(context.get(), slotid)}; ALeffectslot *slot{LookupEffectSlot(context.get(), slotid)};
if(!slot) [[unlikely]] if(!slot) UNLIKELY
{ {
context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", slotid); context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", slotid);
return; return;
@ -467,18 +467,18 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotPlayvSOFT(ALsizei n, const ALuint *
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(n < 0) [[unlikely]] if(n < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Playing %d effect slots", n); context->setError(AL_INVALID_VALUE, "Playing %d effect slots", n);
if(n <= 0) [[unlikely]] return; if(n <= 0) UNLIKELY return;
auto slots = al::vector<ALeffectslot*>(static_cast<ALuint>(n)); auto slots = al::vector<ALeffectslot*>(static_cast<ALuint>(n));
std::lock_guard<std::mutex> _{context->mEffectSlotLock}; std::lock_guard<std::mutex> _{context->mEffectSlotLock};
for(size_t i{0};i < slots.size();++i) for(size_t i{0};i < slots.size();++i)
{ {
ALeffectslot *slot{LookupEffectSlot(context.get(), slotids[i])}; ALeffectslot *slot{LookupEffectSlot(context.get(), slotids[i])};
if(!slot) [[unlikely]] if(!slot) UNLIKELY
{ {
context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", slotids[i]); context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", slotids[i]);
return; return;
@ -502,11 +502,11 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotStopSOFT(ALuint slotid)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mEffectSlotLock}; std::lock_guard<std::mutex> _{context->mEffectSlotLock};
ALeffectslot *slot{LookupEffectSlot(context.get(), slotid)}; ALeffectslot *slot{LookupEffectSlot(context.get(), slotid)};
if(!slot) [[unlikely]] if(!slot) UNLIKELY
{ {
context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", slotid); context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", slotid);
return; return;
@ -521,18 +521,18 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotStopvSOFT(ALsizei n, const ALuint *
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(n < 0) [[unlikely]] if(n < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Stopping %d effect slots", n); context->setError(AL_INVALID_VALUE, "Stopping %d effect slots", n);
if(n <= 0) [[unlikely]] return; if(n <= 0) UNLIKELY return;
auto slots = al::vector<ALeffectslot*>(static_cast<ALuint>(n)); auto slots = al::vector<ALeffectslot*>(static_cast<ALuint>(n));
std::lock_guard<std::mutex> _{context->mEffectSlotLock}; std::lock_guard<std::mutex> _{context->mEffectSlotLock};
for(size_t i{0};i < slots.size();++i) for(size_t i{0};i < slots.size();++i)
{ {
ALeffectslot *slot{LookupEffectSlot(context.get(), slotids[i])}; ALeffectslot *slot{LookupEffectSlot(context.get(), slotids[i])};
if(!slot) [[unlikely]] if(!slot) UNLIKELY
{ {
context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", slotids[i]); context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", slotids[i]);
return; return;
@ -552,12 +552,12 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param,
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
std::lock_guard<std::mutex> __{context->mEffectSlotLock}; std::lock_guard<std::mutex> __{context->mEffectSlotLock};
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
if(!slot) [[unlikely]] if(!slot) UNLIKELY
return context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslot); return context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslot);
ALeffectslot *target{}; ALeffectslot *target{};
@ -580,12 +580,12 @@ START_API_FUNC
err = slot->initEffect(AL_EFFECT_NULL, EffectProps{}, context.get()); err = slot->initEffect(AL_EFFECT_NULL, EffectProps{}, context.get());
} }
} }
if(err != AL_NO_ERROR) [[unlikely]] if(err != AL_NO_ERROR) UNLIKELY
{ {
context->setError(err, "Effect initialization failed"); context->setError(err, "Effect initialization failed");
return; return;
} }
if(slot->mState == SlotState::Initial) [[unlikely]] if(slot->mState == SlotState::Initial) UNLIKELY
{ {
slot->mPropsDirty = false; slot->mPropsDirty = false;
slot->updateProps(context.get()); slot->updateProps(context.get());
@ -600,7 +600,7 @@ START_API_FUNC
if(!(value == AL_TRUE || value == AL_FALSE)) if(!(value == AL_TRUE || value == AL_FALSE))
return context->setError(AL_INVALID_VALUE, return context->setError(AL_INVALID_VALUE,
"Effect slot auxiliary send auto out of range"); "Effect slot auxiliary send auto out of range");
if(slot->AuxSendAuto == !!value) [[unlikely]] if(slot->AuxSendAuto == !!value) UNLIKELY
return; return;
slot->AuxSendAuto = !!value; slot->AuxSendAuto = !!value;
break; break;
@ -609,7 +609,7 @@ START_API_FUNC
target = LookupEffectSlot(context.get(), static_cast<ALuint>(value)); target = LookupEffectSlot(context.get(), static_cast<ALuint>(value));
if(value && !target) if(value && !target)
return context->setError(AL_INVALID_VALUE, "Invalid effect slot target ID"); return context->setError(AL_INVALID_VALUE, "Invalid effect slot target ID");
if(slot->Target == target) [[unlikely]] if(slot->Target == target) UNLIKELY
return; return;
if(target) if(target)
{ {
@ -647,10 +647,10 @@ START_API_FUNC
if(ALbuffer *buffer{slot->Buffer}) if(ALbuffer *buffer{slot->Buffer})
{ {
if(buffer->id == static_cast<ALuint>(value)) [[unlikely]] if(buffer->id == static_cast<ALuint>(value)) UNLIKELY
return; return;
} }
else if(value == 0) [[unlikely]] else if(value == 0) UNLIKELY
return; return;
{ {
@ -703,11 +703,11 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mEffectSlotLock}; std::lock_guard<std::mutex> _{context->mEffectSlotLock};
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
if(!slot) [[unlikely]] if(!slot) UNLIKELY
return context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslot); return context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslot);
switch(param) switch(param)
@ -723,12 +723,12 @@ AL_API void AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param,
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
std::lock_guard<std::mutex> __{context->mEffectSlotLock}; std::lock_guard<std::mutex> __{context->mEffectSlotLock};
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
if(!slot) [[unlikely]] if(!slot) UNLIKELY
return context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslot); return context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslot);
switch(param) switch(param)
@ -736,7 +736,7 @@ START_API_FUNC
case AL_EFFECTSLOT_GAIN: case AL_EFFECTSLOT_GAIN:
if(!(value >= 0.0f && value <= 1.0f)) if(!(value >= 0.0f && value <= 1.0f))
return context->setError(AL_INVALID_VALUE, "Effect slot gain out of range"); return context->setError(AL_INVALID_VALUE, "Effect slot gain out of range");
if(slot->Gain == value) [[unlikely]] if(slot->Gain == value) UNLIKELY
return; return;
slot->Gain = value; slot->Gain = value;
break; break;
@ -760,11 +760,11 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mEffectSlotLock}; std::lock_guard<std::mutex> _{context->mEffectSlotLock};
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
if(!slot) [[unlikely]] if(!slot) UNLIKELY
return context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslot); return context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslot);
switch(param) switch(param)
@ -781,11 +781,11 @@ AL_API void AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum para
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mEffectSlotLock}; std::lock_guard<std::mutex> _{context->mEffectSlotLock};
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
if(!slot) [[unlikely]] if(!slot) UNLIKELY
return context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslot); return context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslot);
switch(param) switch(param)
@ -833,11 +833,11 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mEffectSlotLock}; std::lock_guard<std::mutex> _{context->mEffectSlotLock};
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
if(!slot) [[unlikely]] if(!slot) UNLIKELY
return context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslot); return context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslot);
switch(param) switch(param)
@ -853,11 +853,11 @@ AL_API void AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum para
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mEffectSlotLock}; std::lock_guard<std::mutex> _{context->mEffectSlotLock};
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
if(!slot) [[unlikely]] if(!slot) UNLIKELY
return context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslot); return context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslot);
switch(param) switch(param)
@ -883,11 +883,11 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mEffectSlotLock}; std::lock_guard<std::mutex> _{context->mEffectSlotLock};
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
if(!slot) [[unlikely]] if(!slot) UNLIKELY
return context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslot); return context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", effectslot);
switch(param) switch(param)

View File

@ -225,14 +225,14 @@ bool EnsureBuffers(ALCdevice *device, size_t needed)
while(needed > count) while(needed > count)
{ {
if(device->BufferList.size() >= 1<<25) [[unlikely]] if(device->BufferList.size() >= 1<<25) UNLIKELY
return false; return false;
device->BufferList.emplace_back(); device->BufferList.emplace_back();
auto sublist = device->BufferList.end() - 1; auto sublist = device->BufferList.end() - 1;
sublist->FreeMask = ~0_u64; sublist->FreeMask = ~0_u64;
sublist->Buffers = static_cast<ALbuffer*>(al_calloc(alignof(ALbuffer), sizeof(ALbuffer)*64)); sublist->Buffers = static_cast<ALbuffer*>(al_calloc(alignof(ALbuffer), sizeof(ALbuffer)*64));
if(!sublist->Buffers) [[unlikely]] if(!sublist->Buffers) UNLIKELY
{ {
device->BufferList.pop_back(); device->BufferList.pop_back();
return false; return false;
@ -281,10 +281,10 @@ inline ALbuffer *LookupBuffer(ALCdevice *device, ALuint id)
const size_t lidx{(id-1) >> 6}; const size_t lidx{(id-1) >> 6};
const ALuint slidx{(id-1) & 0x3f}; const ALuint slidx{(id-1) & 0x3f};
if(lidx >= device->BufferList.size()) [[unlikely]] if(lidx >= device->BufferList.size()) UNLIKELY
return nullptr; return nullptr;
BufferSubList &sublist = device->BufferList[lidx]; BufferSubList &sublist = device->BufferList[lidx];
if(sublist.FreeMask & (1_u64 << slidx)) [[unlikely]] if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr; return nullptr;
return sublist.Buffers + slidx; return sublist.Buffers + slidx;
} }
@ -345,22 +345,22 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq, ALuint size,
UserFmtChannels SrcChannels, UserFmtType SrcType, const al::byte *SrcData, UserFmtChannels SrcChannels, UserFmtType SrcType, const al::byte *SrcData,
ALbitfieldSOFT access) ALbitfieldSOFT access)
{ {
if(ReadRef(ALBuf->ref) != 0 || ALBuf->MappedAccess != 0) [[unlikely]] if(ReadRef(ALBuf->ref) != 0 || ALBuf->MappedAccess != 0) UNLIKELY
return context->setError(AL_INVALID_OPERATION, "Modifying storage for in-use buffer %u", return context->setError(AL_INVALID_OPERATION, "Modifying storage for in-use buffer %u",
ALBuf->id); ALBuf->id);
/* Currently no channel configurations need to be converted. */ /* Currently no channel configurations need to be converted. */
auto DstChannels = FmtFromUserFmt(SrcChannels); auto DstChannels = FmtFromUserFmt(SrcChannels);
if(!DstChannels) [[unlikely]] if(!DstChannels) UNLIKELY
return context->setError(AL_INVALID_ENUM, "Invalid format"); return context->setError(AL_INVALID_ENUM, "Invalid format");
const auto DstType = FmtFromUserFmt(SrcType); const auto DstType = FmtFromUserFmt(SrcType);
if(!DstType) [[unlikely]] if(!DstType) UNLIKELY
return context->setError(AL_INVALID_ENUM, "Invalid format"); return context->setError(AL_INVALID_ENUM, "Invalid format");
const ALuint unpackalign{ALBuf->UnpackAlign}; const ALuint unpackalign{ALBuf->UnpackAlign};
const ALuint align{SanitizeAlignment(SrcType, unpackalign)}; const ALuint align{SanitizeAlignment(SrcType, unpackalign)};
if(align < 1) [[unlikely]] if(align < 1) UNLIKELY
return context->setError(AL_INVALID_VALUE, "Invalid unpack alignment %u for %s samples", return context->setError(AL_INVALID_VALUE, "Invalid unpack alignment %u for %s samples",
unpackalign, NameFromUserFmtType(SrcType)); unpackalign, NameFromUserFmtType(SrcType));
@ -370,11 +370,11 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq, ALuint size,
if((access&AL_PRESERVE_DATA_BIT_SOFT)) if((access&AL_PRESERVE_DATA_BIT_SOFT))
{ {
/* Can only preserve data with the same format and alignment. */ /* Can only preserve data with the same format and alignment. */
if(ALBuf->mChannels != *DstChannels || ALBuf->OriginalType != SrcType) [[unlikely]] if(ALBuf->mChannels != *DstChannels || ALBuf->OriginalType != SrcType) UNLIKELY
return context->setError(AL_INVALID_VALUE, "Preserving data of mismatched format"); return context->setError(AL_INVALID_VALUE, "Preserving data of mismatched format");
if(ALBuf->mBlockAlign != align) [[unlikely]] if(ALBuf->mBlockAlign != align) UNLIKELY
return context->setError(AL_INVALID_VALUE, "Preserving data of mismatched alignment"); return context->setError(AL_INVALID_VALUE, "Preserving data of mismatched alignment");
if(ALBuf->mAmbiOrder != ambiorder) [[unlikely]] if(ALBuf->mAmbiOrder != ambiorder) UNLIKELY
return context->setError(AL_INVALID_VALUE, "Preserving data of mismatched order"); return context->setError(AL_INVALID_VALUE, "Preserving data of mismatched order");
} }
@ -385,16 +385,16 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq, ALuint size,
((SrcType == UserFmtIMA4) ? (align-1)/2 + 4 : ((SrcType == UserFmtIMA4) ? (align-1)/2 + 4 :
(SrcType == UserFmtMSADPCM) ? (align-2)/2 + 7 : (SrcType == UserFmtMSADPCM) ? (align-2)/2 + 7 :
(align * BytesFromUserFmt(SrcType)))}; (align * BytesFromUserFmt(SrcType)))};
if((size%SrcBlockSize) != 0) [[unlikely]] if((size%SrcBlockSize) != 0) UNLIKELY
return context->setError(AL_INVALID_VALUE, return context->setError(AL_INVALID_VALUE,
"Data size %d is not a multiple of frame size %d (%d unpack alignment)", "Data size %d is not a multiple of frame size %d (%d unpack alignment)",
size, SrcBlockSize, align); size, SrcBlockSize, align);
const ALuint blocks{size / SrcBlockSize}; const ALuint blocks{size / SrcBlockSize};
if(blocks > std::numeric_limits<ALsizei>::max()/align) [[unlikely]] if(blocks > std::numeric_limits<ALsizei>::max()/align) UNLIKELY
return context->setError(AL_OUT_OF_MEMORY, return context->setError(AL_OUT_OF_MEMORY,
"Buffer size overflow, %d blocks x %d samples per block", blocks, align); "Buffer size overflow, %d blocks x %d samples per block", blocks, align);
if(blocks > std::numeric_limits<size_t>::max()/SrcBlockSize) [[unlikely]] if(blocks > std::numeric_limits<size_t>::max()/SrcBlockSize) UNLIKELY
return context->setError(AL_OUT_OF_MEMORY, return context->setError(AL_OUT_OF_MEMORY,
"Buffer size overflow, %d frames x %d bytes per frame", blocks, SrcBlockSize); "Buffer size overflow, %d frames x %d bytes per frame", blocks, SrcBlockSize);
@ -470,18 +470,18 @@ void PrepareCallback(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq,
UserFmtChannels SrcChannels, UserFmtType SrcType, ALBUFFERCALLBACKTYPESOFT callback, UserFmtChannels SrcChannels, UserFmtType SrcType, ALBUFFERCALLBACKTYPESOFT callback,
void *userptr) void *userptr)
{ {
if(ReadRef(ALBuf->ref) != 0 || ALBuf->MappedAccess != 0) [[unlikely]] if(ReadRef(ALBuf->ref) != 0 || ALBuf->MappedAccess != 0) UNLIKELY
return context->setError(AL_INVALID_OPERATION, "Modifying callback for in-use buffer %u", return context->setError(AL_INVALID_OPERATION, "Modifying callback for in-use buffer %u",
ALBuf->id); ALBuf->id);
/* Currently no channel configurations need to be converted. */ /* Currently no channel configurations need to be converted. */
const auto DstChannels = FmtFromUserFmt(SrcChannels); const auto DstChannels = FmtFromUserFmt(SrcChannels);
if(!DstChannels) [[unlikely]] if(!DstChannels) UNLIKELY
return context->setError(AL_INVALID_ENUM, "Invalid format"); return context->setError(AL_INVALID_ENUM, "Invalid format");
/* Formats that need conversion aren't supported with callbacks. */ /* Formats that need conversion aren't supported with callbacks. */
const auto DstType = FmtFromUserFmt(SrcType); const auto DstType = FmtFromUserFmt(SrcType);
if(!DstType) [[unlikely]] if(!DstType) UNLIKELY
return context->setError(AL_INVALID_ENUM, "Unsupported callback format"); return context->setError(AL_INVALID_ENUM, "Unsupported callback format");
const ALuint ambiorder{IsBFormat(*DstChannels) ? ALBuf->UnpackAmbiOrder : const ALuint ambiorder{IsBFormat(*DstChannels) ? ALBuf->UnpackAmbiOrder :
@ -627,11 +627,11 @@ AL_API void AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(n < 0) [[unlikely]] if(n < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Generating %d buffers", n); context->setError(AL_INVALID_VALUE, "Generating %d buffers", n);
if(n <= 0) [[unlikely]] return; if(n <= 0) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
@ -641,7 +641,7 @@ START_API_FUNC
return; return;
} }
if(n == 1) [[likely]] if(n == 1) LIKELY
{ {
/* Special handling for the easy and normal case. */ /* Special handling for the easy and normal case. */
ALbuffer *buffer{AllocBuffer(device)}; ALbuffer *buffer{AllocBuffer(device)};
@ -667,11 +667,11 @@ AL_API void AL_APIENTRY alDeleteBuffers(ALsizei n, const ALuint *buffers)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(n < 0) [[unlikely]] if(n < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Deleting %d buffers", n); context->setError(AL_INVALID_VALUE, "Deleting %d buffers", n);
if(n <= 0) [[unlikely]] return; if(n <= 0) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
@ -681,12 +681,12 @@ START_API_FUNC
{ {
if(!bid) return true; if(!bid) return true;
ALbuffer *ALBuf{LookupBuffer(device, bid)}; ALbuffer *ALBuf{LookupBuffer(device, bid)};
if(!ALBuf) [[unlikely]] if(!ALBuf) UNLIKELY
{ {
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", bid); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", bid);
return false; return false;
} }
if(ReadRef(ALBuf->ref) != 0) [[unlikely]] if(ReadRef(ALBuf->ref) != 0) UNLIKELY
{ {
context->setError(AL_INVALID_OPERATION, "Deleting in-use buffer %u", bid); context->setError(AL_INVALID_OPERATION, "Deleting in-use buffer %u", bid);
return false; return false;
@ -695,7 +695,7 @@ START_API_FUNC
}; };
const ALuint *buffers_end = buffers + n; const ALuint *buffers_end = buffers + n;
auto invbuf = std::find_if_not(buffers, buffers_end, validate_buffer); auto invbuf = std::find_if_not(buffers, buffers_end, validate_buffer);
if(invbuf != buffers_end) [[unlikely]] return; if(invbuf != buffers_end) UNLIKELY return;
/* All good. Delete non-0 buffer IDs. */ /* All good. Delete non-0 buffer IDs. */
auto delete_buffer = [device](const ALuint bid) -> void auto delete_buffer = [device](const ALuint bid) -> void
@ -711,7 +711,7 @@ AL_API ALboolean AL_APIENTRY alIsBuffer(ALuint buffer)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(context) [[likely]] if(context) LIKELY
{ {
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
@ -732,28 +732,28 @@ AL_API void AL_APIENTRY alBufferStorageSOFT(ALuint buffer, ALenum format, const
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
ALbuffer *albuf = LookupBuffer(device, buffer); ALbuffer *albuf = LookupBuffer(device, buffer);
if(!albuf) [[unlikely]] if(!albuf) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else if(size < 0) [[unlikely]] else if(size < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Negative storage size %d", size); context->setError(AL_INVALID_VALUE, "Negative storage size %d", size);
else if(freq < 1) [[unlikely]] else if(freq < 1) UNLIKELY
context->setError(AL_INVALID_VALUE, "Invalid sample rate %d", freq); context->setError(AL_INVALID_VALUE, "Invalid sample rate %d", freq);
else if((flags&INVALID_STORAGE_MASK) != 0) [[unlikely]] else if((flags&INVALID_STORAGE_MASK) != 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Invalid storage flags 0x%x", context->setError(AL_INVALID_VALUE, "Invalid storage flags 0x%x",
flags&INVALID_STORAGE_MASK); flags&INVALID_STORAGE_MASK);
else if((flags&AL_MAP_PERSISTENT_BIT_SOFT) && !(flags&MAP_READ_WRITE_FLAGS)) [[unlikely]] else if((flags&AL_MAP_PERSISTENT_BIT_SOFT) && !(flags&MAP_READ_WRITE_FLAGS)) UNLIKELY
context->setError(AL_INVALID_VALUE, context->setError(AL_INVALID_VALUE,
"Declaring persistently mapped storage without read or write access"); "Declaring persistently mapped storage without read or write access");
else else
{ {
auto usrfmt = DecomposeUserFormat(format); auto usrfmt = DecomposeUserFormat(format);
if(!usrfmt) [[unlikely]] if(!usrfmt) UNLIKELY
context->setError(AL_INVALID_ENUM, "Invalid format 0x%04x", format); context->setError(AL_INVALID_ENUM, "Invalid format 0x%04x", format);
else else
{ {
@ -768,40 +768,40 @@ AL_API void* AL_APIENTRY alMapBufferSOFT(ALuint buffer, ALsizei offset, ALsizei
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return nullptr; if(!context) UNLIKELY return nullptr;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
ALbuffer *albuf = LookupBuffer(device, buffer); ALbuffer *albuf = LookupBuffer(device, buffer);
if(!albuf) [[unlikely]] if(!albuf) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else if((access&INVALID_MAP_FLAGS) != 0) [[unlikely]] else if((access&INVALID_MAP_FLAGS) != 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Invalid map flags 0x%x", access&INVALID_MAP_FLAGS); context->setError(AL_INVALID_VALUE, "Invalid map flags 0x%x", access&INVALID_MAP_FLAGS);
else if(!(access&MAP_READ_WRITE_FLAGS)) [[unlikely]] else if(!(access&MAP_READ_WRITE_FLAGS)) UNLIKELY
context->setError(AL_INVALID_VALUE, "Mapping buffer %u without read or write access", context->setError(AL_INVALID_VALUE, "Mapping buffer %u without read or write access",
buffer); buffer);
else else
{ {
ALbitfieldSOFT unavailable = (albuf->Access^access) & access; ALbitfieldSOFT unavailable = (albuf->Access^access) & access;
if(ReadRef(albuf->ref) != 0 && !(access&AL_MAP_PERSISTENT_BIT_SOFT)) [[unlikely]] if(ReadRef(albuf->ref) != 0 && !(access&AL_MAP_PERSISTENT_BIT_SOFT)) UNLIKELY
context->setError(AL_INVALID_OPERATION, context->setError(AL_INVALID_OPERATION,
"Mapping in-use buffer %u without persistent mapping", buffer); "Mapping in-use buffer %u without persistent mapping", buffer);
else if(albuf->MappedAccess != 0) [[unlikely]] else if(albuf->MappedAccess != 0) UNLIKELY
context->setError(AL_INVALID_OPERATION, "Mapping already-mapped buffer %u", buffer); context->setError(AL_INVALID_OPERATION, "Mapping already-mapped buffer %u", buffer);
else if((unavailable&AL_MAP_READ_BIT_SOFT)) [[unlikely]] else if((unavailable&AL_MAP_READ_BIT_SOFT)) UNLIKELY
context->setError(AL_INVALID_VALUE, context->setError(AL_INVALID_VALUE,
"Mapping buffer %u for reading without read access", buffer); "Mapping buffer %u for reading without read access", buffer);
else if((unavailable&AL_MAP_WRITE_BIT_SOFT)) [[unlikely]] else if((unavailable&AL_MAP_WRITE_BIT_SOFT)) UNLIKELY
context->setError(AL_INVALID_VALUE, context->setError(AL_INVALID_VALUE,
"Mapping buffer %u for writing without write access", buffer); "Mapping buffer %u for writing without write access", buffer);
else if((unavailable&AL_MAP_PERSISTENT_BIT_SOFT)) [[unlikely]] else if((unavailable&AL_MAP_PERSISTENT_BIT_SOFT)) UNLIKELY
context->setError(AL_INVALID_VALUE, context->setError(AL_INVALID_VALUE,
"Mapping buffer %u persistently without persistent access", buffer); "Mapping buffer %u persistently without persistent access", buffer);
else if(offset < 0 || length <= 0 else if(offset < 0 || length <= 0
|| static_cast<ALuint>(offset) >= albuf->OriginalSize || static_cast<ALuint>(offset) >= albuf->OriginalSize
|| static_cast<ALuint>(length) > albuf->OriginalSize - static_cast<ALuint>(offset)) || static_cast<ALuint>(length) > albuf->OriginalSize - static_cast<ALuint>(offset))
[[unlikely]] UNLIKELY
context->setError(AL_INVALID_VALUE, "Mapping invalid range %d+%d for buffer %u", context->setError(AL_INVALID_VALUE, "Mapping invalid range %d+%d for buffer %u",
offset, length, buffer); offset, length, buffer);
else else
@ -822,15 +822,15 @@ AL_API void AL_APIENTRY alUnmapBufferSOFT(ALuint buffer)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
ALbuffer *albuf = LookupBuffer(device, buffer); ALbuffer *albuf = LookupBuffer(device, buffer);
if(!albuf) [[unlikely]] if(!albuf) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else if(albuf->MappedAccess == 0) [[unlikely]] else if(albuf->MappedAccess == 0) UNLIKELY
context->setError(AL_INVALID_OPERATION, "Unmapping unmapped buffer %u", buffer); context->setError(AL_INVALID_OPERATION, "Unmapping unmapped buffer %u", buffer);
else else
{ {
@ -845,20 +845,20 @@ AL_API void AL_APIENTRY alFlushMappedBufferSOFT(ALuint buffer, ALsizei offset, A
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
ALbuffer *albuf = LookupBuffer(device, buffer); ALbuffer *albuf = LookupBuffer(device, buffer);
if(!albuf) [[unlikely]] if(!albuf) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else if(!(albuf->MappedAccess&AL_MAP_WRITE_BIT_SOFT)) [[unlikely]] else if(!(albuf->MappedAccess&AL_MAP_WRITE_BIT_SOFT)) UNLIKELY
context->setError(AL_INVALID_OPERATION, "Flushing buffer %u while not mapped for writing", context->setError(AL_INVALID_OPERATION, "Flushing buffer %u while not mapped for writing",
buffer); buffer);
else if(offset < albuf->MappedOffset || length <= 0 else if(offset < albuf->MappedOffset || length <= 0
|| offset >= albuf->MappedOffset+albuf->MappedSize || offset >= albuf->MappedOffset+albuf->MappedSize
|| length > albuf->MappedOffset+albuf->MappedSize-offset) [[unlikely]] || length > albuf->MappedOffset+albuf->MappedSize-offset) UNLIKELY
context->setError(AL_INVALID_VALUE, "Flushing invalid range %d+%d on buffer %u", offset, context->setError(AL_INVALID_VALUE, "Flushing invalid range %d+%d on buffer %u", offset,
length, buffer); length, buffer);
else else
@ -877,34 +877,34 @@ AL_API void AL_APIENTRY alBufferSubDataSOFT(ALuint buffer, ALenum format, const
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
ALbuffer *albuf = LookupBuffer(device, buffer); ALbuffer *albuf = LookupBuffer(device, buffer);
if(!albuf) [[unlikely]] if(!albuf) UNLIKELY
return context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); return context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
auto usrfmt = DecomposeUserFormat(format); auto usrfmt = DecomposeUserFormat(format);
if(!usrfmt) [[unlikely]] if(!usrfmt) UNLIKELY
return context->setError(AL_INVALID_ENUM, "Invalid format 0x%04x", format); return context->setError(AL_INVALID_ENUM, "Invalid format 0x%04x", format);
const ALuint unpack_align{albuf->UnpackAlign}; const ALuint unpack_align{albuf->UnpackAlign};
const ALuint align{SanitizeAlignment(usrfmt->type, unpack_align)}; const ALuint align{SanitizeAlignment(usrfmt->type, unpack_align)};
if(align < 1) [[unlikely]] if(align < 1) UNLIKELY
return context->setError(AL_INVALID_VALUE, "Invalid unpack alignment %u", unpack_align); return context->setError(AL_INVALID_VALUE, "Invalid unpack alignment %u", unpack_align);
if(al::to_underlying(usrfmt->channels) != al::to_underlying(albuf->mChannels) if(al::to_underlying(usrfmt->channels) != al::to_underlying(albuf->mChannels)
|| usrfmt->type != albuf->OriginalType) [[unlikely]] || usrfmt->type != albuf->OriginalType) UNLIKELY
return context->setError(AL_INVALID_ENUM, "Unpacking data with mismatched format"); return context->setError(AL_INVALID_ENUM, "Unpacking data with mismatched format");
if(align != albuf->mBlockAlign) [[unlikely]] if(align != albuf->mBlockAlign) UNLIKELY
return context->setError(AL_INVALID_VALUE, return context->setError(AL_INVALID_VALUE,
"Unpacking data with alignment %u does not match original alignment %u", align, "Unpacking data with alignment %u does not match original alignment %u", align,
albuf->mBlockAlign); albuf->mBlockAlign);
if(albuf->isBFormat() && albuf->UnpackAmbiOrder != albuf->mAmbiOrder) [[unlikely]] if(albuf->isBFormat() && albuf->UnpackAmbiOrder != albuf->mAmbiOrder) UNLIKELY
return context->setError(AL_INVALID_VALUE, return context->setError(AL_INVALID_VALUE,
"Unpacking data with mismatched ambisonic order"); "Unpacking data with mismatched ambisonic order");
if(albuf->MappedAccess != 0) [[unlikely]] if(albuf->MappedAccess != 0) UNLIKELY
return context->setError(AL_INVALID_OPERATION, "Unpacking data into mapped buffer %u", return context->setError(AL_INVALID_OPERATION, "Unpacking data into mapped buffer %u",
buffer); buffer);
@ -916,14 +916,14 @@ START_API_FUNC
if(offset < 0 || length < 0 || static_cast<ALuint>(offset) > albuf->OriginalSize if(offset < 0 || length < 0 || static_cast<ALuint>(offset) > albuf->OriginalSize
|| static_cast<ALuint>(length) > albuf->OriginalSize-static_cast<ALuint>(offset)) || static_cast<ALuint>(length) > albuf->OriginalSize-static_cast<ALuint>(offset))
[[unlikely]] UNLIKELY
return context->setError(AL_INVALID_VALUE, "Invalid data sub-range %d+%d on buffer %u", return context->setError(AL_INVALID_VALUE, "Invalid data sub-range %d+%d on buffer %u",
offset, length, buffer); offset, length, buffer);
if((static_cast<ALuint>(offset)%byte_align) != 0) [[unlikely]] if((static_cast<ALuint>(offset)%byte_align) != 0) UNLIKELY
return context->setError(AL_INVALID_VALUE, return context->setError(AL_INVALID_VALUE,
"Sub-range offset %d is not a multiple of frame size %d (%d unpack alignment)", "Sub-range offset %d is not a multiple of frame size %d (%d unpack alignment)",
offset, byte_align, align); offset, byte_align, align);
if((static_cast<ALuint>(length)%byte_align) != 0) [[unlikely]] if((static_cast<ALuint>(length)%byte_align) != 0) UNLIKELY
return context->setError(AL_INVALID_VALUE, return context->setError(AL_INVALID_VALUE,
"Sub-range length %d is not a multiple of frame size %d (%d unpack alignment)", "Sub-range length %d is not a multiple of frame size %d (%d unpack alignment)",
length, byte_align, align); length, byte_align, align);
@ -940,7 +940,7 @@ AL_API void AL_APIENTRY alBufferSamplesSOFT(ALuint /*buffer*/, ALuint /*samplera
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
context->setError(AL_INVALID_OPERATION, "alBufferSamplesSOFT not supported"); context->setError(AL_INVALID_OPERATION, "alBufferSamplesSOFT not supported");
} }
@ -951,7 +951,7 @@ AL_API void AL_APIENTRY alBufferSubSamplesSOFT(ALuint /*buffer*/, ALsizei /*offs
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
context->setError(AL_INVALID_OPERATION, "alBufferSubSamplesSOFT not supported"); context->setError(AL_INVALID_OPERATION, "alBufferSubSamplesSOFT not supported");
} }
@ -962,7 +962,7 @@ AL_API void AL_APIENTRY alGetBufferSamplesSOFT(ALuint /*buffer*/, ALsizei /*offs
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
context->setError(AL_INVALID_OPERATION, "alGetBufferSamplesSOFT not supported"); context->setError(AL_INVALID_OPERATION, "alGetBufferSamplesSOFT not supported");
} }
@ -972,7 +972,7 @@ AL_API ALboolean AL_APIENTRY alIsBufferFormatSupportedSOFT(ALenum /*format*/)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return AL_FALSE; if(!context) UNLIKELY return AL_FALSE;
context->setError(AL_INVALID_OPERATION, "alIsBufferFormatSupportedSOFT not supported"); context->setError(AL_INVALID_OPERATION, "alIsBufferFormatSupportedSOFT not supported");
return AL_FALSE; return AL_FALSE;
@ -984,12 +984,12 @@ AL_API void AL_APIENTRY alBufferf(ALuint buffer, ALenum param, ALfloat /*value*/
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
if(LookupBuffer(device, buffer) == nullptr) [[unlikely]] if(LookupBuffer(device, buffer) == nullptr) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else switch(param) else switch(param)
{ {
@ -1004,12 +1004,12 @@ AL_API void AL_APIENTRY alBuffer3f(ALuint buffer, ALenum param,
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
if(LookupBuffer(device, buffer) == nullptr) [[unlikely]] if(LookupBuffer(device, buffer) == nullptr) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else switch(param) else switch(param)
{ {
@ -1023,14 +1023,14 @@ AL_API void AL_APIENTRY alBufferfv(ALuint buffer, ALenum param, const ALfloat *v
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
if(LookupBuffer(device, buffer) == nullptr) [[unlikely]] if(LookupBuffer(device, buffer) == nullptr) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else if(!values) [[unlikely]] else if(!values) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else switch(param) else switch(param)
{ {
@ -1045,53 +1045,53 @@ AL_API void AL_APIENTRY alBufferi(ALuint buffer, ALenum param, ALint value)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
ALbuffer *albuf = LookupBuffer(device, buffer); ALbuffer *albuf = LookupBuffer(device, buffer);
if(!albuf) [[unlikely]] if(!albuf) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else switch(param) else switch(param)
{ {
case AL_UNPACK_BLOCK_ALIGNMENT_SOFT: case AL_UNPACK_BLOCK_ALIGNMENT_SOFT:
if(value < 0) [[unlikely]] if(value < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Invalid unpack block alignment %d", value); context->setError(AL_INVALID_VALUE, "Invalid unpack block alignment %d", value);
else else
albuf->UnpackAlign = static_cast<ALuint>(value); albuf->UnpackAlign = static_cast<ALuint>(value);
break; break;
case AL_PACK_BLOCK_ALIGNMENT_SOFT: case AL_PACK_BLOCK_ALIGNMENT_SOFT:
if(value < 0) [[unlikely]] if(value < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Invalid pack block alignment %d", value); context->setError(AL_INVALID_VALUE, "Invalid pack block alignment %d", value);
else else
albuf->PackAlign = static_cast<ALuint>(value); albuf->PackAlign = static_cast<ALuint>(value);
break; break;
case AL_AMBISONIC_LAYOUT_SOFT: case AL_AMBISONIC_LAYOUT_SOFT:
if(ReadRef(albuf->ref) != 0) [[unlikely]] if(ReadRef(albuf->ref) != 0) UNLIKELY
context->setError(AL_INVALID_OPERATION, "Modifying in-use buffer %u's ambisonic layout", context->setError(AL_INVALID_OPERATION, "Modifying in-use buffer %u's ambisonic layout",
buffer); buffer);
else if(value != AL_FUMA_SOFT && value != AL_ACN_SOFT) [[unlikely]] else if(value != AL_FUMA_SOFT && value != AL_ACN_SOFT) UNLIKELY
context->setError(AL_INVALID_VALUE, "Invalid unpack ambisonic layout %04x", value); context->setError(AL_INVALID_VALUE, "Invalid unpack ambisonic layout %04x", value);
else else
albuf->mAmbiLayout = AmbiLayoutFromEnum(value).value(); albuf->mAmbiLayout = AmbiLayoutFromEnum(value).value();
break; break;
case AL_AMBISONIC_SCALING_SOFT: case AL_AMBISONIC_SCALING_SOFT:
if(ReadRef(albuf->ref) != 0) [[unlikely]] if(ReadRef(albuf->ref) != 0) UNLIKELY
context->setError(AL_INVALID_OPERATION, "Modifying in-use buffer %u's ambisonic scaling", context->setError(AL_INVALID_OPERATION, "Modifying in-use buffer %u's ambisonic scaling",
buffer); buffer);
else if(value != AL_FUMA_SOFT && value != AL_SN3D_SOFT && value != AL_N3D_SOFT) else if(value != AL_FUMA_SOFT && value != AL_SN3D_SOFT && value != AL_N3D_SOFT)
[[unlikely]] UNLIKELY
context->setError(AL_INVALID_VALUE, "Invalid unpack ambisonic scaling %04x", value); context->setError(AL_INVALID_VALUE, "Invalid unpack ambisonic scaling %04x", value);
else else
albuf->mAmbiScaling = AmbiScalingFromEnum(value).value(); albuf->mAmbiScaling = AmbiScalingFromEnum(value).value();
break; break;
case AL_UNPACK_AMBISONIC_ORDER_SOFT: case AL_UNPACK_AMBISONIC_ORDER_SOFT:
if(value < 1 || value > 14) [[unlikely]] if(value < 1 || value > 14) UNLIKELY
context->setError(AL_INVALID_VALUE, "Invalid unpack ambisonic order %d", value); context->setError(AL_INVALID_VALUE, "Invalid unpack ambisonic order %d", value);
else else
albuf->UnpackAmbiOrder = static_cast<ALuint>(value); albuf->UnpackAmbiOrder = static_cast<ALuint>(value);
@ -1108,12 +1108,12 @@ AL_API void AL_APIENTRY alBuffer3i(ALuint buffer, ALenum param,
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
if(LookupBuffer(device, buffer) == nullptr) [[unlikely]] if(LookupBuffer(device, buffer) == nullptr) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else switch(param) else switch(param)
{ {
@ -1141,24 +1141,24 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
ALbuffer *albuf = LookupBuffer(device, buffer); ALbuffer *albuf = LookupBuffer(device, buffer);
if(!albuf) [[unlikely]] if(!albuf) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else if(!values) [[unlikely]] else if(!values) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else switch(param) else switch(param)
{ {
case AL_LOOP_POINTS_SOFT: case AL_LOOP_POINTS_SOFT:
if(ReadRef(albuf->ref) != 0) [[unlikely]] if(ReadRef(albuf->ref) != 0) UNLIKELY
context->setError(AL_INVALID_OPERATION, "Modifying in-use buffer %u's loop points", context->setError(AL_INVALID_OPERATION, "Modifying in-use buffer %u's loop points",
buffer); buffer);
else if(values[0] < 0 || values[0] >= values[1] else if(values[0] < 0 || values[0] >= values[1]
|| static_cast<ALuint>(values[1]) > albuf->mSampleLen) [[unlikely]] || static_cast<ALuint>(values[1]) > albuf->mSampleLen) UNLIKELY
context->setError(AL_INVALID_VALUE, "Invalid loop point range %d -> %d on buffer %u", context->setError(AL_INVALID_VALUE, "Invalid loop point range %d -> %d on buffer %u",
values[0], values[1], buffer); values[0], values[1], buffer);
else else
@ -1179,15 +1179,15 @@ AL_API void AL_APIENTRY alGetBufferf(ALuint buffer, ALenum param, ALfloat *value
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
ALbuffer *albuf = LookupBuffer(device, buffer); ALbuffer *albuf = LookupBuffer(device, buffer);
if(!albuf) [[unlikely]] if(!albuf) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else if(!value) [[unlikely]] else if(!value) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else switch(param) else switch(param)
{ {
@ -1201,14 +1201,14 @@ AL_API void AL_APIENTRY alGetBuffer3f(ALuint buffer, ALenum param, ALfloat *valu
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
if(LookupBuffer(device, buffer) == nullptr) [[unlikely]] if(LookupBuffer(device, buffer) == nullptr) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else if(!value1 || !value2 || !value3) [[unlikely]] else if(!value1 || !value2 || !value3) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else switch(param) else switch(param)
{ {
@ -1229,14 +1229,14 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
if(LookupBuffer(device, buffer) == nullptr) [[unlikely]] if(LookupBuffer(device, buffer) == nullptr) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else if(!values) [[unlikely]] else if(!values) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else switch(param) else switch(param)
{ {
@ -1251,14 +1251,14 @@ AL_API void AL_APIENTRY alGetBufferi(ALuint buffer, ALenum param, ALint *value)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
ALbuffer *albuf = LookupBuffer(device, buffer); ALbuffer *albuf = LookupBuffer(device, buffer);
if(!albuf) [[unlikely]] if(!albuf) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else if(!value) [[unlikely]] else if(!value) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else switch(param) else switch(param)
{ {
@ -1310,13 +1310,13 @@ AL_API void AL_APIENTRY alGetBuffer3i(ALuint buffer, ALenum param, ALint *value1
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
if(LookupBuffer(device, buffer) == nullptr) [[unlikely]] if(LookupBuffer(device, buffer) == nullptr) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else if(!value1 || !value2 || !value3) [[unlikely]] else if(!value1 || !value2 || !value3) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else switch(param) else switch(param)
{ {
@ -1348,14 +1348,14 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
ALbuffer *albuf = LookupBuffer(device, buffer); ALbuffer *albuf = LookupBuffer(device, buffer);
if(!albuf) [[unlikely]] if(!albuf) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else if(!values) [[unlikely]] else if(!values) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else switch(param) else switch(param)
{ {
@ -1376,22 +1376,22 @@ AL_API void AL_APIENTRY alBufferCallbackSOFT(ALuint buffer, ALenum format, ALsiz
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
ALbuffer *albuf = LookupBuffer(device, buffer); ALbuffer *albuf = LookupBuffer(device, buffer);
if(!albuf) [[unlikely]] if(!albuf) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else if(freq < 1) [[unlikely]] else if(freq < 1) UNLIKELY
context->setError(AL_INVALID_VALUE, "Invalid sample rate %d", freq); context->setError(AL_INVALID_VALUE, "Invalid sample rate %d", freq);
else if(callback == nullptr) [[unlikely]] else if(callback == nullptr) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL callback"); context->setError(AL_INVALID_VALUE, "NULL callback");
else else
{ {
auto usrfmt = DecomposeUserFormat(format); auto usrfmt = DecomposeUserFormat(format);
if(!usrfmt) [[unlikely]] if(!usrfmt) UNLIKELY
context->setError(AL_INVALID_ENUM, "Invalid format 0x%04x", format); context->setError(AL_INVALID_ENUM, "Invalid format 0x%04x", format);
else else
PrepareCallback(context.get(), albuf, freq, usrfmt->channels, usrfmt->type, callback, PrepareCallback(context.get(), albuf, freq, usrfmt->channels, usrfmt->type, callback,
@ -1404,14 +1404,14 @@ AL_API void AL_APIENTRY alGetBufferPtrSOFT(ALuint buffer, ALenum param, ALvoid *
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
ALbuffer *albuf = LookupBuffer(device, buffer); ALbuffer *albuf = LookupBuffer(device, buffer);
if(!albuf) [[unlikely]] if(!albuf) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else if(!value) [[unlikely]] else if(!value) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else switch(param) else switch(param)
{ {
@ -1432,13 +1432,13 @@ AL_API void AL_APIENTRY alGetBuffer3PtrSOFT(ALuint buffer, ALenum param, ALvoid
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
if(LookupBuffer(device, buffer) == nullptr) [[unlikely]] if(LookupBuffer(device, buffer) == nullptr) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else if(!value1 || !value2 || !value3) [[unlikely]] else if(!value1 || !value2 || !value3) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else switch(param) else switch(param)
{ {
@ -1460,13 +1460,13 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->BufferLock}; std::lock_guard<std::mutex> _{device->BufferLock};
if(LookupBuffer(device, buffer) == nullptr) [[unlikely]] if(LookupBuffer(device, buffer) == nullptr) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
else if(!values) [[unlikely]] else if(!values) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else switch(param) else switch(param)
{ {
@ -1551,7 +1551,7 @@ START_API_FUNC
continue; continue;
const auto al_buffer = LookupBuffer(device, buffer); const auto al_buffer = LookupBuffer(device, buffer);
if(!al_buffer) [[unlikely]] if(!al_buffer) UNLIKELY
{ {
ERR(EAX_PREFIX "Invalid buffer ID %u.\n", buffer); ERR(EAX_PREFIX "Invalid buffer ID %u.\n", buffer);
return ALC_FALSE; return ALC_FALSE;
@ -1567,7 +1567,7 @@ START_API_FUNC
* buffer ID is specified multiple times in the provided list, it * buffer ID is specified multiple times in the provided list, it
* counts each instance as more memory that needs to fit in X-RAM. * counts each instance as more memory that needs to fit in X-RAM.
*/ */
if(std::numeric_limits<size_t>::max()-al_buffer->OriginalSize < total_needed) [[unlikely]] if(std::numeric_limits<size_t>::max()-al_buffer->OriginalSize < total_needed) UNLIKELY
{ {
context->setError(AL_OUT_OF_MEMORY, EAX_PREFIX "Buffer size overflow (%u + %zu)\n", context->setError(AL_OUT_OF_MEMORY, EAX_PREFIX "Buffer size overflow (%u + %zu)\n",
al_buffer->OriginalSize, total_needed); al_buffer->OriginalSize, total_needed);

View File

@ -167,14 +167,14 @@ bool EnsureEffects(ALCdevice *device, size_t needed)
while(needed > count) while(needed > count)
{ {
if(device->EffectList.size() >= 1<<25) [[unlikely]] if(device->EffectList.size() >= 1<<25) UNLIKELY
return false; return false;
device->EffectList.emplace_back(); device->EffectList.emplace_back();
auto sublist = device->EffectList.end() - 1; auto sublist = device->EffectList.end() - 1;
sublist->FreeMask = ~0_u64; sublist->FreeMask = ~0_u64;
sublist->Effects = static_cast<ALeffect*>(al_calloc(alignof(ALeffect), sizeof(ALeffect)*64)); sublist->Effects = static_cast<ALeffect*>(al_calloc(alignof(ALeffect), sizeof(ALeffect)*64));
if(!sublist->Effects) [[unlikely]] if(!sublist->Effects) UNLIKELY
{ {
device->EffectList.pop_back(); device->EffectList.pop_back();
return false; return false;
@ -220,10 +220,10 @@ inline ALeffect *LookupEffect(ALCdevice *device, ALuint id)
const size_t lidx{(id-1) >> 6}; const size_t lidx{(id-1) >> 6};
const ALuint slidx{(id-1) & 0x3f}; const ALuint slidx{(id-1) & 0x3f};
if(lidx >= device->EffectList.size()) [[unlikely]] if(lidx >= device->EffectList.size()) UNLIKELY
return nullptr; return nullptr;
EffectSubList &sublist = device->EffectList[lidx]; EffectSubList &sublist = device->EffectList[lidx];
if(sublist.FreeMask & (1_u64 << slidx)) [[unlikely]] if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr; return nullptr;
return sublist.Effects + slidx; return sublist.Effects + slidx;
} }
@ -234,11 +234,11 @@ AL_API void AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(n < 0) [[unlikely]] if(n < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Generating %d effects", n); context->setError(AL_INVALID_VALUE, "Generating %d effects", n);
if(n <= 0) [[unlikely]] return; if(n <= 0) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->EffectLock}; std::lock_guard<std::mutex> _{device->EffectLock};
@ -248,7 +248,7 @@ START_API_FUNC
return; return;
} }
if(n == 1) [[likely]] if(n == 1) LIKELY
{ {
/* Special handling for the easy and normal case. */ /* Special handling for the easy and normal case. */
ALeffect *effect{AllocEffect(device)}; ALeffect *effect{AllocEffect(device)};
@ -274,11 +274,11 @@ AL_API void AL_APIENTRY alDeleteEffects(ALsizei n, const ALuint *effects)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(n < 0) [[unlikely]] if(n < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Deleting %d effects", n); context->setError(AL_INVALID_VALUE, "Deleting %d effects", n);
if(n <= 0) [[unlikely]] return; if(n <= 0) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->EffectLock}; std::lock_guard<std::mutex> _{device->EffectLock};
@ -289,7 +289,7 @@ START_API_FUNC
const ALuint *effects_end = effects + n; const ALuint *effects_end = effects + n;
auto inveffect = std::find_if_not(effects, effects_end, validate_effect); auto inveffect = std::find_if_not(effects, effects_end, validate_effect);
if(inveffect != effects_end) [[unlikely]] if(inveffect != effects_end) UNLIKELY
{ {
context->setError(AL_INVALID_NAME, "Invalid effect ID %u", *inveffect); context->setError(AL_INVALID_NAME, "Invalid effect ID %u", *inveffect);
return; return;
@ -309,7 +309,7 @@ AL_API ALboolean AL_APIENTRY alIsEffect(ALuint effect)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(context) [[likely]] if(context) LIKELY
{ {
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->EffectLock}; std::lock_guard<std::mutex> _{device->EffectLock};
@ -324,13 +324,13 @@ AL_API void AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint value)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->EffectLock}; std::lock_guard<std::mutex> _{device->EffectLock};
ALeffect *aleffect{LookupEffect(device, effect)}; ALeffect *aleffect{LookupEffect(device, effect)};
if(!aleffect) [[unlikely]] if(!aleffect) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect);
else if(param == AL_EFFECT_TYPE) else if(param == AL_EFFECT_TYPE)
{ {
@ -374,13 +374,13 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->EffectLock}; std::lock_guard<std::mutex> _{device->EffectLock};
ALeffect *aleffect{LookupEffect(device, effect)}; ALeffect *aleffect{LookupEffect(device, effect)};
if(!aleffect) [[unlikely]] if(!aleffect) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect);
else try else try
{ {
@ -397,13 +397,13 @@ AL_API void AL_APIENTRY alEffectf(ALuint effect, ALenum param, ALfloat value)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->EffectLock}; std::lock_guard<std::mutex> _{device->EffectLock};
ALeffect *aleffect{LookupEffect(device, effect)}; ALeffect *aleffect{LookupEffect(device, effect)};
if(!aleffect) [[unlikely]] if(!aleffect) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect);
else try else try
{ {
@ -420,13 +420,13 @@ AL_API void AL_APIENTRY alEffectfv(ALuint effect, ALenum param, const ALfloat *v
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->EffectLock}; std::lock_guard<std::mutex> _{device->EffectLock};
ALeffect *aleffect{LookupEffect(device, effect)}; ALeffect *aleffect{LookupEffect(device, effect)};
if(!aleffect) [[unlikely]] if(!aleffect) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect);
else try else try
{ {
@ -443,13 +443,13 @@ AL_API void AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *value)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->EffectLock}; std::lock_guard<std::mutex> _{device->EffectLock};
const ALeffect *aleffect{LookupEffect(device, effect)}; const ALeffect *aleffect{LookupEffect(device, effect)};
if(!aleffect) [[unlikely]] if(!aleffect) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect);
else if(param == AL_EFFECT_TYPE) else if(param == AL_EFFECT_TYPE)
*value = aleffect->type; *value = aleffect->type;
@ -475,13 +475,13 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->EffectLock}; std::lock_guard<std::mutex> _{device->EffectLock};
const ALeffect *aleffect{LookupEffect(device, effect)}; const ALeffect *aleffect{LookupEffect(device, effect)};
if(!aleffect) [[unlikely]] if(!aleffect) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect);
else try else try
{ {
@ -498,13 +498,13 @@ AL_API void AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *value
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->EffectLock}; std::lock_guard<std::mutex> _{device->EffectLock};
const ALeffect *aleffect{LookupEffect(device, effect)}; const ALeffect *aleffect{LookupEffect(device, effect)};
if(!aleffect) [[unlikely]] if(!aleffect) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect);
else try else try
{ {
@ -521,13 +521,13 @@ AL_API void AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *valu
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->EffectLock}; std::lock_guard<std::mutex> _{device->EffectLock};
const ALeffect *aleffect{LookupEffect(device, effect)}; const ALeffect *aleffect{LookupEffect(device, effect)};
if(!aleffect) [[unlikely]] if(!aleffect) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect);
else try else try
{ {

View File

@ -85,7 +85,7 @@ AL_API ALenum AL_APIENTRY alGetError(void)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] if(!context) UNLIKELY
{ {
static constexpr ALenum deferror{AL_INVALID_OPERATION}; static constexpr ALenum deferror{AL_INVALID_OPERATION};
WARN("Querying error state on null context (implicitly 0x%04x)\n", deferror); WARN("Querying error state on null context (implicitly 0x%04x)\n", deferror);

View File

@ -55,7 +55,7 @@ static int EventThread(ALCcontext *context)
ring->readAdvance(1); ring->readAdvance(1);
quitnow = evt.EnumType == AsyncEvent::KillThread; quitnow = evt.EnumType == AsyncEvent::KillThread;
if(quitnow) [[unlikely]] break; if(quitnow) UNLIKELY break;
if(evt.EnumType == AsyncEvent::ReleaseEffectState) if(evt.EnumType == AsyncEvent::ReleaseEffectState)
{ {
@ -150,7 +150,7 @@ AL_API void AL_APIENTRY alEventControlSOFT(ALsizei count, const ALenum *types, A
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(count < 0) context->setError(AL_INVALID_VALUE, "Controlling %d events", count); if(count < 0) context->setError(AL_INVALID_VALUE, "Controlling %d events", count);
if(count <= 0) return; if(count <= 0) return;
@ -205,7 +205,7 @@ AL_API void AL_APIENTRY alEventCallbackSOFT(ALEVENTPROCSOFT callback, void *user
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
std::lock_guard<std::mutex> __{context->mEventCbLock}; std::lock_guard<std::mutex> __{context->mEventCbLock};

View File

@ -37,9 +37,9 @@ AL_API ALboolean AL_APIENTRY alIsExtensionPresent(const ALchar *extName)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return AL_FALSE; if(!context) UNLIKELY return AL_FALSE;
if(!extName) [[unlikely]] if(!extName) UNLIKELY
{ {
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
return AL_FALSE; return AL_FALSE;

View File

@ -336,14 +336,14 @@ bool EnsureFilters(ALCdevice *device, size_t needed)
while(needed > count) while(needed > count)
{ {
if(device->FilterList.size() >= 1<<25) [[unlikely]] if(device->FilterList.size() >= 1<<25) UNLIKELY
return false; return false;
device->FilterList.emplace_back(); device->FilterList.emplace_back();
auto sublist = device->FilterList.end() - 1; auto sublist = device->FilterList.end() - 1;
sublist->FreeMask = ~0_u64; sublist->FreeMask = ~0_u64;
sublist->Filters = static_cast<ALfilter*>(al_calloc(alignof(ALfilter), sizeof(ALfilter)*64)); sublist->Filters = static_cast<ALfilter*>(al_calloc(alignof(ALfilter), sizeof(ALfilter)*64));
if(!sublist->Filters) [[unlikely]] if(!sublist->Filters) UNLIKELY
{ {
device->FilterList.pop_back(); device->FilterList.pop_back();
return false; return false;
@ -391,10 +391,10 @@ inline ALfilter *LookupFilter(ALCdevice *device, ALuint id)
const size_t lidx{(id-1) >> 6}; const size_t lidx{(id-1) >> 6};
const ALuint slidx{(id-1) & 0x3f}; const ALuint slidx{(id-1) & 0x3f};
if(lidx >= device->FilterList.size()) [[unlikely]] if(lidx >= device->FilterList.size()) UNLIKELY
return nullptr; return nullptr;
FilterSubList &sublist = device->FilterList[lidx]; FilterSubList &sublist = device->FilterList[lidx];
if(sublist.FreeMask & (1_u64 << slidx)) [[unlikely]] if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr; return nullptr;
return sublist.Filters + slidx; return sublist.Filters + slidx;
} }
@ -405,11 +405,11 @@ AL_API void AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(n < 0) [[unlikely]] if(n < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Generating %d filters", n); context->setError(AL_INVALID_VALUE, "Generating %d filters", n);
if(n <= 0) [[unlikely]] return; if(n <= 0) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->FilterLock}; std::lock_guard<std::mutex> _{device->FilterLock};
@ -419,7 +419,7 @@ START_API_FUNC
return; return;
} }
if(n == 1) [[likely]] if(n == 1) LIKELY
{ {
/* Special handling for the easy and normal case. */ /* Special handling for the easy and normal case. */
ALfilter *filter{AllocFilter(device)}; ALfilter *filter{AllocFilter(device)};
@ -445,11 +445,11 @@ AL_API void AL_APIENTRY alDeleteFilters(ALsizei n, const ALuint *filters)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(n < 0) [[unlikely]] if(n < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Deleting %d filters", n); context->setError(AL_INVALID_VALUE, "Deleting %d filters", n);
if(n <= 0) [[unlikely]] return; if(n <= 0) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->FilterLock}; std::lock_guard<std::mutex> _{device->FilterLock};
@ -460,7 +460,7 @@ START_API_FUNC
const ALuint *filters_end = filters + n; const ALuint *filters_end = filters + n;
auto invflt = std::find_if_not(filters, filters_end, validate_filter); auto invflt = std::find_if_not(filters, filters_end, validate_filter);
if(invflt != filters_end) [[unlikely]] if(invflt != filters_end) UNLIKELY
{ {
context->setError(AL_INVALID_NAME, "Invalid filter ID %u", *invflt); context->setError(AL_INVALID_NAME, "Invalid filter ID %u", *invflt);
return; return;
@ -480,7 +480,7 @@ AL_API ALboolean AL_APIENTRY alIsFilter(ALuint filter)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(context) [[likely]] if(context) LIKELY
{ {
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->FilterLock}; std::lock_guard<std::mutex> _{device->FilterLock};
@ -496,13 +496,13 @@ AL_API void AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint value)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->FilterLock}; std::lock_guard<std::mutex> _{device->FilterLock};
ALfilter *alfilt{LookupFilter(device, filter)}; ALfilter *alfilt{LookupFilter(device, filter)};
if(!alfilt) [[unlikely]] if(!alfilt) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter);
else else
{ {
@ -537,13 +537,13 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->FilterLock}; std::lock_guard<std::mutex> _{device->FilterLock};
ALfilter *alfilt{LookupFilter(device, filter)}; ALfilter *alfilt{LookupFilter(device, filter)};
if(!alfilt) [[unlikely]] if(!alfilt) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter);
else try else try
{ {
@ -560,13 +560,13 @@ AL_API void AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat value)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->FilterLock}; std::lock_guard<std::mutex> _{device->FilterLock};
ALfilter *alfilt{LookupFilter(device, filter)}; ALfilter *alfilt{LookupFilter(device, filter)};
if(!alfilt) [[unlikely]] if(!alfilt) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter);
else try else try
{ {
@ -583,13 +583,13 @@ AL_API void AL_APIENTRY alFilterfv(ALuint filter, ALenum param, const ALfloat *v
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->FilterLock}; std::lock_guard<std::mutex> _{device->FilterLock};
ALfilter *alfilt{LookupFilter(device, filter)}; ALfilter *alfilt{LookupFilter(device, filter)};
if(!alfilt) [[unlikely]] if(!alfilt) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter);
else try else try
{ {
@ -606,13 +606,13 @@ AL_API void AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *value)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->FilterLock}; std::lock_guard<std::mutex> _{device->FilterLock};
const ALfilter *alfilt{LookupFilter(device, filter)}; const ALfilter *alfilt{LookupFilter(device, filter)};
if(!alfilt) [[unlikely]] if(!alfilt) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter);
else else
{ {
@ -641,13 +641,13 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->FilterLock}; std::lock_guard<std::mutex> _{device->FilterLock};
const ALfilter *alfilt{LookupFilter(device, filter)}; const ALfilter *alfilt{LookupFilter(device, filter)};
if(!alfilt) [[unlikely]] if(!alfilt) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter);
else try else try
{ {
@ -664,13 +664,13 @@ AL_API void AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *value
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->FilterLock}; std::lock_guard<std::mutex> _{device->FilterLock};
const ALfilter *alfilt{LookupFilter(device, filter)}; const ALfilter *alfilt{LookupFilter(device, filter)};
if(!alfilt) [[unlikely]] if(!alfilt) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter);
else try else try
{ {
@ -687,13 +687,13 @@ AL_API void AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *valu
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
std::lock_guard<std::mutex> _{device->FilterLock}; std::lock_guard<std::mutex> _{device->FilterLock};
const ALfilter *alfilt{LookupFilter(device, filter)}; const ALfilter *alfilt{LookupFilter(device, filter)};
if(!alfilt) [[unlikely]] if(!alfilt) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter);
else try else try
{ {

View File

@ -81,7 +81,7 @@ AL_API void AL_APIENTRY alListenerf(ALenum param, ALfloat value)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALlistener &listener = context->mListener; ALlistener &listener = context->mListener;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
@ -111,7 +111,7 @@ AL_API void AL_APIENTRY alListener3f(ALenum param, ALfloat value1, ALfloat value
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALlistener &listener = context->mListener; ALlistener &listener = context->mListener;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
@ -161,9 +161,9 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(!values) [[unlikely]] if(!values) UNLIKELY
return context->setError(AL_INVALID_VALUE, "NULL pointer"); return context->setError(AL_INVALID_VALUE, "NULL pointer");
ALlistener &listener = context->mListener; ALlistener &listener = context->mListener;
@ -195,7 +195,7 @@ AL_API void AL_APIENTRY alListeneri(ALenum param, ALint /*value*/)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
switch(param) switch(param)
@ -219,7 +219,7 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
switch(param) switch(param)
@ -257,10 +257,10 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
if(!values) [[unlikely]] if(!values) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else switch(param) else switch(param)
{ {
@ -275,7 +275,7 @@ AL_API void AL_APIENTRY alGetListenerf(ALenum param, ALfloat *value)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALlistener &listener = context->mListener; ALlistener &listener = context->mListener;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
@ -301,7 +301,7 @@ AL_API void AL_APIENTRY alGetListener3f(ALenum param, ALfloat *value1, ALfloat *
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALlistener &listener = context->mListener; ALlistener &listener = context->mListener;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
@ -344,7 +344,7 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALlistener &listener = context->mListener; ALlistener &listener = context->mListener;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
@ -373,7 +373,7 @@ AL_API void AL_APIENTRY alGetListeneri(ALenum param, ALint *value)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
if(!value) if(!value)
@ -390,7 +390,7 @@ AL_API void AL_APIENTRY alGetListener3i(ALenum param, ALint *value1, ALint *valu
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALlistener &listener = context->mListener; ALlistener &listener = context->mListener;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
@ -428,7 +428,7 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
ALlistener &listener = context->mListener; ALlistener &listener = context->mListener;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};

View File

@ -553,7 +553,7 @@ void InitVoice(Voice *voice, ALsource *source, ALbufferQueueItem *BufferList, AL
VoiceChange *GetVoiceChanger(ALCcontext *ctx) VoiceChange *GetVoiceChanger(ALCcontext *ctx)
{ {
VoiceChange *vchg{ctx->mVoiceChangeTail}; VoiceChange *vchg{ctx->mVoiceChangeTail};
if(vchg == ctx->mCurrentVoiceChange.load(std::memory_order_acquire)) [[unlikely]] if(vchg == ctx->mCurrentVoiceChange.load(std::memory_order_acquire)) UNLIKELY
{ {
ctx->allocVoiceChanges(); ctx->allocVoiceChanges();
vchg = ctx->mVoiceChangeTail; vchg = ctx->mVoiceChangeTail;
@ -575,7 +575,7 @@ void SendVoiceChanges(ALCcontext *ctx, VoiceChange *tail)
const bool connected{device->Connected.load(std::memory_order_acquire)}; const bool connected{device->Connected.load(std::memory_order_acquire)};
device->waitForMix(); device->waitForMix();
if(!connected) [[unlikely]] if(!connected) UNLIKELY
{ {
if(ctx->mStopVoicesOnDisconnect.load(std::memory_order_acquire)) if(ctx->mStopVoicesOnDisconnect.load(std::memory_order_acquire))
{ {
@ -613,7 +613,7 @@ bool SetVoiceOffset(Voice *oldvoice, const VoicePos &vpos, ALsource *source, ALC
} }
++vidx; ++vidx;
} }
if(!newvoice) [[unlikely]] if(!newvoice) UNLIKELY
{ {
auto &allvoices = *context->mVoices.load(std::memory_order_relaxed); auto &allvoices = *context->mVoices.load(std::memory_order_relaxed);
if(allvoices.size() == voicelist.size()) if(allvoices.size() == voicelist.size())
@ -670,7 +670,7 @@ bool SetVoiceOffset(Voice *oldvoice, const VoicePos &vpos, ALsource *source, ALC
/* If the old voice still has a sourceID, it's still active and the change- /* If the old voice still has a sourceID, it's still active and the change-
* over will work on the next update. * over will work on the next update.
*/ */
if(oldvoice->mSourceID.load(std::memory_order_acquire) != 0u) [[likely]] if(oldvoice->mSourceID.load(std::memory_order_acquire) != 0u) LIKELY
return true; return true;
/* Otherwise, if the new voice's state is not pending, the change-over /* Otherwise, if the new voice's state is not pending, the change-over
@ -723,14 +723,14 @@ bool EnsureSources(ALCcontext *context, size_t needed)
while(needed > count) while(needed > count)
{ {
if(context->mSourceList.size() >= 1<<25) [[unlikely]] if(context->mSourceList.size() >= 1<<25) UNLIKELY
return false; return false;
context->mSourceList.emplace_back(); context->mSourceList.emplace_back();
auto sublist = context->mSourceList.end() - 1; auto sublist = context->mSourceList.end() - 1;
sublist->FreeMask = ~0_u64; sublist->FreeMask = ~0_u64;
sublist->Sources = static_cast<ALsource*>(al_calloc(alignof(ALsource), sizeof(ALsource)*64)); sublist->Sources = static_cast<ALsource*>(al_calloc(alignof(ALsource), sizeof(ALsource)*64));
if(!sublist->Sources) [[unlikely]] if(!sublist->Sources) UNLIKELY
{ {
context->mSourceList.pop_back(); context->mSourceList.pop_back();
return false; return false;
@ -790,10 +790,10 @@ inline ALsource *LookupSource(ALCcontext *context, ALuint id) noexcept
const size_t lidx{(id-1) >> 6}; const size_t lidx{(id-1) >> 6};
const ALuint slidx{(id-1) & 0x3f}; const ALuint slidx{(id-1) & 0x3f};
if(lidx >= context->mSourceList.size()) [[unlikely]] if(lidx >= context->mSourceList.size()) UNLIKELY
return nullptr; return nullptr;
SourceSubList &sublist{context->mSourceList[lidx]}; SourceSubList &sublist{context->mSourceList[lidx]};
if(sublist.FreeMask & (1_u64 << slidx)) [[unlikely]] if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr; return nullptr;
return sublist.Sources + slidx; return sublist.Sources + slidx;
} }
@ -803,10 +803,10 @@ inline ALbuffer *LookupBuffer(ALCdevice *device, ALuint id) noexcept
const size_t lidx{(id-1) >> 6}; const size_t lidx{(id-1) >> 6};
const ALuint slidx{(id-1) & 0x3f}; const ALuint slidx{(id-1) & 0x3f};
if(lidx >= device->BufferList.size()) [[unlikely]] if(lidx >= device->BufferList.size()) UNLIKELY
return nullptr; return nullptr;
BufferSubList &sublist = device->BufferList[lidx]; BufferSubList &sublist = device->BufferList[lidx];
if(sublist.FreeMask & (1_u64 << slidx)) [[unlikely]] if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr; return nullptr;
return sublist.Buffers + slidx; return sublist.Buffers + slidx;
} }
@ -816,10 +816,10 @@ inline ALfilter *LookupFilter(ALCdevice *device, ALuint id) noexcept
const size_t lidx{(id-1) >> 6}; const size_t lidx{(id-1) >> 6};
const ALuint slidx{(id-1) & 0x3f}; const ALuint slidx{(id-1) & 0x3f};
if(lidx >= device->FilterList.size()) [[unlikely]] if(lidx >= device->FilterList.size()) UNLIKELY
return nullptr; return nullptr;
FilterSubList &sublist = device->FilterList[lidx]; FilterSubList &sublist = device->FilterList[lidx];
if(sublist.FreeMask & (1_u64 << slidx)) [[unlikely]] if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr; return nullptr;
return sublist.Filters + slidx; return sublist.Filters + slidx;
} }
@ -829,10 +829,10 @@ inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id) noexcept
const size_t lidx{(id-1) >> 6}; const size_t lidx{(id-1) >> 6};
const ALuint slidx{(id-1) & 0x3f}; const ALuint slidx{(id-1) & 0x3f};
if(lidx >= context->mEffectSlotList.size()) [[unlikely]] if(lidx >= context->mEffectSlotList.size()) UNLIKELY
return nullptr; return nullptr;
EffectSlotSubList &sublist{context->mEffectSlotList[lidx]}; EffectSlotSubList &sublist{context->mEffectSlotList[lidx]};
if(sublist.FreeMask & (1_u64 << slidx)) [[unlikely]] if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr; return nullptr;
return sublist.EffectSlots + slidx; return sublist.EffectSlots + slidx;
} }
@ -1212,14 +1212,14 @@ auto GetCheckers(ALCcontext *const Context, const SourceProp prop, const al::spa
return std::make_pair( return std::make_pair(
[=](size_t expect) -> void [=](size_t expect) -> void
{ {
if(values.size() == expect || values.size() == MaxValues) [[likely]] return; if(values.size() == expect || values.size() == MaxValues) LIKELY return;
Context->setError(AL_INVALID_ENUM, "Property 0x%04x expects %zu value(s), got %zu", Context->setError(AL_INVALID_ENUM, "Property 0x%04x expects %zu value(s), got %zu",
prop, expect, values.size()); prop, expect, values.size());
throw check_size_exception{}; throw check_size_exception{};
}, },
[Context](bool passed) -> void [Context](bool passed) -> void
{ {
if(passed) [[likely]] return; if(passed) LIKELY return;
Context->setError(AL_INVALID_VALUE, "Value out of range"); Context->setError(AL_INVALID_VALUE, "Value out of range");
throw check_value_exception{}; throw check_value_exception{};
} }
@ -1931,7 +1931,7 @@ auto GetSizeChecker(ALCcontext *const Context, const SourceProp prop, const al::
{ {
return [=](size_t expect) -> void return [=](size_t expect) -> void
{ {
if(values.size() == expect || values.size() == MaxValues) [[likely]] return; if(values.size() == expect || values.size() == MaxValues) LIKELY return;
Context->setError(AL_INVALID_ENUM, "Property 0x%04x expects %zu value(s), got %zu", Context->setError(AL_INVALID_ENUM, "Property 0x%04x expects %zu value(s), got %zu",
prop, expect, values.size()); prop, expect, values.size());
throw check_size_exception{}; throw check_size_exception{};
@ -2506,7 +2506,7 @@ void StartSources(ALCcontext *const context, const al::span<ALsource*> srchandle
/* If the device is disconnected, and voices stop on disconnect, go right /* If the device is disconnected, and voices stop on disconnect, go right
* to stopped. * to stopped.
*/ */
if(!device->Connected.load(std::memory_order_acquire)) [[unlikely]] if(!device->Connected.load(std::memory_order_acquire)) UNLIKELY
{ {
if(context->mStopVoicesOnDisconnect.load(std::memory_order_acquire)) if(context->mStopVoicesOnDisconnect.load(std::memory_order_acquire))
{ {
@ -2532,7 +2532,7 @@ void StartSources(ALCcontext *const context, const al::span<ALsource*> srchandle
if(free_voices == srchandles.size()) if(free_voices == srchandles.size())
break; break;
} }
if(srchandles.size() != free_voices) [[unlikely]] if(srchandles.size() != free_voices) UNLIKELY
{ {
const size_t inc_amount{srchandles.size() - free_voices}; const size_t inc_amount{srchandles.size() - free_voices};
auto &allvoices = *context->mVoices.load(std::memory_order_relaxed); auto &allvoices = *context->mVoices.load(std::memory_order_relaxed);
@ -2558,7 +2558,7 @@ void StartSources(ALCcontext *const context, const al::span<ALsource*> srchandle
auto BufferList = std::find_if(source->mQueue.begin(), source->mQueue.end(), find_buffer); auto BufferList = std::find_if(source->mQueue.begin(), source->mQueue.end(), find_buffer);
/* If there's nothing to play, go right to stopped. */ /* If there's nothing to play, go right to stopped. */
if(BufferList == source->mQueue.end()) [[unlikely]] if(BufferList == source->mQueue.end()) UNLIKELY
{ {
/* NOTE: A source without any playable buffers should not have a /* NOTE: A source without any playable buffers should not have a
* Voice since it shouldn't be in a playing or paused state. So * Voice since it shouldn't be in a playing or paused state. So
@ -2664,7 +2664,7 @@ void StartSources(ALCcontext *const context, const al::span<ALsource*> srchandle
cur->mSourceID = source->id; cur->mSourceID = source->id;
cur->mState = VChangeState::Play; cur->mState = VChangeState::Play;
} }
if(tail) [[likely]] if(tail) LIKELY
SendVoiceChanges(context, tail); SendVoiceChanges(context, tail);
} }
@ -2674,11 +2674,11 @@ AL_API void AL_APIENTRY alGenSources(ALsizei n, ALuint *sources)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(n < 0) [[unlikely]] if(n < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Generating %d sources", n); context->setError(AL_INVALID_VALUE, "Generating %d sources", n);
if(n <= 0) [[unlikely]] return; if(n <= 0) UNLIKELY return;
std::unique_lock<std::mutex> srclock{context->mSourceLock}; std::unique_lock<std::mutex> srclock{context->mSourceLock};
ALCdevice *device{context->mALDevice.get()}; ALCdevice *device{context->mALDevice.get()};
@ -2724,11 +2724,11 @@ AL_API void AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(n < 0) [[unlikely]] if(n < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Deleting %d sources", n); context->setError(AL_INVALID_VALUE, "Deleting %d sources", n);
if(n <= 0) [[unlikely]] return; if(n <= 0) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mSourceLock}; std::lock_guard<std::mutex> _{context->mSourceLock};
@ -2738,7 +2738,7 @@ START_API_FUNC
const ALuint *sources_end = sources + n; const ALuint *sources_end = sources + n;
auto invsrc = std::find_if_not(sources, sources_end, validate_source); auto invsrc = std::find_if_not(sources, sources_end, validate_source);
if(invsrc != sources_end) [[unlikely]] if(invsrc != sources_end) UNLIKELY
return context->setError(AL_INVALID_NAME, "Invalid source ID %u", *invsrc); return context->setError(AL_INVALID_NAME, "Invalid source ID %u", *invsrc);
/* All good. Delete source IDs. */ /* All good. Delete source IDs. */
@ -2755,7 +2755,7 @@ AL_API ALboolean AL_APIENTRY alIsSource(ALuint source)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(context) [[likely]] if(context) LIKELY
{ {
std::lock_guard<std::mutex> _{context->mSourceLock}; std::lock_guard<std::mutex> _{context->mSourceLock};
if(LookupSource(context.get(), source) != nullptr) if(LookupSource(context.get(), source) != nullptr)
@ -2770,12 +2770,12 @@ AL_API void AL_APIENTRY alSourcef(ALuint source, ALenum param, ALfloat value)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
std::lock_guard<std::mutex> __{context->mSourceLock}; std::lock_guard<std::mutex> __{context->mSourceLock};
ALsource *Source = LookupSource(context.get(), source); ALsource *Source = LookupSource(context.get(), source);
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else else
SetSourcefv(Source, context.get(), static_cast<SourceProp>(param), {&value, 1u}); SetSourcefv(Source, context.get(), static_cast<SourceProp>(param), {&value, 1u});
@ -2786,12 +2786,12 @@ AL_API void AL_APIENTRY alSource3f(ALuint source, ALenum param, ALfloat value1,
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
std::lock_guard<std::mutex> __{context->mSourceLock}; std::lock_guard<std::mutex> __{context->mSourceLock};
ALsource *Source = LookupSource(context.get(), source); ALsource *Source = LookupSource(context.get(), source);
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else else
{ {
@ -2805,14 +2805,14 @@ AL_API void AL_APIENTRY alSourcefv(ALuint source, ALenum param, const ALfloat *v
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
std::lock_guard<std::mutex> __{context->mSourceLock}; std::lock_guard<std::mutex> __{context->mSourceLock};
ALsource *Source = LookupSource(context.get(), source); ALsource *Source = LookupSource(context.get(), source);
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!values) [[unlikely]] else if(!values) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else else
SetSourcefv(Source, context.get(), static_cast<SourceProp>(param), {values, MaxValues}); SetSourcefv(Source, context.get(), static_cast<SourceProp>(param), {values, MaxValues});
@ -2824,12 +2824,12 @@ AL_API void AL_APIENTRY alSourcedSOFT(ALuint source, ALenum param, ALdouble valu
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
std::lock_guard<std::mutex> __{context->mSourceLock}; std::lock_guard<std::mutex> __{context->mSourceLock};
ALsource *Source = LookupSource(context.get(), source); ALsource *Source = LookupSource(context.get(), source);
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else else
{ {
@ -2843,12 +2843,12 @@ AL_API void AL_APIENTRY alSource3dSOFT(ALuint source, ALenum param, ALdouble val
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
std::lock_guard<std::mutex> __{context->mSourceLock}; std::lock_guard<std::mutex> __{context->mSourceLock};
ALsource *Source = LookupSource(context.get(), source); ALsource *Source = LookupSource(context.get(), source);
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else else
{ {
@ -2863,14 +2863,14 @@ AL_API void AL_APIENTRY alSourcedvSOFT(ALuint source, ALenum param, const ALdoub
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
std::lock_guard<std::mutex> __{context->mSourceLock}; std::lock_guard<std::mutex> __{context->mSourceLock};
ALsource *Source = LookupSource(context.get(), source); ALsource *Source = LookupSource(context.get(), source);
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!values) [[unlikely]] else if(!values) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else else
{ {
@ -2888,12 +2888,12 @@ AL_API void AL_APIENTRY alSourcei(ALuint source, ALenum param, ALint value)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
std::lock_guard<std::mutex> __{context->mSourceLock}; std::lock_guard<std::mutex> __{context->mSourceLock};
ALsource *Source = LookupSource(context.get(), source); ALsource *Source = LookupSource(context.get(), source);
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else else
SetSourceiv(Source, context.get(), static_cast<SourceProp>(param), {&value, 1u}); SetSourceiv(Source, context.get(), static_cast<SourceProp>(param), {&value, 1u});
@ -2904,12 +2904,12 @@ AL_API void AL_APIENTRY alSource3i(ALuint source, ALenum param, ALint value1, AL
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
std::lock_guard<std::mutex> __{context->mSourceLock}; std::lock_guard<std::mutex> __{context->mSourceLock};
ALsource *Source = LookupSource(context.get(), source); ALsource *Source = LookupSource(context.get(), source);
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else else
{ {
@ -2923,14 +2923,14 @@ AL_API void AL_APIENTRY alSourceiv(ALuint source, ALenum param, const ALint *val
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
std::lock_guard<std::mutex> __{context->mSourceLock}; std::lock_guard<std::mutex> __{context->mSourceLock};
ALsource *Source = LookupSource(context.get(), source); ALsource *Source = LookupSource(context.get(), source);
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!values) [[unlikely]] else if(!values) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else else
SetSourceiv(Source, context.get(), static_cast<SourceProp>(param), {values, MaxValues}); SetSourceiv(Source, context.get(), static_cast<SourceProp>(param), {values, MaxValues});
@ -2942,12 +2942,12 @@ AL_API void AL_APIENTRY alSourcei64SOFT(ALuint source, ALenum param, ALint64SOFT
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
std::lock_guard<std::mutex> __{context->mSourceLock}; std::lock_guard<std::mutex> __{context->mSourceLock};
ALsource *Source{LookupSource(context.get(), source)}; ALsource *Source{LookupSource(context.get(), source)};
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else else
SetSourcei64v(Source, context.get(), static_cast<SourceProp>(param), {&value, 1u}); SetSourcei64v(Source, context.get(), static_cast<SourceProp>(param), {&value, 1u});
@ -2958,12 +2958,12 @@ AL_API void AL_APIENTRY alSource3i64SOFT(ALuint source, ALenum param, ALint64SOF
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
std::lock_guard<std::mutex> __{context->mSourceLock}; std::lock_guard<std::mutex> __{context->mSourceLock};
ALsource *Source{LookupSource(context.get(), source)}; ALsource *Source{LookupSource(context.get(), source)};
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else else
{ {
@ -2977,14 +2977,14 @@ AL_API void AL_APIENTRY alSourcei64vSOFT(ALuint source, ALenum param, const ALin
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
std::lock_guard<std::mutex> __{context->mSourceLock}; std::lock_guard<std::mutex> __{context->mSourceLock};
ALsource *Source{LookupSource(context.get(), source)}; ALsource *Source{LookupSource(context.get(), source)};
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!values) [[unlikely]] else if(!values) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else else
SetSourcei64v(Source, context.get(), static_cast<SourceProp>(param), {values, MaxValues}); SetSourcei64v(Source, context.get(), static_cast<SourceProp>(param), {values, MaxValues});
@ -2996,13 +2996,13 @@ AL_API void AL_APIENTRY alGetSourcef(ALuint source, ALenum param, ALfloat *value
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mSourceLock}; std::lock_guard<std::mutex> _{context->mSourceLock};
ALsource *Source{LookupSource(context.get(), source)}; ALsource *Source{LookupSource(context.get(), source)};
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!value) [[unlikely]] else if(!value) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else else
{ {
@ -3017,13 +3017,13 @@ AL_API void AL_APIENTRY alGetSource3f(ALuint source, ALenum param, ALfloat *valu
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mSourceLock}; std::lock_guard<std::mutex> _{context->mSourceLock};
ALsource *Source{LookupSource(context.get(), source)}; ALsource *Source{LookupSource(context.get(), source)};
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!(value1 && value2 && value3)) [[unlikely]] else if(!(value1 && value2 && value3)) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else else
{ {
@ -3042,13 +3042,13 @@ AL_API void AL_APIENTRY alGetSourcefv(ALuint source, ALenum param, ALfloat *valu
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mSourceLock}; std::lock_guard<std::mutex> _{context->mSourceLock};
ALsource *Source{LookupSource(context.get(), source)}; ALsource *Source{LookupSource(context.get(), source)};
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!values) [[unlikely]] else if(!values) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else else
{ {
@ -3068,13 +3068,13 @@ AL_API void AL_APIENTRY alGetSourcedSOFT(ALuint source, ALenum param, ALdouble *
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mSourceLock}; std::lock_guard<std::mutex> _{context->mSourceLock};
ALsource *Source{LookupSource(context.get(), source)}; ALsource *Source{LookupSource(context.get(), source)};
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!value) [[unlikely]] else if(!value) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else else
GetSourcedv(Source, context.get(), static_cast<SourceProp>(param), {value, 1u}); GetSourcedv(Source, context.get(), static_cast<SourceProp>(param), {value, 1u});
@ -3085,13 +3085,13 @@ AL_API void AL_APIENTRY alGetSource3dSOFT(ALuint source, ALenum param, ALdouble
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mSourceLock}; std::lock_guard<std::mutex> _{context->mSourceLock};
ALsource *Source{LookupSource(context.get(), source)}; ALsource *Source{LookupSource(context.get(), source)};
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!(value1 && value2 && value3)) [[unlikely]] else if(!(value1 && value2 && value3)) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else else
{ {
@ -3110,13 +3110,13 @@ AL_API void AL_APIENTRY alGetSourcedvSOFT(ALuint source, ALenum param, ALdouble
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mSourceLock}; std::lock_guard<std::mutex> _{context->mSourceLock};
ALsource *Source{LookupSource(context.get(), source)}; ALsource *Source{LookupSource(context.get(), source)};
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!values) [[unlikely]] else if(!values) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else else
GetSourcedv(Source, context.get(), static_cast<SourceProp>(param), {values, MaxValues}); GetSourcedv(Source, context.get(), static_cast<SourceProp>(param), {values, MaxValues});
@ -3128,13 +3128,13 @@ AL_API void AL_APIENTRY alGetSourcei(ALuint source, ALenum param, ALint *value)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mSourceLock}; std::lock_guard<std::mutex> _{context->mSourceLock};
ALsource *Source{LookupSource(context.get(), source)}; ALsource *Source{LookupSource(context.get(), source)};
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!value) [[unlikely]] else if(!value) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else else
GetSourceiv(Source, context.get(), static_cast<SourceProp>(param), {value, 1u}); GetSourceiv(Source, context.get(), static_cast<SourceProp>(param), {value, 1u});
@ -3145,13 +3145,13 @@ AL_API void AL_APIENTRY alGetSource3i(ALuint source, ALenum param, ALint *value1
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mSourceLock}; std::lock_guard<std::mutex> _{context->mSourceLock};
ALsource *Source{LookupSource(context.get(), source)}; ALsource *Source{LookupSource(context.get(), source)};
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!(value1 && value2 && value3)) [[unlikely]] else if(!(value1 && value2 && value3)) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else else
{ {
@ -3170,13 +3170,13 @@ AL_API void AL_APIENTRY alGetSourceiv(ALuint source, ALenum param, ALint *values
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mSourceLock}; std::lock_guard<std::mutex> _{context->mSourceLock};
ALsource *Source{LookupSource(context.get(), source)}; ALsource *Source{LookupSource(context.get(), source)};
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!values) [[unlikely]] else if(!values) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else else
GetSourceiv(Source, context.get(), static_cast<SourceProp>(param), {values, MaxValues}); GetSourceiv(Source, context.get(), static_cast<SourceProp>(param), {values, MaxValues});
@ -3188,13 +3188,13 @@ AL_API void AL_APIENTRY alGetSourcei64SOFT(ALuint source, ALenum param, ALint64S
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mSourceLock}; std::lock_guard<std::mutex> _{context->mSourceLock};
ALsource *Source{LookupSource(context.get(), source)}; ALsource *Source{LookupSource(context.get(), source)};
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!value) [[unlikely]] else if(!value) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else else
GetSourcei64v(Source, context.get(), static_cast<SourceProp>(param), {value, 1u}); GetSourcei64v(Source, context.get(), static_cast<SourceProp>(param), {value, 1u});
@ -3205,13 +3205,13 @@ AL_API void AL_APIENTRY alGetSource3i64SOFT(ALuint source, ALenum param, ALint64
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mSourceLock}; std::lock_guard<std::mutex> _{context->mSourceLock};
ALsource *Source{LookupSource(context.get(), source)}; ALsource *Source{LookupSource(context.get(), source)};
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!(value1 && value2 && value3)) [[unlikely]] else if(!(value1 && value2 && value3)) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else else
{ {
@ -3230,13 +3230,13 @@ AL_API void AL_APIENTRY alGetSourcei64vSOFT(ALuint source, ALenum param, ALint64
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mSourceLock}; std::lock_guard<std::mutex> _{context->mSourceLock};
ALsource *Source{LookupSource(context.get(), source)}; ALsource *Source{LookupSource(context.get(), source)};
if(!Source) [[unlikely]] if(!Source) UNLIKELY
context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); context->setError(AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!values) [[unlikely]] else if(!values) UNLIKELY
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
else else
GetSourcei64v(Source, context.get(), static_cast<SourceProp>(param), {values, MaxValues}); GetSourcei64v(Source, context.get(), static_cast<SourceProp>(param), {values, MaxValues});
@ -3248,7 +3248,7 @@ AL_API void AL_APIENTRY alSourcePlay(ALuint source)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mSourceLock}; std::lock_guard<std::mutex> _{context->mSourceLock};
ALsource *srchandle{LookupSource(context.get(), source)}; ALsource *srchandle{LookupSource(context.get(), source)};
@ -3263,9 +3263,9 @@ void AL_APIENTRY alSourcePlayAtTimeSOFT(ALuint source, ALint64SOFT start_time)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(start_time < 0) [[unlikely]] if(start_time < 0) UNLIKELY
return context->setError(AL_INVALID_VALUE, "Invalid time point %" PRId64, start_time); return context->setError(AL_INVALID_VALUE, "Invalid time point %" PRId64, start_time);
std::lock_guard<std::mutex> _{context->mSourceLock}; std::lock_guard<std::mutex> _{context->mSourceLock};
@ -3281,16 +3281,16 @@ AL_API void AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(n < 0) [[unlikely]] if(n < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Playing %d sources", n); context->setError(AL_INVALID_VALUE, "Playing %d sources", n);
if(n <= 0) [[unlikely]] return; if(n <= 0) UNLIKELY return;
al::vector<ALsource*> extra_sources; al::vector<ALsource*> extra_sources;
std::array<ALsource*,8> source_storage; std::array<ALsource*,8> source_storage;
al::span<ALsource*> srchandles; al::span<ALsource*> srchandles;
if(static_cast<ALuint>(n) <= source_storage.size()) [[likely]] if(static_cast<ALuint>(n) <= source_storage.size()) LIKELY
srchandles = {source_storage.data(), static_cast<ALuint>(n)}; srchandles = {source_storage.data(), static_cast<ALuint>(n)};
else else
{ {
@ -3302,7 +3302,7 @@ START_API_FUNC
for(auto &srchdl : srchandles) for(auto &srchdl : srchandles)
{ {
srchdl = LookupSource(context.get(), *sources); srchdl = LookupSource(context.get(), *sources);
if(!srchdl) [[unlikely]] if(!srchdl) UNLIKELY
return context->setError(AL_INVALID_NAME, "Invalid source ID %u", *sources); return context->setError(AL_INVALID_NAME, "Invalid source ID %u", *sources);
++sources; ++sources;
} }
@ -3315,19 +3315,19 @@ void AL_APIENTRY alSourcePlayAtTimevSOFT(ALsizei n, const ALuint *sources, ALint
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(n < 0) [[unlikely]] if(n < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Playing %d sources", n); context->setError(AL_INVALID_VALUE, "Playing %d sources", n);
if(n <= 0) [[unlikely]] return; if(n <= 0) UNLIKELY return;
if(start_time < 0) [[unlikely]] if(start_time < 0) UNLIKELY
return context->setError(AL_INVALID_VALUE, "Invalid time point %" PRId64, start_time); return context->setError(AL_INVALID_VALUE, "Invalid time point %" PRId64, start_time);
al::vector<ALsource*> extra_sources; al::vector<ALsource*> extra_sources;
std::array<ALsource*,8> source_storage; std::array<ALsource*,8> source_storage;
al::span<ALsource*> srchandles; al::span<ALsource*> srchandles;
if(static_cast<ALuint>(n) <= source_storage.size()) [[likely]] if(static_cast<ALuint>(n) <= source_storage.size()) LIKELY
srchandles = {source_storage.data(), static_cast<ALuint>(n)}; srchandles = {source_storage.data(), static_cast<ALuint>(n)};
else else
{ {
@ -3358,16 +3358,16 @@ AL_API void AL_APIENTRY alSourcePausev(ALsizei n, const ALuint *sources)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(n < 0) [[unlikely]] if(n < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Pausing %d sources", n); context->setError(AL_INVALID_VALUE, "Pausing %d sources", n);
if(n <= 0) [[unlikely]] return; if(n <= 0) UNLIKELY return;
al::vector<ALsource*> extra_sources; al::vector<ALsource*> extra_sources;
std::array<ALsource*,8> source_storage; std::array<ALsource*,8> source_storage;
al::span<ALsource*> srchandles; al::span<ALsource*> srchandles;
if(static_cast<ALuint>(n) <= source_storage.size()) [[likely]] if(static_cast<ALuint>(n) <= source_storage.size()) LIKELY
srchandles = {source_storage.data(), static_cast<ALuint>(n)}; srchandles = {source_storage.data(), static_cast<ALuint>(n)};
else else
{ {
@ -3406,7 +3406,7 @@ START_API_FUNC
cur->mState = VChangeState::Pause; cur->mState = VChangeState::Pause;
} }
} }
if(tail) [[likely]] if(tail) LIKELY
{ {
SendVoiceChanges(context.get(), tail); SendVoiceChanges(context.get(), tail);
/* Second, now that the voice changes have been sent, because it's /* Second, now that the voice changes have been sent, because it's
@ -3434,16 +3434,16 @@ AL_API void AL_APIENTRY alSourceStopv(ALsizei n, const ALuint *sources)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(n < 0) [[unlikely]] if(n < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Stopping %d sources", n); context->setError(AL_INVALID_VALUE, "Stopping %d sources", n);
if(n <= 0) [[unlikely]] return; if(n <= 0) UNLIKELY return;
al::vector<ALsource*> extra_sources; al::vector<ALsource*> extra_sources;
std::array<ALsource*,8> source_storage; std::array<ALsource*,8> source_storage;
al::span<ALsource*> srchandles; al::span<ALsource*> srchandles;
if(static_cast<ALuint>(n) <= source_storage.size()) [[likely]] if(static_cast<ALuint>(n) <= source_storage.size()) LIKELY
srchandles = {source_storage.data(), static_cast<ALuint>(n)}; srchandles = {source_storage.data(), static_cast<ALuint>(n)};
else else
{ {
@ -3482,7 +3482,7 @@ START_API_FUNC
source->OffsetType = AL_NONE; source->OffsetType = AL_NONE;
source->VoiceIdx = INVALID_VOICE_IDX; source->VoiceIdx = INVALID_VOICE_IDX;
} }
if(tail) [[likely]] if(tail) LIKELY
SendVoiceChanges(context.get(), tail); SendVoiceChanges(context.get(), tail);
} }
END_API_FUNC END_API_FUNC
@ -3497,16 +3497,16 @@ AL_API void AL_APIENTRY alSourceRewindv(ALsizei n, const ALuint *sources)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(n < 0) [[unlikely]] if(n < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Rewinding %d sources", n); context->setError(AL_INVALID_VALUE, "Rewinding %d sources", n);
if(n <= 0) [[unlikely]] return; if(n <= 0) UNLIKELY return;
al::vector<ALsource*> extra_sources; al::vector<ALsource*> extra_sources;
std::array<ALsource*,8> source_storage; std::array<ALsource*,8> source_storage;
al::span<ALsource*> srchandles; al::span<ALsource*> srchandles;
if(static_cast<ALuint>(n) <= source_storage.size()) [[likely]] if(static_cast<ALuint>(n) <= source_storage.size()) LIKELY
srchandles = {source_storage.data(), static_cast<ALuint>(n)}; srchandles = {source_storage.data(), static_cast<ALuint>(n)};
else else
{ {
@ -3547,7 +3547,7 @@ START_API_FUNC
source->OffsetType = AL_NONE; source->OffsetType = AL_NONE;
source->VoiceIdx = INVALID_VOICE_IDX; source->VoiceIdx = INVALID_VOICE_IDX;
} }
if(tail) [[likely]] if(tail) LIKELY
SendVoiceChanges(context.get(), tail); SendVoiceChanges(context.get(), tail);
} }
END_API_FUNC END_API_FUNC
@ -3557,19 +3557,19 @@ AL_API void AL_APIENTRY alSourceQueueBuffers(ALuint src, ALsizei nb, const ALuin
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(nb < 0) [[unlikely]] if(nb < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Queueing %d buffers", nb); context->setError(AL_INVALID_VALUE, "Queueing %d buffers", nb);
if(nb <= 0) [[unlikely]] return; if(nb <= 0) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mSourceLock}; std::lock_guard<std::mutex> _{context->mSourceLock};
ALsource *source{LookupSource(context.get(),src)}; ALsource *source{LookupSource(context.get(),src)};
if(!source) [[unlikely]] if(!source) UNLIKELY
return context->setError(AL_INVALID_NAME, "Invalid source ID %u", src); return context->setError(AL_INVALID_NAME, "Invalid source ID %u", src);
/* Can't queue on a Static Source */ /* Can't queue on a Static Source */
if(source->SourceType == AL_STATIC) [[unlikely]] if(source->SourceType == AL_STATIC) UNLIKELY
return context->setError(AL_INVALID_OPERATION, "Queueing onto static source %u", src); return context->setError(AL_INVALID_OPERATION, "Queueing onto static source %u", src);
/* Check for a valid Buffer, for its frequency and format */ /* Check for a valid Buffer, for its frequency and format */
@ -3637,7 +3637,7 @@ START_API_FUNC
fmt_mismatch |= BufferFmt->mAmbiOrder != buffer->mAmbiOrder; fmt_mismatch |= BufferFmt->mAmbiOrder != buffer->mAmbiOrder;
fmt_mismatch |= BufferFmt->OriginalType != buffer->OriginalType; fmt_mismatch |= BufferFmt->OriginalType != buffer->OriginalType;
} }
if(fmt_mismatch) [[unlikely]] if(fmt_mismatch) UNLIKELY
{ {
context->setError(AL_INVALID_OPERATION, "Queueing buffer with mismatched format"); context->setError(AL_INVALID_OPERATION, "Queueing buffer with mismatched format");
@ -3673,26 +3673,26 @@ AL_API void AL_APIENTRY alSourceUnqueueBuffers(ALuint src, ALsizei nb, ALuint *b
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(nb < 0) [[unlikely]] if(nb < 0) UNLIKELY
context->setError(AL_INVALID_VALUE, "Unqueueing %d buffers", nb); context->setError(AL_INVALID_VALUE, "Unqueueing %d buffers", nb);
if(nb <= 0) [[unlikely]] return; if(nb <= 0) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mSourceLock}; std::lock_guard<std::mutex> _{context->mSourceLock};
ALsource *source{LookupSource(context.get(),src)}; ALsource *source{LookupSource(context.get(),src)};
if(!source) [[unlikely]] if(!source) UNLIKELY
return context->setError(AL_INVALID_NAME, "Invalid source ID %u", src); return context->setError(AL_INVALID_NAME, "Invalid source ID %u", src);
if(source->SourceType != AL_STREAMING) [[unlikely]] if(source->SourceType != AL_STREAMING) UNLIKELY
return context->setError(AL_INVALID_VALUE, "Unqueueing from a non-streaming source %u", return context->setError(AL_INVALID_VALUE, "Unqueueing from a non-streaming source %u",
src); src);
if(source->Looping) [[unlikely]] if(source->Looping) UNLIKELY
return context->setError(AL_INVALID_VALUE, "Unqueueing from looping source %u", src); return context->setError(AL_INVALID_VALUE, "Unqueueing from looping source %u", src);
/* Make sure enough buffers have been processed to unqueue. */ /* Make sure enough buffers have been processed to unqueue. */
uint processed{0u}; uint processed{0u};
if(source->state != AL_INITIAL) [[likely]] if(source->state != AL_INITIAL) LIKELY
{ {
VoiceBufferItem *Current{nullptr}; VoiceBufferItem *Current{nullptr};
if(Voice *voice{GetSourceVoice(source, context.get())}) if(Voice *voice{GetSourceVoice(source, context.get())})
@ -3704,7 +3704,7 @@ START_API_FUNC
++processed; ++processed;
} }
} }
if(processed < static_cast<ALuint>(nb)) [[unlikely]] if(processed < static_cast<ALuint>(nb)) UNLIKELY
return context->setError(AL_INVALID_VALUE, "Unqueueing %d buffer%s (only %u processed)", return context->setError(AL_INVALID_VALUE, "Unqueueing %d buffer%s (only %u processed)",
nb, (nb==1)?"":"s", processed); nb, (nb==1)?"":"s", processed);
@ -3727,7 +3727,7 @@ AL_API void AL_APIENTRY alSourceQueueBufferLayersSOFT(ALuint, ALsizei, const ALu
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
context->setError(AL_INVALID_OPERATION, "alSourceQueueBufferLayersSOFT not supported"); context->setError(AL_INVALID_OPERATION, "alSourceQueueBufferLayersSOFT not supported");
} }

View File

@ -158,7 +158,7 @@ AL_API void AL_APIENTRY alEnable(ALenum capability)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
switch(capability) switch(capability)
{ {
@ -184,7 +184,7 @@ AL_API void AL_APIENTRY alDisable(ALenum capability)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
switch(capability) switch(capability)
{ {
@ -210,7 +210,7 @@ AL_API ALboolean AL_APIENTRY alIsEnabled(ALenum capability)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return AL_FALSE; if(!context) UNLIKELY return AL_FALSE;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
ALboolean value{AL_FALSE}; ALboolean value{AL_FALSE};
@ -236,7 +236,7 @@ AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum pname)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return AL_FALSE; if(!context) UNLIKELY return AL_FALSE;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
ALboolean value{AL_FALSE}; ALboolean value{AL_FALSE};
@ -293,7 +293,7 @@ AL_API ALdouble AL_APIENTRY alGetDouble(ALenum pname)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return 0.0; if(!context) UNLIKELY return 0.0;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
ALdouble value{0.0}; ALdouble value{0.0};
@ -344,7 +344,7 @@ AL_API ALfloat AL_APIENTRY alGetFloat(ALenum pname)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return 0.0f; if(!context) UNLIKELY return 0.0f;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
ALfloat value{0.0f}; ALfloat value{0.0f};
@ -395,7 +395,7 @@ AL_API ALint AL_APIENTRY alGetInteger(ALenum pname)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return 0; if(!context) UNLIKELY return 0;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
ALint value{0}; ALint value{0};
@ -481,7 +481,7 @@ AL_API ALint64SOFT AL_APIENTRY alGetInteger64SOFT(ALenum pname)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return 0_i64; if(!context) UNLIKELY return 0_i64;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
ALint64SOFT value{0}; ALint64SOFT value{0};
@ -532,7 +532,7 @@ AL_API ALvoid* AL_APIENTRY alGetPointerSOFT(ALenum pname)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return nullptr; if(!context) UNLIKELY return nullptr;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
void *value{nullptr}; void *value{nullptr};
@ -575,7 +575,7 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(!values) if(!values)
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
@ -608,7 +608,7 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(!values) if(!values)
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
@ -641,7 +641,7 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(!values) if(!values)
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
@ -674,7 +674,7 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(!values) if(!values)
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
@ -707,7 +707,7 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(!values) if(!values)
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
@ -734,7 +734,7 @@ START_API_FUNC
} }
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(!values) if(!values)
context->setError(AL_INVALID_VALUE, "NULL pointer"); context->setError(AL_INVALID_VALUE, "NULL pointer");
@ -750,7 +750,7 @@ AL_API const ALchar* AL_APIENTRY alGetString(ALenum pname)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return nullptr; if(!context) UNLIKELY return nullptr;
const ALchar *value{nullptr}; const ALchar *value{nullptr};
switch(pname) switch(pname)
@ -806,7 +806,7 @@ AL_API void AL_APIENTRY alDopplerFactor(ALfloat value)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(!(value >= 0.0f && std::isfinite(value))) if(!(value >= 0.0f && std::isfinite(value)))
context->setError(AL_INVALID_VALUE, "Doppler factor %f out of range", value); context->setError(AL_INVALID_VALUE, "Doppler factor %f out of range", value);
@ -823,7 +823,7 @@ AL_API void AL_APIENTRY alDopplerVelocity(ALfloat value)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(!(value >= 0.0f && std::isfinite(value))) if(!(value >= 0.0f && std::isfinite(value)))
context->setError(AL_INVALID_VALUE, "Doppler velocity %f out of range", value); context->setError(AL_INVALID_VALUE, "Doppler velocity %f out of range", value);
@ -840,7 +840,7 @@ AL_API void AL_APIENTRY alSpeedOfSound(ALfloat value)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(!(value > 0.0f && std::isfinite(value))) if(!(value > 0.0f && std::isfinite(value)))
context->setError(AL_INVALID_VALUE, "Speed of sound %f out of range", value); context->setError(AL_INVALID_VALUE, "Speed of sound %f out of range", value);
@ -857,7 +857,7 @@ AL_API void AL_APIENTRY alDistanceModel(ALenum value)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
if(auto model = DistanceModelFromALenum(value)) if(auto model = DistanceModelFromALenum(value))
{ {
@ -876,7 +876,7 @@ AL_API void AL_APIENTRY alDeferUpdatesSOFT(void)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
context->deferUpdates(); context->deferUpdates();
@ -887,7 +887,7 @@ AL_API void AL_APIENTRY alProcessUpdatesSOFT(void)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return; if(!context) UNLIKELY return;
std::lock_guard<std::mutex> _{context->mPropLock}; std::lock_guard<std::mutex> _{context->mPropLock};
context->processUpdates(); context->processUpdates();
@ -899,7 +899,7 @@ AL_API const ALchar* AL_APIENTRY alGetStringiSOFT(ALenum pname, ALsizei index)
START_API_FUNC START_API_FUNC
{ {
ContextRef context{GetContextRef()}; ContextRef context{GetContextRef()};
if(!context) [[unlikely]] return nullptr; if(!context) UNLIKELY return nullptr;
const ALchar *value{nullptr}; const ALchar *value{nullptr};
switch(pname) switch(pname)

View File

@ -2472,7 +2472,7 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
bool ResetDeviceParams(ALCdevice *device, const int *attrList) bool ResetDeviceParams(ALCdevice *device, const int *attrList)
{ {
/* If the device was disconnected, reset it since we're opened anew. */ /* If the device was disconnected, reset it since we're opened anew. */
if(!device->Connected.load(std::memory_order_relaxed)) [[unlikely]] if(!device->Connected.load(std::memory_order_relaxed)) UNLIKELY
{ {
/* Make sure disconnection is finished before continuing on. */ /* Make sure disconnection is finished before continuing on. */
device->waitForMix(); device->waitForMix();
@ -2504,7 +2504,7 @@ bool ResetDeviceParams(ALCdevice *device, const int *attrList)
} }
ALCenum err{UpdateDeviceParams(device, attrList)}; ALCenum err{UpdateDeviceParams(device, attrList)};
if(err == ALC_NO_ERROR) [[likely]] return ALC_TRUE; if(err == ALC_NO_ERROR) LIKELY return ALC_TRUE;
alcSetError(device, err); alcSetError(device, err);
return ALC_FALSE; return ALC_FALSE;
@ -2556,7 +2556,7 @@ ContextRef GetContextRef(void)
*/ */
} }
context = ALCcontext::sGlobalContext.load(std::memory_order_acquire); context = ALCcontext::sGlobalContext.load(std::memory_order_acquire);
if(context) [[likely]] context->add_ref(); if(context) LIKELY context->add_ref();
ALCcontext::sGlobalContextLock.store(false, std::memory_order_release); ALCcontext::sGlobalContextLock.store(false, std::memory_order_release);
} }
return ContextRef{context}; return ContextRef{context};

View File

@ -488,7 +488,7 @@ bool CalcEffectSlotParams(EffectSlot *slot, EffectSlot **sorted_slots, ContextBa
/* Otherwise, if it would be deleted send it off with a release event. */ /* Otherwise, if it would be deleted send it off with a release event. */
RingBuffer *ring{context->mAsyncEvents.get()}; RingBuffer *ring{context->mAsyncEvents.get()};
auto evt_vec = ring->getWriteVector(); auto evt_vec = ring->getWriteVector();
if(evt_vec.first.len > 0) [[likely]] if(evt_vec.first.len > 0) LIKELY
{ {
AsyncEvent *evt{al::construct_at(reinterpret_cast<AsyncEvent*>(evt_vec.first.buf), AsyncEvent *evt{al::construct_at(reinterpret_cast<AsyncEvent*>(evt_vec.first.buf),
AsyncEvent::ReleaseEffectState)}; AsyncEvent::ReleaseEffectState)};
@ -1531,7 +1531,7 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ContextBa
} }
/* Distance-based air absorption and initial send decay. */ /* Distance-based air absorption and initial send decay. */
if(Distance > props->RefDistance) [[likely]] if(Distance > props->RefDistance) LIKELY
{ {
const float distance_base{(Distance-props->RefDistance) * props->RolloffFactor}; const float distance_base{(Distance-props->RefDistance) * props->RolloffFactor};
const float distance_meters{distance_base * context->mParams.MetersPerUnit}; const float distance_meters{distance_base * context->mParams.MetersPerUnit};
@ -1826,7 +1826,7 @@ void ProcessParamUpdates(ContextBase *ctx, const EffectSlotArray &slots,
ProcessVoiceChanges(ctx); ProcessVoiceChanges(ctx);
IncrementRef(ctx->mUpdateCount); IncrementRef(ctx->mUpdateCount);
if(!ctx->mHoldUpdates.load(std::memory_order_acquire)) [[likely]] if(!ctx->mHoldUpdates.load(std::memory_order_acquire)) LIKELY
{ {
bool force{CalcContextParams(ctx)}; bool force{CalcContextParams(ctx)};
auto sorted_slots = const_cast<EffectSlot**>(slots.data() + slots.size()); auto sorted_slots = const_cast<EffectSlot**>(slots.data() + slots.size());
@ -1918,7 +1918,7 @@ void ProcessContexts(DeviceBase *device, const uint SamplesToDo)
* left that don't target any sorted slots, they can't * left that don't target any sorted slots, they can't
* contribute to the output, so leave them. * contribute to the output, so leave them.
*/ */
if(next_target == split_point) [[unlikely]] if(next_target == split_point) UNLIKELY
break; break;
--next_target; --next_target;
@ -1961,7 +1961,7 @@ void ApplyDistanceComp(const al::span<FloatBufferLine> Samples, const size_t Sam
float *inout{al::assume_aligned<16>(chanbuffer.data())}; float *inout{al::assume_aligned<16>(chanbuffer.data())};
auto inout_end = inout + SamplesToDo; auto inout_end = inout + SamplesToDo;
if(SamplesToDo >= base) [[likely]] if(SamplesToDo >= base) LIKELY
{ {
auto delay_end = std::rotate(inout, inout_end - base, inout_end); auto delay_end = std::rotate(inout, inout_end - base, inout_end);
std::swap_ranges(inout, delay_end, distbuf); std::swap_ranges(inout, delay_end, distbuf);
@ -2136,7 +2136,7 @@ void DeviceBase::renderSamples(void *outBuffer, const uint numSamples, const siz
{ {
const uint samplesToDo{renderSamples(todo)}; const uint samplesToDo{renderSamples(todo)};
if(outBuffer) [[likely]] if(outBuffer) LIKELY
{ {
/* Finally, interleave and convert samples, writing to the device's /* Finally, interleave and convert samples, writing to the device's
* output buffer. * output buffer.

View File

@ -345,7 +345,7 @@ int JackPlayback::processRt(jack_nframes_t numframes) noexcept
out[numchans++] = static_cast<float*>(jack_port_get_buffer(port, numframes)); out[numchans++] = static_cast<float*>(jack_port_get_buffer(port, numframes));
} }
if(mPlaying.load(std::memory_order_acquire)) [[likely]] if(mPlaying.load(std::memory_order_acquire)) LIKELY
mDevice->renderSamples({out.data(), numchans}, static_cast<uint>(numframes)); mDevice->renderSamples({out.data(), numchans}, static_cast<uint>(numframes));
else else
{ {
@ -369,7 +369,7 @@ int JackPlayback::process(jack_nframes_t numframes) noexcept
} }
jack_nframes_t total{0}; jack_nframes_t total{0};
if(mPlaying.load(std::memory_order_acquire)) [[likely]] if(mPlaying.load(std::memory_order_acquire)) LIKELY
{ {
auto data = mRing->getReadVector(); auto data = mRing->getReadVector();
jack_nframes_t todo{minu(numframes, static_cast<uint>(data.first.len))}; jack_nframes_t todo{minu(numframes, static_cast<uint>(data.first.len))};

View File

@ -113,7 +113,7 @@ constexpr SLuint32 GetByteOrderEndianness() noexcept
return SL_BYTEORDER_BIGENDIAN; return SL_BYTEORDER_BIGENDIAN;
} }
const char *res_str(SLresult result) noexcept constexpr const char *res_str(SLresult result) noexcept
{ {
switch(result) switch(result)
{ {
@ -147,10 +147,11 @@ const char *res_str(SLresult result) noexcept
return "Unknown error code"; return "Unknown error code";
} }
#define PRINTERR(x, s) do { \ inline void PrintErr(SLresult res, const char *str)
if((x) != SL_RESULT_SUCCESS) [[unlikely]] \ {
ERR("%s: %s\n", (s), res_str((x))); \ if(res != SL_RESULT_SUCCESS) UNLIKELY
} while(0) ERR("%s: %s\n", str, res_str(res));
}
struct OpenSLPlayback final : public BackendBase { struct OpenSLPlayback final : public BackendBase {
@ -234,11 +235,11 @@ int OpenSLPlayback::mixerProc()
SLAndroidSimpleBufferQueueItf bufferQueue; SLAndroidSimpleBufferQueueItf bufferQueue;
SLresult result{VCALL(mBufferQueueObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE, SLresult result{VCALL(mBufferQueueObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
&bufferQueue)}; &bufferQueue)};
PRINTERR(result, "bufferQueue->GetInterface SL_IID_ANDROIDSIMPLEBUFFERQUEUE"); PrintErr(result, "bufferQueue->GetInterface SL_IID_ANDROIDSIMPLEBUFFERQUEUE");
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
result = VCALL(mBufferQueueObj,GetInterface)(SL_IID_PLAY, &player); result = VCALL(mBufferQueueObj,GetInterface)(SL_IID_PLAY, &player);
PRINTERR(result, "bufferQueue->GetInterface SL_IID_PLAY"); PrintErr(result, "bufferQueue->GetInterface SL_IID_PLAY");
} }
const size_t frame_step{mDevice->channelsFromFmt()}; const size_t frame_step{mDevice->channelsFromFmt()};
@ -254,11 +255,11 @@ int OpenSLPlayback::mixerProc()
SLuint32 state{0}; SLuint32 state{0};
result = VCALL(player,GetPlayState)(&state); result = VCALL(player,GetPlayState)(&state);
PRINTERR(result, "player->GetPlayState"); PrintErr(result, "player->GetPlayState");
if(SL_RESULT_SUCCESS == result && state != SL_PLAYSTATE_PLAYING) if(SL_RESULT_SUCCESS == result && state != SL_PLAYSTATE_PLAYING)
{ {
result = VCALL(player,SetPlayState)(SL_PLAYSTATE_PLAYING); result = VCALL(player,SetPlayState)(SL_PLAYSTATE_PLAYING);
PRINTERR(result, "player->SetPlayState"); PrintErr(result, "player->SetPlayState");
} }
if(SL_RESULT_SUCCESS != result) if(SL_RESULT_SUCCESS != result)
{ {
@ -295,7 +296,7 @@ int OpenSLPlayback::mixerProc()
} }
result = VCALL(bufferQueue,Enqueue)(data.first.buf, mDevice->UpdateSize*mFrameSize); result = VCALL(bufferQueue,Enqueue)(data.first.buf, mDevice->UpdateSize*mFrameSize);
PRINTERR(result, "bufferQueue->Enqueue"); PrintErr(result, "bufferQueue->Enqueue");
if(SL_RESULT_SUCCESS != result) if(SL_RESULT_SUCCESS != result)
{ {
mDevice->handleDisconnect("Failed to queue audio: 0x%08x", result); mDevice->handleDisconnect("Failed to queue audio: 0x%08x", result);
@ -324,26 +325,26 @@ void OpenSLPlayback::open(const char *name)
// create engine // create engine
SLresult result{slCreateEngine(&mEngineObj, 0, nullptr, 0, nullptr, nullptr)}; SLresult result{slCreateEngine(&mEngineObj, 0, nullptr, 0, nullptr, nullptr)};
PRINTERR(result, "slCreateEngine"); PrintErr(result, "slCreateEngine");
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
result = VCALL(mEngineObj,Realize)(SL_BOOLEAN_FALSE); result = VCALL(mEngineObj,Realize)(SL_BOOLEAN_FALSE);
PRINTERR(result, "engine->Realize"); PrintErr(result, "engine->Realize");
} }
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
result = VCALL(mEngineObj,GetInterface)(SL_IID_ENGINE, &mEngine); result = VCALL(mEngineObj,GetInterface)(SL_IID_ENGINE, &mEngine);
PRINTERR(result, "engine->GetInterface"); PrintErr(result, "engine->GetInterface");
} }
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
result = VCALL(mEngine,CreateOutputMix)(&mOutputMix, 0, nullptr, nullptr); result = VCALL(mEngine,CreateOutputMix)(&mOutputMix, 0, nullptr, nullptr);
PRINTERR(result, "engine->CreateOutputMix"); PrintErr(result, "engine->CreateOutputMix");
} }
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
result = VCALL(mOutputMix,Realize)(SL_BOOLEAN_FALSE); result = VCALL(mOutputMix,Realize)(SL_BOOLEAN_FALSE);
PRINTERR(result, "outputMix->Realize"); PrintErr(result, "outputMix->Realize");
} }
if(SL_RESULT_SUCCESS != result) if(SL_RESULT_SUCCESS != result)
@ -511,20 +512,20 @@ bool OpenSLPlayback::reset()
result = VCALL(mEngine,CreateAudioPlayer)(&mBufferQueueObj, &audioSrc, &audioSnk, ids.size(), result = VCALL(mEngine,CreateAudioPlayer)(&mBufferQueueObj, &audioSrc, &audioSnk, ids.size(),
ids.data(), reqs.data()); ids.data(), reqs.data());
PRINTERR(result, "engine->CreateAudioPlayer"); PrintErr(result, "engine->CreateAudioPlayer");
} }
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
/* Set the stream type to "media" (games, music, etc), if possible. */ /* Set the stream type to "media" (games, music, etc), if possible. */
SLAndroidConfigurationItf config; SLAndroidConfigurationItf config;
result = VCALL(mBufferQueueObj,GetInterface)(SL_IID_ANDROIDCONFIGURATION, &config); result = VCALL(mBufferQueueObj,GetInterface)(SL_IID_ANDROIDCONFIGURATION, &config);
PRINTERR(result, "bufferQueue->GetInterface SL_IID_ANDROIDCONFIGURATION"); PrintErr(result, "bufferQueue->GetInterface SL_IID_ANDROIDCONFIGURATION");
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
SLint32 streamType = SL_ANDROID_STREAM_MEDIA; SLint32 streamType = SL_ANDROID_STREAM_MEDIA;
result = VCALL(config,SetConfiguration)(SL_ANDROID_KEY_STREAM_TYPE, &streamType, result = VCALL(config,SetConfiguration)(SL_ANDROID_KEY_STREAM_TYPE, &streamType,
sizeof(streamType)); sizeof(streamType));
PRINTERR(result, "config->SetConfiguration"); PrintErr(result, "config->SetConfiguration");
} }
/* Clear any error since this was optional. */ /* Clear any error since this was optional. */
@ -533,7 +534,7 @@ bool OpenSLPlayback::reset()
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
result = VCALL(mBufferQueueObj,Realize)(SL_BOOLEAN_FALSE); result = VCALL(mBufferQueueObj,Realize)(SL_BOOLEAN_FALSE);
PRINTERR(result, "bufferQueue->Realize"); PrintErr(result, "bufferQueue->Realize");
} }
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
@ -560,11 +561,11 @@ void OpenSLPlayback::start()
SLAndroidSimpleBufferQueueItf bufferQueue; SLAndroidSimpleBufferQueueItf bufferQueue;
SLresult result{VCALL(mBufferQueueObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE, SLresult result{VCALL(mBufferQueueObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
&bufferQueue)}; &bufferQueue)};
PRINTERR(result, "bufferQueue->GetInterface"); PrintErr(result, "bufferQueue->GetInterface");
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
result = VCALL(bufferQueue,RegisterCallback)(&OpenSLPlayback::processC, this); result = VCALL(bufferQueue,RegisterCallback)(&OpenSLPlayback::processC, this);
PRINTERR(result, "bufferQueue->RegisterCallback"); PrintErr(result, "bufferQueue->RegisterCallback");
} }
if(SL_RESULT_SUCCESS != result) if(SL_RESULT_SUCCESS != result)
throw al::backend_exception{al::backend_error::DeviceError, throw al::backend_exception{al::backend_error::DeviceError,
@ -590,25 +591,25 @@ void OpenSLPlayback::stop()
SLPlayItf player; SLPlayItf player;
SLresult result{VCALL(mBufferQueueObj,GetInterface)(SL_IID_PLAY, &player)}; SLresult result{VCALL(mBufferQueueObj,GetInterface)(SL_IID_PLAY, &player)};
PRINTERR(result, "bufferQueue->GetInterface"); PrintErr(result, "bufferQueue->GetInterface");
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
result = VCALL(player,SetPlayState)(SL_PLAYSTATE_STOPPED); result = VCALL(player,SetPlayState)(SL_PLAYSTATE_STOPPED);
PRINTERR(result, "player->SetPlayState"); PrintErr(result, "player->SetPlayState");
} }
SLAndroidSimpleBufferQueueItf bufferQueue; SLAndroidSimpleBufferQueueItf bufferQueue;
result = VCALL(mBufferQueueObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &bufferQueue); result = VCALL(mBufferQueueObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &bufferQueue);
PRINTERR(result, "bufferQueue->GetInterface"); PrintErr(result, "bufferQueue->GetInterface");
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
result = VCALL0(bufferQueue,Clear)(); result = VCALL0(bufferQueue,Clear)();
PRINTERR(result, "bufferQueue->Clear"); PrintErr(result, "bufferQueue->Clear");
} }
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
result = VCALL(bufferQueue,RegisterCallback)(nullptr, nullptr); result = VCALL(bufferQueue,RegisterCallback)(nullptr, nullptr);
PRINTERR(result, "bufferQueue->RegisterCallback"); PrintErr(result, "bufferQueue->RegisterCallback");
} }
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
@ -617,7 +618,7 @@ void OpenSLPlayback::stop()
std::this_thread::yield(); std::this_thread::yield();
result = VCALL(bufferQueue,GetState)(&state); result = VCALL(bufferQueue,GetState)(&state);
} while(SL_RESULT_SUCCESS == result && state.count > 0); } while(SL_RESULT_SUCCESS == result && state.count > 0);
PRINTERR(result, "bufferQueue->GetState"); PrintErr(result, "bufferQueue->GetState");
mRing->reset(); mRing->reset();
} }
@ -694,16 +695,16 @@ void OpenSLCapture::open(const char* name)
name}; name};
SLresult result{slCreateEngine(&mEngineObj, 0, nullptr, 0, nullptr, nullptr)}; SLresult result{slCreateEngine(&mEngineObj, 0, nullptr, 0, nullptr, nullptr)};
PRINTERR(result, "slCreateEngine"); PrintErr(result, "slCreateEngine");
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
result = VCALL(mEngineObj,Realize)(SL_BOOLEAN_FALSE); result = VCALL(mEngineObj,Realize)(SL_BOOLEAN_FALSE);
PRINTERR(result, "engine->Realize"); PrintErr(result, "engine->Realize");
} }
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
result = VCALL(mEngineObj,GetInterface)(SL_IID_ENGINE, &mEngine); result = VCALL(mEngineObj,GetInterface)(SL_IID_ENGINE, &mEngine);
PRINTERR(result, "engine->GetInterface"); PrintErr(result, "engine->GetInterface");
} }
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
@ -778,7 +779,7 @@ void OpenSLCapture::open(const char* name)
result = VCALL(mEngine,CreateAudioRecorder)(&mRecordObj, &audioSrc, &audioSnk, result = VCALL(mEngine,CreateAudioRecorder)(&mRecordObj, &audioSrc, &audioSnk,
ids.size(), ids.data(), reqs.data()); ids.size(), ids.data(), reqs.data());
} }
PRINTERR(result, "engine->CreateAudioRecorder"); PrintErr(result, "engine->CreateAudioRecorder");
} }
} }
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
@ -786,13 +787,13 @@ void OpenSLCapture::open(const char* name)
/* Set the record preset to "generic", if possible. */ /* Set the record preset to "generic", if possible. */
SLAndroidConfigurationItf config; SLAndroidConfigurationItf config;
result = VCALL(mRecordObj,GetInterface)(SL_IID_ANDROIDCONFIGURATION, &config); result = VCALL(mRecordObj,GetInterface)(SL_IID_ANDROIDCONFIGURATION, &config);
PRINTERR(result, "recordObj->GetInterface SL_IID_ANDROIDCONFIGURATION"); PrintErr(result, "recordObj->GetInterface SL_IID_ANDROIDCONFIGURATION");
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
SLuint32 preset = SL_ANDROID_RECORDING_PRESET_GENERIC; SLuint32 preset = SL_ANDROID_RECORDING_PRESET_GENERIC;
result = VCALL(config,SetConfiguration)(SL_ANDROID_KEY_RECORDING_PRESET, &preset, result = VCALL(config,SetConfiguration)(SL_ANDROID_KEY_RECORDING_PRESET, &preset,
sizeof(preset)); sizeof(preset));
PRINTERR(result, "config->SetConfiguration"); PrintErr(result, "config->SetConfiguration");
} }
/* Clear any error since this was optional. */ /* Clear any error since this was optional. */
@ -801,19 +802,19 @@ void OpenSLCapture::open(const char* name)
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
result = VCALL(mRecordObj,Realize)(SL_BOOLEAN_FALSE); result = VCALL(mRecordObj,Realize)(SL_BOOLEAN_FALSE);
PRINTERR(result, "recordObj->Realize"); PrintErr(result, "recordObj->Realize");
} }
SLAndroidSimpleBufferQueueItf bufferQueue; SLAndroidSimpleBufferQueueItf bufferQueue;
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
result = VCALL(mRecordObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &bufferQueue); result = VCALL(mRecordObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &bufferQueue);
PRINTERR(result, "recordObj->GetInterface"); PrintErr(result, "recordObj->GetInterface");
} }
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
result = VCALL(bufferQueue,RegisterCallback)(&OpenSLCapture::processC, this); result = VCALL(bufferQueue,RegisterCallback)(&OpenSLCapture::processC, this);
PRINTERR(result, "bufferQueue->RegisterCallback"); PrintErr(result, "bufferQueue->RegisterCallback");
} }
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
@ -826,12 +827,12 @@ void OpenSLCapture::open(const char* name)
for(size_t i{0u};i < data.first.len && SL_RESULT_SUCCESS == result;i++) for(size_t i{0u};i < data.first.len && SL_RESULT_SUCCESS == result;i++)
{ {
result = VCALL(bufferQueue,Enqueue)(data.first.buf + chunk_size*i, chunk_size); result = VCALL(bufferQueue,Enqueue)(data.first.buf + chunk_size*i, chunk_size);
PRINTERR(result, "bufferQueue->Enqueue"); PrintErr(result, "bufferQueue->Enqueue");
} }
for(size_t i{0u};i < data.second.len && SL_RESULT_SUCCESS == result;i++) for(size_t i{0u};i < data.second.len && SL_RESULT_SUCCESS == result;i++)
{ {
result = VCALL(bufferQueue,Enqueue)(data.second.buf + chunk_size*i, chunk_size); result = VCALL(bufferQueue,Enqueue)(data.second.buf + chunk_size*i, chunk_size);
PRINTERR(result, "bufferQueue->Enqueue"); PrintErr(result, "bufferQueue->Enqueue");
} }
} }
@ -857,12 +858,12 @@ void OpenSLCapture::start()
{ {
SLRecordItf record; SLRecordItf record;
SLresult result{VCALL(mRecordObj,GetInterface)(SL_IID_RECORD, &record)}; SLresult result{VCALL(mRecordObj,GetInterface)(SL_IID_RECORD, &record)};
PRINTERR(result, "recordObj->GetInterface"); PrintErr(result, "recordObj->GetInterface");
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
result = VCALL(record,SetRecordState)(SL_RECORDSTATE_RECORDING); result = VCALL(record,SetRecordState)(SL_RECORDSTATE_RECORDING);
PRINTERR(result, "record->SetRecordState"); PrintErr(result, "record->SetRecordState");
} }
if(SL_RESULT_SUCCESS != result) if(SL_RESULT_SUCCESS != result)
throw al::backend_exception{al::backend_error::DeviceError, throw al::backend_exception{al::backend_error::DeviceError,
@ -873,12 +874,12 @@ void OpenSLCapture::stop()
{ {
SLRecordItf record; SLRecordItf record;
SLresult result{VCALL(mRecordObj,GetInterface)(SL_IID_RECORD, &record)}; SLresult result{VCALL(mRecordObj,GetInterface)(SL_IID_RECORD, &record)};
PRINTERR(result, "recordObj->GetInterface"); PrintErr(result, "recordObj->GetInterface");
if(SL_RESULT_SUCCESS == result) if(SL_RESULT_SUCCESS == result)
{ {
result = VCALL(record,SetRecordState)(SL_RECORDSTATE_PAUSED); result = VCALL(record,SetRecordState)(SL_RECORDSTATE_PAUSED);
PRINTERR(result, "record->SetRecordState"); PrintErr(result, "record->SetRecordState");
} }
} }
@ -916,12 +917,12 @@ void OpenSLCapture::captureSamples(al::byte *buffer, uint samples)
} }
SLAndroidSimpleBufferQueueItf bufferQueue{}; SLAndroidSimpleBufferQueueItf bufferQueue{};
if(mDevice->Connected.load(std::memory_order_acquire)) [[likely]] if(mDevice->Connected.load(std::memory_order_acquire)) LIKELY
{ {
const SLresult result{VCALL(mRecordObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE, const SLresult result{VCALL(mRecordObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
&bufferQueue)}; &bufferQueue)};
PRINTERR(result, "recordObj->GetInterface"); PrintErr(result, "recordObj->GetInterface");
if(SL_RESULT_SUCCESS != result) [[unlikely]] if(SL_RESULT_SUCCESS != result) UNLIKELY
{ {
mDevice->handleDisconnect("Failed to get capture buffer queue: 0x%08x", result); mDevice->handleDisconnect("Failed to get capture buffer queue: 0x%08x", result);
bufferQueue = nullptr; bufferQueue = nullptr;
@ -942,14 +943,14 @@ void OpenSLCapture::captureSamples(al::byte *buffer, uint samples)
SLresult result{SL_RESULT_SUCCESS}; SLresult result{SL_RESULT_SUCCESS};
auto wdata = mRing->getWriteVector(); auto wdata = mRing->getWriteVector();
if(adv_count > wdata.second.len) [[likely]] if(adv_count > wdata.second.len) LIKELY
{ {
auto len1 = std::min(wdata.first.len, adv_count-wdata.second.len); auto len1 = std::min(wdata.first.len, adv_count-wdata.second.len);
auto buf1 = wdata.first.buf + chunk_size*(wdata.first.len-len1); auto buf1 = wdata.first.buf + chunk_size*(wdata.first.len-len1);
for(size_t i{0u};i < len1 && SL_RESULT_SUCCESS == result;i++) for(size_t i{0u};i < len1 && SL_RESULT_SUCCESS == result;i++)
{ {
result = VCALL(bufferQueue,Enqueue)(buf1 + chunk_size*i, chunk_size); result = VCALL(bufferQueue,Enqueue)(buf1 + chunk_size*i, chunk_size);
PRINTERR(result, "bufferQueue->Enqueue"); PrintErr(result, "bufferQueue->Enqueue");
} }
} }
if(wdata.second.len > 0) if(wdata.second.len > 0)
@ -959,7 +960,7 @@ void OpenSLCapture::captureSamples(al::byte *buffer, uint samples)
for(size_t i{0u};i < len2 && SL_RESULT_SUCCESS == result;i++) for(size_t i{0u};i < len2 && SL_RESULT_SUCCESS == result;i++)
{ {
result = VCALL(bufferQueue,Enqueue)(buf2 + chunk_size*i, chunk_size); result = VCALL(bufferQueue,Enqueue)(buf2 + chunk_size*i, chunk_size);
PRINTERR(result, "bufferQueue->Enqueue"); PrintErr(result, "bufferQueue->Enqueue");
} }
} }
} }

View File

@ -477,7 +477,7 @@ struct EventManager {
*/ */
void waitForInit() void waitForInit()
{ {
if(!mInitDone.load(std::memory_order_acquire)) [[unlikely]] if(!mInitDone.load(std::memory_order_acquire)) UNLIKELY
{ {
MainloopUniqueLock plock{mLoop}; MainloopUniqueLock plock{mLoop};
plock.wait([this](){ return mInitDone.load(std::memory_order_acquire); }); plock.wait([this](){ return mInitDone.load(std::memory_order_acquire); });
@ -862,7 +862,7 @@ void NodeProxy::infoCallback(const pw_node_info *info)
{ {
/* Can this actually change? */ /* Can this actually change? */
const char *media_class{spa_dict_lookup(info->props, PW_KEY_MEDIA_CLASS)}; const char *media_class{spa_dict_lookup(info->props, PW_KEY_MEDIA_CLASS)};
if(!media_class) [[unlikely]] return; if(!media_class) UNLIKELY return;
NodeType ntype{}; NodeType ntype{};
if(al::strcasecmp(media_class, AudioSinkClass) == 0) if(al::strcasecmp(media_class, AudioSinkClass) == 0)
@ -919,7 +919,7 @@ void NodeProxy::paramCallback(int, uint32_t id, uint32_t, uint32_t, const spa_po
if(id == SPA_PARAM_EnumFormat) if(id == SPA_PARAM_EnumFormat)
{ {
DeviceNode *node{DeviceNode::Find(mId)}; DeviceNode *node{DeviceNode::Find(mId)};
if(!node) [[unlikely]] return; if(!node) UNLIKELY return;
if(const spa_pod_prop *prop{spa_pod_find_prop(param, nullptr, SPA_FORMAT_AUDIO_rate)}) if(const spa_pod_prop *prop{spa_pod_find_prop(param, nullptr, SPA_FORMAT_AUDIO_rate)})
node->parseSampleRate(&prop->value); node->parseSampleRate(&prop->value);
@ -1344,7 +1344,7 @@ void PipeWirePlayback::ioChangedCallback(uint32_t id, void *area, uint32_t size)
void PipeWirePlayback::outputCallback() void PipeWirePlayback::outputCallback()
{ {
pw_buffer *pw_buf{pw_stream_dequeue_buffer(mStream.get())}; pw_buffer *pw_buf{pw_stream_dequeue_buffer(mStream.get())};
if(!pw_buf) [[unlikely]] return; if(!pw_buf) UNLIKELY return;
const al::span<spa_data> datas{pw_buf->buffer->datas, const al::span<spa_data> datas{pw_buf->buffer->datas,
minu(mNumChannels, pw_buf->buffer->n_datas)}; minu(mNumChannels, pw_buf->buffer->n_datas)};
@ -1360,7 +1360,7 @@ void PipeWirePlayback::outputCallback()
uint length{mRateMatch ? mRateMatch->size : 0u}; uint length{mRateMatch ? mRateMatch->size : 0u};
#endif #endif
/* If no length is specified, use the device's update size as a fallback. */ /* If no length is specified, use the device's update size as a fallback. */
if(!length) [[unlikely]] length = mDevice->UpdateSize; if(!length) UNLIKELY length = mDevice->UpdateSize;
/* For planar formats, each datas[] seems to contain one channel, so store /* For planar formats, each datas[] seems to contain one channel, so store
* the pointers in an array. Limit the render length in case the available * the pointers in an array. Limit the render length in case the available
@ -1729,7 +1729,7 @@ ClockLatency PipeWirePlayback::getClockLatency()
*/ */
nanoseconds monoclock{seconds{tspec.tv_sec} + nanoseconds{tspec.tv_nsec}}; nanoseconds monoclock{seconds{tspec.tv_sec} + nanoseconds{tspec.tv_nsec}};
nanoseconds curtic{}, delay{}; nanoseconds curtic{}, delay{};
if(ptime.rate.denom < 1) [[unlikely]] if(ptime.rate.denom < 1) UNLIKELY
{ {
/* If there's no stream rate, the stream hasn't had a chance to get /* If there's no stream rate, the stream hasn't had a chance to get
* going and return time info yet. Just use dummy values. * going and return time info yet. Just use dummy values.
@ -1827,7 +1827,7 @@ void PipeWireCapture::stateChangedCallback(pw_stream_state, pw_stream_state, con
void PipeWireCapture::inputCallback() void PipeWireCapture::inputCallback()
{ {
pw_buffer *pw_buf{pw_stream_dequeue_buffer(mStream.get())}; pw_buffer *pw_buf{pw_stream_dequeue_buffer(mStream.get())};
if(!pw_buf) [[unlikely]] return; if(!pw_buf) UNLIKELY return;
spa_data *bufdata{pw_buf->buffer->datas}; spa_data *bufdata{pw_buf->buffer->datas};
const uint offset{minu(bufdata->chunk->offset, bufdata->maxsize)}; const uint offset{minu(bufdata->chunk->offset, bufdata->maxsize)};

View File

@ -667,7 +667,7 @@ void PulsePlayback::streamWriteCallback(pa_stream *stream, size_t nbytes) noexce
pa_free_cb_t free_func{nullptr}; pa_free_cb_t free_func{nullptr};
auto buflen = static_cast<size_t>(-1); auto buflen = static_cast<size_t>(-1);
void *buf{}; void *buf{};
if(pa_stream_begin_write(stream, &buf, &buflen) || !buf) [[unlikely]] if(pa_stream_begin_write(stream, &buf, &buflen) || !buf) UNLIKELY
{ {
buflen = nbytes; buflen = nbytes;
buf = pa_xmalloc(buflen); buf = pa_xmalloc(buflen);
@ -680,7 +680,7 @@ void PulsePlayback::streamWriteCallback(pa_stream *stream, size_t nbytes) noexce
mDevice->renderSamples(buf, static_cast<uint>(buflen/mFrameSize), mSpec.channels); mDevice->renderSamples(buf, static_cast<uint>(buflen/mFrameSize), mSpec.channels);
int ret{pa_stream_write(stream, buf, buflen, free_func, 0, PA_SEEK_RELATIVE)}; int ret{pa_stream_write(stream, buf, buflen, free_func, 0, PA_SEEK_RELATIVE)};
if(ret != PA_OK) [[unlikely]] if(ret != PA_OK) UNLIKELY
ERR("Failed to write to stream: %d, %s\n", ret, pa_strerror(ret)); ERR("Failed to write to stream: %d, %s\n", ret, pa_strerror(ret));
} while(nbytes > 0); } while(nbytes > 0);
} }
@ -1006,7 +1006,7 @@ ClockLatency PulsePlayback::getClockLatency()
err = pa_stream_get_latency(mStream, &latency, &neg); err = pa_stream_get_latency(mStream, &latency, &neg);
} }
if(err != 0) [[unlikely]] if(err != 0) UNLIKELY
{ {
/* If err = -PA_ERR_NODATA, it means we were called too soon after /* If err = -PA_ERR_NODATA, it means we were called too soon after
* starting the stream and no timing info has been received from the * starting the stream and no timing info has been received from the
@ -1017,7 +1017,7 @@ ClockLatency PulsePlayback::getClockLatency()
latency = mDevice->BufferSize - mDevice->UpdateSize; latency = mDevice->BufferSize - mDevice->UpdateSize;
neg = 0; neg = 0;
} }
else if(neg) [[unlikely]] else if(neg) UNLIKELY
latency = 0; latency = 0;
ret.Latency = std::chrono::microseconds{latency}; ret.Latency = std::chrono::microseconds{latency};
@ -1240,7 +1240,7 @@ void PulseCapture::captureSamples(al::byte *buffer, uint samples)
mLastReadable -= static_cast<uint>(dstbuf.size()); mLastReadable -= static_cast<uint>(dstbuf.size());
while(!dstbuf.empty()) while(!dstbuf.empty())
{ {
if(mHoleLength > 0) [[unlikely]] if(mHoleLength > 0) UNLIKELY
{ {
const size_t rem{minz(dstbuf.size(), mHoleLength)}; const size_t rem{minz(dstbuf.size(), mHoleLength)};
std::fill_n(dstbuf.begin(), rem, mSilentVal); std::fill_n(dstbuf.begin(), rem, mSilentVal);
@ -1259,7 +1259,7 @@ void PulseCapture::captureSamples(al::byte *buffer, uint samples)
continue; continue;
} }
if(!mDevice->Connected.load(std::memory_order_acquire)) [[unlikely]] if(!mDevice->Connected.load(std::memory_order_acquire)) UNLIKELY
break; break;
MainloopUniqueLock plock{mMainloop}; MainloopUniqueLock plock{mMainloop};
@ -1270,7 +1270,7 @@ void PulseCapture::captureSamples(al::byte *buffer, uint samples)
} }
const pa_stream_state_t state{pa_stream_get_state(mStream)}; const pa_stream_state_t state{pa_stream_get_state(mStream)};
if(!PA_STREAM_IS_GOOD(state)) [[unlikely]] if(!PA_STREAM_IS_GOOD(state)) UNLIKELY
{ {
mDevice->handleDisconnect("Bad capture state: %u", state); mDevice->handleDisconnect("Bad capture state: %u", state);
break; break;
@ -1278,7 +1278,7 @@ void PulseCapture::captureSamples(al::byte *buffer, uint samples)
const void *capbuf; const void *capbuf;
size_t caplen; size_t caplen;
if(pa_stream_peek(mStream, &capbuf, &caplen) < 0) [[unlikely]] if(pa_stream_peek(mStream, &capbuf, &caplen) < 0) UNLIKELY
{ {
mDevice->handleDisconnect("Failed retrieving capture samples: %s", mDevice->handleDisconnect("Failed retrieving capture samples: %s",
pa_strerror(pa_context_errno(mContext))); pa_strerror(pa_context_errno(mContext)));
@ -1287,7 +1287,7 @@ void PulseCapture::captureSamples(al::byte *buffer, uint samples)
plock.unlock(); plock.unlock();
if(caplen == 0) break; if(caplen == 0) break;
if(!capbuf) [[unlikely]] if(!capbuf) UNLIKELY
mHoleLength = caplen; mHoleLength = caplen;
else else
mCapBuffer = {static_cast<const al::byte*>(capbuf), caplen}; mCapBuffer = {static_cast<const al::byte*>(capbuf), caplen};
@ -1305,7 +1305,7 @@ uint PulseCapture::availableSamples()
{ {
MainloopUniqueLock plock{mMainloop}; MainloopUniqueLock plock{mMainloop};
size_t got{pa_stream_readable_size(mStream)}; size_t got{pa_stream_readable_size(mStream)};
if(static_cast<ssize_t>(got) < 0) [[unlikely]] if(static_cast<ssize_t>(got) < 0) UNLIKELY
{ {
const char *err{pa_strerror(static_cast<int>(got))}; const char *err{pa_strerror(static_cast<int>(got))};
ERR("pa_stream_readable_size() failed: %s\n", err); ERR("pa_stream_readable_size() failed: %s\n", err);
@ -1342,13 +1342,13 @@ ClockLatency PulseCapture::getClockLatency()
err = pa_stream_get_latency(mStream, &latency, &neg); err = pa_stream_get_latency(mStream, &latency, &neg);
} }
if(err != 0) [[unlikely]] if(err != 0) UNLIKELY
{ {
ERR("Failed to get stream latency: 0x%x\n", err); ERR("Failed to get stream latency: 0x%x\n", err);
latency = 0; latency = 0;
neg = 0; neg = 0;
} }
else if(neg) [[unlikely]] else if(neg) UNLIKELY
latency = 0; latency = 0;
ret.Latency = std::chrono::microseconds{latency}; ret.Latency = std::chrono::microseconds{latency};

View File

@ -420,7 +420,7 @@ void ConvolutionState::update(const ContextBase *context, const EffectSlot *slot
{ SideRight, Deg2Rad( 90.0f), Deg2Rad(0.0f) } { SideRight, Deg2Rad( 90.0f), Deg2Rad(0.0f) }
}; };
if(mNumConvolveSegs < 1) [[unlikely]] if(mNumConvolveSegs < 1) UNLIKELY
return; return;
mMix = &ConvolutionState::NormalMix; mMix = &ConvolutionState::NormalMix;
@ -524,7 +524,7 @@ void ConvolutionState::update(const ContextBase *context, const EffectSlot *slot
void ConvolutionState::process(const size_t samplesToDo, void ConvolutionState::process(const size_t samplesToDo,
const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut) const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut)
{ {
if(mNumConvolveSegs < 1) [[unlikely]] if(mNumConvolveSegs < 1) UNLIKELY
return; return;
constexpr size_t m{ConvolveUpdateSize/2 + 1}; constexpr size_t m{ConvolveUpdateSize/2 + 1};

View File

@ -101,7 +101,7 @@ complex_fft(const al::span<std::complex<Real>> buffer, const al::type_identity_t
*/ */
const size_t log2_size{static_cast<size_t>(al::countr_zero(fftsize))}; const size_t log2_size{static_cast<size_t>(al::countr_zero(fftsize))};
if(log2_size >= gBitReverses.size()) [[unlikely]] if(log2_size >= gBitReverses.size()) UNLIKELY
{ {
for(size_t idx{1u};idx < fftsize-1;++idx) for(size_t idx{1u};idx < fftsize-1;++idx)
{ {

View File

@ -170,11 +170,11 @@ inline int float2int(float f) noexcept
shift = ((conv.i>>23)&0xff) - (127+23); shift = ((conv.i>>23)&0xff) - (127+23);
/* Over/underflow */ /* Over/underflow */
if(shift >= 31 || shift < -23) [[unlikely]] if(shift >= 31 || shift < -23) UNLIKELY
return 0; return 0;
mant = (conv.i&0x7fffff) | 0x800000; mant = (conv.i&0x7fffff) | 0x800000;
if(shift < 0) [[likely]] if(shift < 0) LIKELY
return (mant >> -shift) * sign; return (mant >> -shift) * sign;
return (mant << shift) * sign; return (mant << shift) * sign;
@ -207,11 +207,11 @@ inline int double2int(double d) noexcept
shift = ((conv.i64 >> 52) & 0x7ff) - (1023 + 52); shift = ((conv.i64 >> 52) & 0x7ff) - (1023 + 52);
/* Over/underflow */ /* Over/underflow */
if(shift >= 63 || shift < -52) [[unlikely]] if(shift >= 63 || shift < -52) UNLIKELY
return 0; return 0;
mant = (conv.i64 & 0xfffffffffffff_i64) | 0x10000000000000_i64; mant = (conv.i64 & 0xfffffffffffff_i64) | 0x10000000000000_i64;
if(shift < 0) [[likely]] if(shift < 0) LIKELY
return (int)(mant >> -shift) * sign; return (int)(mant >> -shift) * sign;
return (int)(mant << shift) * sign; return (int)(mant << shift) * sign;
@ -260,7 +260,7 @@ inline float fast_roundf(float f) noexcept
sign = (conv.i>>31)&0x01; sign = (conv.i>>31)&0x01;
expo = (conv.i>>23)&0xff; expo = (conv.i>>23)&0xff;
if(expo >= 150/*+23*/) [[unlikely]] if(expo >= 150/*+23*/) UNLIKELY
{ {
/* An exponent (base-2) of 23 or higher is incapable of sub-integral /* An exponent (base-2) of 23 or higher is incapable of sub-integral
* precision, so it's already an integral value. We don't need to worry * precision, so it's already an integral value. We don't need to worry

View File

@ -44,7 +44,7 @@ public:
} }
ComPtr& operator=(ComPtr&& rhs) ComPtr& operator=(ComPtr&& rhs)
{ {
if(&rhs != this) [[likely]] if(&rhs != this) LIKELY
{ {
if(mPtr) mPtr->Release(); if(mPtr) mPtr->Release();
mPtr = std::exchange(rhs.mPtr, nullptr); mPtr = std::exchange(rhs.mPtr, nullptr);

View File

@ -18,7 +18,7 @@ public:
unsigned int dec_ref() noexcept unsigned int dec_ref() noexcept
{ {
auto ref = DecrementRef(mRef); auto ref = DecrementRef(mRef);
if(ref == 0) [[unlikely]] if(ref == 0) UNLIKELY
delete static_cast<T*>(this); delete static_cast<T*>(this);
return ref; return ref;
} }
@ -71,7 +71,7 @@ public:
} }
intrusive_ptr& operator=(intrusive_ptr&& rhs) noexcept intrusive_ptr& operator=(intrusive_ptr&& rhs) noexcept
{ {
if(&rhs != this) [[likely]] if(&rhs != this) LIKELY
{ {
if(mPtr) mPtr->dec_ref(); if(mPtr) mPtr->dec_ref();
mPtr = std::exchange(rhs.mPtr, nullptr); mPtr = std::exchange(rhs.mPtr, nullptr);

View File

@ -36,6 +36,17 @@
#define ASSUME(x) ((void)0) #define ASSUME(x) ((void)0)
#endif #endif
/* This shouldn't be needed since unknown attributes are ignored, but older
* versions of GCC choke on the attribute syntax in certain situations.
*/
#if !__has_attribute(likely)
#define LIKELY
#define UNLIKELY
#else
#define LIKELY [[likely]]
#define UNLIKELY [[unlikely]]
#endif
namespace al { namespace al {
template<typename T> template<typename T>

View File

@ -21,7 +21,7 @@ using uint = unsigned int;
*/ */
double Sinc(const double x) double Sinc(const double x)
{ {
if(std::abs(x) < Epsilon) [[unlikely]] if(std::abs(x) < Epsilon) UNLIKELY
return 1.0; return 1.0;
return std::sin(al::numbers::pi*x) / (al::numbers::pi*x); return std::sin(al::numbers::pi*x) / (al::numbers::pi*x);
} }
@ -96,7 +96,7 @@ constexpr uint Gcd(uint x, uint y)
constexpr uint CalcKaiserOrder(const double rejection, const double transition) constexpr uint CalcKaiserOrder(const double rejection, const double transition)
{ {
const double w_t{2.0 * al::numbers::pi * transition}; const double w_t{2.0 * al::numbers::pi * transition};
if(rejection > 21.0) [[likely]] if(rejection > 21.0) LIKELY
return static_cast<uint>(std::ceil((rejection - 7.95) / (2.285 * w_t))); return static_cast<uint>(std::ceil((rejection - 7.95) / (2.285 * w_t)));
return static_cast<uint>(std::ceil(5.79 / w_t)); return static_cast<uint>(std::ceil(5.79 / w_t));
} }
@ -104,7 +104,7 @@ constexpr uint CalcKaiserOrder(const double rejection, const double transition)
// Calculates the beta value of the Kaiser window. Rejection is in dB. // Calculates the beta value of the Kaiser window. Rejection is in dB.
constexpr double CalcKaiserBeta(const double rejection) constexpr double CalcKaiserBeta(const double rejection)
{ {
if(rejection > 50.0) [[likely]] if(rejection > 50.0) LIKELY
return 0.1102 * (rejection - 8.7); return 0.1102 * (rejection - 8.7);
if(rejection >= 21.0) if(rejection >= 21.0)
return (0.5842 * std::pow(rejection - 21.0, 0.4)) + return (0.5842 * std::pow(rejection - 21.0, 0.4)) +
@ -171,13 +171,13 @@ void PPhaseResampler::init(const uint srcRate, const uint dstRate)
// polyphase filter implementation. // polyphase filter implementation.
void PPhaseResampler::process(const uint inN, const double *in, const uint outN, double *out) void PPhaseResampler::process(const uint inN, const double *in, const uint outN, double *out)
{ {
if(outN == 0) [[unlikely]] if(outN == 0) UNLIKELY
return; return;
// Handle in-place operation. // Handle in-place operation.
std::vector<double> workspace; std::vector<double> workspace;
double *work{out}; double *work{out};
if(work == in) [[unlikely]] if(work == in) UNLIKELY
{ {
workspace.resize(outN); workspace.resize(outN);
work = workspace.data(); work = workspace.data();
@ -195,17 +195,17 @@ void PPhaseResampler::process(const uint inN, const double *in, const uint outN,
// Only take input when 0 <= j_s < inN. // Only take input when 0 <= j_s < inN.
double r{0.0}; double r{0.0};
if(j_f < m) [[likely]] if(j_f < m) LIKELY
{ {
size_t filt_len{(m-j_f+p-1) / p}; size_t filt_len{(m-j_f+p-1) / p};
if(j_s+1 > inN) [[likely]] if(j_s+1 > inN) LIKELY
{ {
size_t skip{std::min<size_t>(j_s+1 - inN, filt_len)}; size_t skip{std::min<size_t>(j_s+1 - inN, filt_len)};
j_f += p*skip; j_f += p*skip;
j_s -= skip; j_s -= skip;
filt_len -= skip; filt_len -= skip;
} }
if(size_t todo{std::min<size_t>(j_s+1, filt_len)}) [[likely]] if(size_t todo{std::min<size_t>(j_s+1, filt_len)}) LIKELY
{ {
do { do {
r += f[j_f] * in[j_s]; r += f[j_f] * in[j_s];

View File

@ -61,7 +61,7 @@ al::optional<std::string> make_error(size_t linenum, const char *fmt, ...)
va_start(args, fmt); va_start(args, fmt);
va_copy(args2, args); va_copy(args2, args);
const int msglen{std::vsnprintf(&str[plen], str.size()-plen, fmt, args)}; const int msglen{std::vsnprintf(&str[plen], str.size()-plen, fmt, args)};
if(msglen >= 0 && static_cast<size_t>(msglen) >= str.size()-plen) [[unlikely]] if(msglen >= 0 && static_cast<size_t>(msglen) >= str.size()-plen)
{ {
str.resize(static_cast<size_t>(msglen) + plen + 1u); str.resize(static_cast<size_t>(msglen) + plen + 1u);
std::vsnprintf(&str[plen], str.size()-plen, fmt, args2); std::vsnprintf(&str[plen], str.size()-plen, fmt, args2);

View File

@ -140,7 +140,7 @@ void Multi2Mono(uint chanmask, const size_t step, const float scale, float *REST
std::fill_n(dst, frames, 0.0f); std::fill_n(dst, frames, 0.0f);
for(size_t c{0};chanmask;++c) for(size_t c{0};chanmask;++c)
{ {
if((chanmask&1)) [[likely]] if((chanmask&1)) LIKELY
{ {
for(size_t i{0u};i < frames;i++) for(size_t i{0u};i < frames;i++)
dst[i] += LoadSample<T>(ssrc[i*step + c]); dst[i] += LoadSample<T>(ssrc[i*step + c]);

View File

@ -310,7 +310,7 @@ struct DeviceBase {
void ProcessBs2b(const size_t SamplesToDo); void ProcessBs2b(const size_t SamplesToDo);
inline void postProcess(const size_t SamplesToDo) inline void postProcess(const size_t SamplesToDo)
{ if(PostProcess) [[likely]] (this->*PostProcess)(SamplesToDo); } { if(PostProcess) LIKELY (this->*PostProcess)(SamplesToDo); }
void renderSamples(const al::span<float*> outBuffers, const uint numSamples); void renderSamples(const al::span<float*> outBuffers, const uint numSamples);
void renderSamples(void *outBuffer, const uint numSamples, const size_t frameStep); void renderSamples(void *outBuffer, const uint numSamples, const size_t frameStep);

View File

@ -18,7 +18,7 @@ void base_exception::setMessage(const char* msg, std::va_list args)
std::va_list args2; std::va_list args2;
va_copy(args2, args); va_copy(args2, args);
int msglen{std::vsnprintf(nullptr, 0, msg, args)}; int msglen{std::vsnprintf(nullptr, 0, msg, args)};
if(msglen > 0) [[likely]] if(msglen > 0) LIKELY
{ {
mMessage.resize(static_cast<size_t>(msglen)+1); mMessage.resize(static_cast<size_t>(msglen)+1);
std::vsnprintf(const_cast<char*>(mMessage.data()), mMessage.length(), msg, args2); std::vsnprintf(const_cast<char*>(mMessage.data()), mMessage.length(), msg, args2);

View File

@ -45,7 +45,7 @@ void al_print(LogLevel level, FILE *logfile, const char *fmt, ...)
va_start(args, fmt); va_start(args, fmt);
va_copy(args2, args); va_copy(args2, args);
const int msglen{std::vsnprintf(msg.data(), msg.size(), fmt, args)}; const int msglen{std::vsnprintf(msg.data(), msg.size(), fmt, args)};
if(msglen >= 0 && static_cast<size_t>(msglen) >= msg.size()) [[unlikely]] if(msglen >= 0 && static_cast<size_t>(msglen) >= msg.size()) UNLIKELY
{ {
dynmsg.resize(static_cast<size_t>(msglen)+prefix.size() + 1u); dynmsg.resize(static_cast<size_t>(msglen)+prefix.size() + 1u);

View File

@ -25,17 +25,17 @@ void al_print(LogLevel level, FILE *logfile, const char *fmt, ...);
#if (!defined(_WIN32) || defined(NDEBUG)) && !defined(__ANDROID__) #if (!defined(_WIN32) || defined(NDEBUG)) && !defined(__ANDROID__)
#define TRACE(...) do { \ #define TRACE(...) do { \
if(gLogLevel >= LogLevel::Trace) [[unlikely]] \ if(gLogLevel >= LogLevel::Trace) UNLIKELY \
al_print(LogLevel::Trace, gLogFile, __VA_ARGS__); \ al_print(LogLevel::Trace, gLogFile, __VA_ARGS__); \
} while(0) } while(0)
#define WARN(...) do { \ #define WARN(...) do { \
if(gLogLevel >= LogLevel::Warning) [[unlikely]] \ if(gLogLevel >= LogLevel::Warning) UNLIKELY \
al_print(LogLevel::Warning, gLogFile, __VA_ARGS__); \ al_print(LogLevel::Warning, gLogFile, __VA_ARGS__); \
} while(0) } while(0)
#define ERR(...) do { \ #define ERR(...) do { \
if(gLogLevel >= LogLevel::Error) [[unlikely]] \ if(gLogLevel >= LogLevel::Error) UNLIKELY \
al_print(LogLevel::Error, gLogFile, __VA_ARGS__); \ al_print(LogLevel::Error, gLogFile, __VA_ARGS__); \
} while(0) } while(0)

View File

@ -295,7 +295,7 @@ void SignalDelay(Compressor *Comp, const uint SamplesToDo, FloatBufferLine *OutB
float *delaybuf{al::assume_aligned<16>(Comp->mDelay[c].data())}; float *delaybuf{al::assume_aligned<16>(Comp->mDelay[c].data())};
auto inout_end = inout + SamplesToDo; auto inout_end = inout + SamplesToDo;
if(SamplesToDo >= lookAhead) [[likely]] if(SamplesToDo >= lookAhead) LIKELY
{ {
auto delay_end = std::rotate(inout, inout_end - lookAhead, inout_end); auto delay_end = std::rotate(inout, inout_end - lookAhead, inout_end);
std::swap_ranges(inout, delay_end, delaybuf); std::swap_ranges(inout, delay_end, delaybuf);

View File

@ -50,7 +50,7 @@ inline void MixHrtfBlendBase(const float *InSamples, float2 *RESTRICT AccumSampl
const ConstHrirSpan NewCoeffs{newparams->Coeffs}; const ConstHrirSpan NewCoeffs{newparams->Coeffs};
const float newGainStep{newparams->GainStep}; const float newGainStep{newparams->GainStep};
if(oldparams->Gain > GainSilenceThreshold) [[likely]] if(oldparams->Gain > GainSilenceThreshold) LIKELY
{ {
size_t ldelay{HrtfHistoryLength - oldparams->Delay[0]}; size_t ldelay{HrtfHistoryLength - oldparams->Delay[0]};
size_t rdelay{HrtfHistoryLength - oldparams->Delay[1]}; size_t rdelay{HrtfHistoryLength - oldparams->Delay[1]};
@ -66,7 +66,7 @@ inline void MixHrtfBlendBase(const float *InSamples, float2 *RESTRICT AccumSampl
} }
} }
if(newGainStep*static_cast<float>(BufferSize) > GainSilenceThreshold) [[likely]] if(newGainStep*static_cast<float>(BufferSize) > GainSilenceThreshold) LIKELY
{ {
size_t ldelay{HrtfHistoryLength+1 - newparams->Delay[0]}; size_t ldelay{HrtfHistoryLength+1 - newparams->Delay[0]};
size_t rdelay{HrtfHistoryLength+1 - newparams->Delay[1]}; size_t rdelay{HrtfHistoryLength+1 - newparams->Delay[1]};

View File

@ -67,7 +67,7 @@ void UhjAllPassFilter::process(const al::span<const float,4> coeffs,
return x; return x;
}; };
std::transform(src.begin(), src.end(), dst, proc_sample); std::transform(src.begin(), src.end(), dst, proc_sample);
if(updateState) [[likely]] mState = state; if(updateState) LIKELY mState = state;
} }
@ -133,7 +133,7 @@ void UhjEncoder<N>::encode(float *LeftOut, float *RightOut,
float *inout{al::assume_aligned<16>(buffer)}; float *inout{al::assume_aligned<16>(buffer)};
auto inout_end = inout + SamplesToDo; auto inout_end = inout + SamplesToDo;
if(SamplesToDo >= sFilterDelay) [[likely]] if(SamplesToDo >= sFilterDelay) LIKELY
{ {
auto delay_end = std::rotate(inout, inout_end - sFilterDelay, inout_end); auto delay_end = std::rotate(inout, inout_end - sFilterDelay, inout_end);
std::swap_ranges(inout, delay_end, distbuf); std::swap_ranges(inout, delay_end, distbuf);
@ -270,7 +270,7 @@ void UhjDecoder<N>::decode(const al::span<float*> samples, const size_t samplesT
auto tmpiter = std::copy(mDTHistory.cbegin(), mDTHistory.cend(), mTemp.begin()); auto tmpiter = std::copy(mDTHistory.cbegin(), mDTHistory.cend(), mTemp.begin());
std::transform(mD.cbegin(), mD.cbegin()+samplesToDo+sInputPadding, mT.cbegin(), tmpiter, std::transform(mD.cbegin(), mD.cbegin()+samplesToDo+sInputPadding, mT.cbegin(), tmpiter,
[](const float d, const float t) noexcept { return 0.828331f*d + 0.767820f*t; }); [](const float d, const float t) noexcept { return 0.828331f*d + 0.767820f*t; });
if(updateState) [[likely]] if(updateState) LIKELY
std::copy_n(mTemp.cbegin()+samplesToDo, mDTHistory.size(), mDTHistory.begin()); std::copy_n(mTemp.cbegin()+samplesToDo, mDTHistory.size(), mDTHistory.begin());
PShift.process({xoutput, samplesToDo}, mTemp.data()); PShift.process({xoutput, samplesToDo}, mTemp.data());
@ -284,7 +284,7 @@ void UhjDecoder<N>::decode(const al::span<float*> samples, const size_t samplesT
/* Precompute j*S and store in youtput. */ /* Precompute j*S and store in youtput. */
tmpiter = std::copy(mSHistory.cbegin(), mSHistory.cend(), mTemp.begin()); tmpiter = std::copy(mSHistory.cbegin(), mSHistory.cend(), mTemp.begin());
std::copy_n(mS.cbegin(), samplesToDo+sInputPadding, tmpiter); std::copy_n(mS.cbegin(), samplesToDo+sInputPadding, tmpiter);
if(updateState) [[likely]] if(updateState) LIKELY
std::copy_n(mTemp.cbegin()+samplesToDo, mSHistory.size(), mSHistory.begin()); std::copy_n(mTemp.cbegin()+samplesToDo, mSHistory.size(), mSHistory.begin());
PShift.process({youtput, samplesToDo}, mTemp.data()); PShift.process({youtput, samplesToDo}, mTemp.data());
@ -333,7 +333,7 @@ void UhjDecoderIIR::decode(const al::span<float*> samples, const size_t samplesT
/* Apply filter1 to S and store in mTemp. */ /* Apply filter1 to S and store in mTemp. */
mTemp[0] = mDelayS; mTemp[0] = mDelayS;
mFilter1S.process(Filter1Coeff, {mS.data(), samplesToDo}, updateState, mTemp.data()+1); mFilter1S.process(Filter1Coeff, {mS.data(), samplesToDo}, updateState, mTemp.data()+1);
if(updateState) [[likely]] mDelayS = mTemp[samplesToDo]; if(updateState) LIKELY mDelayS = mTemp[samplesToDo];
/* W = 0.981532*S + 0.197484*j(0.828331*D + 0.767820*T) */ /* W = 0.981532*S + 0.197484*j(0.828331*D + 0.767820*T) */
for(size_t i{0};i < samplesToDo;++i) for(size_t i{0};i < samplesToDo;++i)
@ -348,7 +348,7 @@ void UhjDecoderIIR::decode(const al::span<float*> samples, const size_t samplesT
[](const float d, const float t) noexcept { return 0.795968f*d - 0.676392f*t; }); [](const float d, const float t) noexcept { return 0.795968f*d - 0.676392f*t; });
mTemp[0] = mDelayDT; mTemp[0] = mDelayDT;
mFilter1DT.process(Filter1Coeff, {youtput, samplesToDo}, updateState, mTemp.data()+1); mFilter1DT.process(Filter1Coeff, {youtput, samplesToDo}, updateState, mTemp.data()+1);
if(updateState) [[likely]] mDelayDT = mTemp[samplesToDo]; if(updateState) LIKELY mDelayDT = mTemp[samplesToDo];
/* Precompute j*S and store in youtput. */ /* Precompute j*S and store in youtput. */
mFilter2S.process(Filter2Coeff, {mS.data(), samplesToDo}, updateState, youtput); mFilter2S.process(Filter2Coeff, {mS.data(), samplesToDo}, updateState, youtput);
@ -365,7 +365,7 @@ void UhjDecoderIIR::decode(const al::span<float*> samples, const size_t samplesT
/* Apply filter1 to Q and store in mTemp. */ /* Apply filter1 to Q and store in mTemp. */
mTemp[0] = mDelayQ; mTemp[0] = mDelayQ;
mFilter1Q.process(Filter1Coeff, {zoutput, samplesToDo}, updateState, mTemp.data()+1); mFilter1Q.process(Filter1Coeff, {zoutput, samplesToDo}, updateState, mTemp.data()+1);
if(updateState) [[likely]] mDelayQ = mTemp[samplesToDo]; if(updateState) LIKELY mDelayQ = mTemp[samplesToDo];
/* Z = 1.023332*Q */ /* Z = 1.023332*Q */
for(size_t i{0};i < samplesToDo;++i) for(size_t i{0};i < samplesToDo;++i)
@ -436,7 +436,7 @@ void UhjStereoDecoder<N>::decode(const al::span<float*> samples, const size_t sa
/* Precompute j*D and store in xoutput. */ /* Precompute j*D and store in xoutput. */
auto tmpiter = std::copy(mDTHistory.cbegin(), mDTHistory.cend(), mTemp.begin()); auto tmpiter = std::copy(mDTHistory.cbegin(), mDTHistory.cend(), mTemp.begin());
std::copy_n(mD.cbegin(), samplesToDo+sInputPadding, tmpiter); std::copy_n(mD.cbegin(), samplesToDo+sInputPadding, tmpiter);
if(updateState) [[likely]] if(updateState) LIKELY
std::copy_n(mTemp.cbegin()+samplesToDo, mDTHistory.size(), mDTHistory.begin()); std::copy_n(mTemp.cbegin()+samplesToDo, mDTHistory.size(), mDTHistory.begin());
PShift.process({xoutput, samplesToDo}, mTemp.data()); PShift.process({xoutput, samplesToDo}, mTemp.data());
@ -450,7 +450,7 @@ void UhjStereoDecoder<N>::decode(const al::span<float*> samples, const size_t sa
/* Precompute j*S and store in youtput. */ /* Precompute j*S and store in youtput. */
tmpiter = std::copy(mSHistory.cbegin(), mSHistory.cend(), mTemp.begin()); tmpiter = std::copy(mSHistory.cbegin(), mSHistory.cend(), mTemp.begin());
std::copy_n(mS.cbegin(), samplesToDo+sInputPadding, tmpiter); std::copy_n(mS.cbegin(), samplesToDo+sInputPadding, tmpiter);
if(updateState) [[likely]] if(updateState) LIKELY
std::copy_n(mTemp.cbegin()+samplesToDo, mSHistory.size(), mSHistory.begin()); std::copy_n(mTemp.cbegin()+samplesToDo, mSHistory.size(), mSHistory.begin());
PShift.process({youtput, samplesToDo}, mTemp.data()); PShift.process({youtput, samplesToDo}, mTemp.data());
@ -504,7 +504,7 @@ void UhjStereoDecoderIIR::decode(const al::span<float*> samples, const size_t sa
/* Apply filter1 to S and store in mTemp. */ /* Apply filter1 to S and store in mTemp. */
mTemp[0] = mDelayS; mTemp[0] = mDelayS;
mFilter1S.process(Filter1Coeff, {mS.data(), samplesToDo}, updateState, mTemp.data()+1); mFilter1S.process(Filter1Coeff, {mS.data(), samplesToDo}, updateState, mTemp.data()+1);
if(updateState) [[likely]] mDelayS = mTemp[samplesToDo]; if(updateState) LIKELY mDelayS = mTemp[samplesToDo];
/* Precompute j*D and store in xoutput. */ /* Precompute j*D and store in xoutput. */
mFilter2D.process(Filter2Coeff, {mD.data(), samplesToDo}, updateState, xoutput); mFilter2D.process(Filter2Coeff, {mD.data(), samplesToDo}, updateState, xoutput);
@ -522,7 +522,7 @@ void UhjStereoDecoderIIR::decode(const al::span<float*> samples, const size_t sa
/* Apply filter1 to D and store in mTemp. */ /* Apply filter1 to D and store in mTemp. */
mTemp[0] = mDelayD; mTemp[0] = mDelayD;
mFilter1D.process(Filter1Coeff, {mD.data(), samplesToDo}, updateState, mTemp.data()+1); mFilter1D.process(Filter1Coeff, {mD.data(), samplesToDo}, updateState, mTemp.data()+1);
if(updateState) [[likely]] mDelayD = mTemp[samplesToDo]; if(updateState) LIKELY mDelayD = mTemp[samplesToDo];
/* Y = 1.6822415*w*D - 0.2156194*j*S */ /* Y = 1.6822415*w*D - 0.2156194*j*S */
for(size_t i{0};i < samplesToDo;++i) for(size_t i{0};i < samplesToDo;++i)

View File

@ -493,7 +493,7 @@ void LoadBufferStatic(VoiceBufferItem *buffer, VoiceBufferItem *bufferLoopItem,
if(!bufferLoopItem) if(!bufferLoopItem)
{ {
/* Load what's left to play from the buffer */ /* Load what's left to play from the buffer */
if(buffer->mSampleLen > dataPosInt) [[likely]] if(buffer->mSampleLen > dataPosInt) LIKELY
{ {
const size_t buffer_remaining{buffer->mSampleLen - dataPosInt}; const size_t buffer_remaining{buffer->mSampleLen - dataPosInt};
const size_t remaining{minz(samplesToLoad-samplesLoaded, buffer_remaining)}; const size_t remaining{minz(samplesToLoad-samplesLoaded, buffer_remaining)};
@ -539,7 +539,7 @@ void LoadBufferCallback(VoiceBufferItem *buffer, const size_t dataPosInt,
const size_t srcStep, size_t samplesLoaded, const size_t samplesToLoad, float *voiceSamples) const size_t srcStep, size_t samplesLoaded, const size_t samplesToLoad, float *voiceSamples)
{ {
/* Load what's left to play from the buffer */ /* Load what's left to play from the buffer */
if(numCallbackSamples > dataPosInt) [[likely]] if(numCallbackSamples > dataPosInt) LIKELY
{ {
const size_t remaining{minz(samplesToLoad-samplesLoaded, numCallbackSamples-dataPosInt)}; const size_t remaining{minz(samplesToLoad-samplesLoaded, numCallbackSamples-dataPosInt)};
LoadSamples(voiceSamples+samplesLoaded, buffer->mSamples, srcChannel, dataPosInt, LoadSamples(voiceSamples+samplesLoaded, buffer->mSamples, srcChannel, dataPosInt,
@ -603,7 +603,7 @@ void DoHrtfMix(const float *samples, const uint DstBufferSize, DirectParams &par
std::begin(HrtfSamples)); std::begin(HrtfSamples));
std::copy_n(samples, DstBufferSize, src_iter); std::copy_n(samples, DstBufferSize, src_iter);
/* Copy the last used samples back into the history buffer for later. */ /* Copy the last used samples back into the history buffer for later. */
if(IsPlaying) [[likely]] if(IsPlaying) LIKELY
std::copy_n(std::begin(HrtfSamples) + DstBufferSize, parms.Hrtf.History.size(), std::copy_n(std::begin(HrtfSamples) + DstBufferSize, parms.Hrtf.History.size(),
parms.Hrtf.History.begin()); parms.Hrtf.History.begin());
@ -710,7 +710,7 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi
VoiceBufferItem *BufferListItem{mCurrentBuffer.load(std::memory_order_relaxed)}; VoiceBufferItem *BufferListItem{mCurrentBuffer.load(std::memory_order_relaxed)};
VoiceBufferItem *BufferLoopItem{mLoopBuffer.load(std::memory_order_relaxed)}; VoiceBufferItem *BufferLoopItem{mLoopBuffer.load(std::memory_order_relaxed)};
const uint increment{mStep}; const uint increment{mStep};
if(increment < 1) [[unlikely]] if(increment < 1) UNLIKELY
{ {
/* If the voice is supposed to be stopping but can't be mixed, just /* If the voice is supposed to be stopping but can't be mixed, just
* stop it before bailing. * stop it before bailing.
@ -863,7 +863,7 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi
else else
{ {
size_t srcSampleDelay{0}; size_t srcSampleDelay{0};
if(intPos < 0) [[unlikely]] if(intPos < 0) UNLIKELY
{ {
/* If the current position is negative, there's that many /* If the current position is negative, there's that many
* silent samples to load before using the buffer. * silent samples to load before using the buffer.
@ -922,13 +922,13 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi
{MixingSamples[chan]+samplesLoaded, dstBufferSize}); {MixingSamples[chan]+samplesLoaded, dstBufferSize});
/* Store the last source samples used for next time. */ /* Store the last source samples used for next time. */
if(vstate == Playing) [[likely]] if(vstate == Playing) LIKELY
{ {
/* Only store samples for the end of the mix, excluding what /* Only store samples for the end of the mix, excluding what
* gets loaded for decoder padding. * gets loaded for decoder padding.
*/ */
const uint loadEnd{samplesLoaded + dstBufferSize}; const uint loadEnd{samplesLoaded + dstBufferSize};
if(samplesToMix > samplesLoaded && samplesToMix <= loadEnd) [[likely]] if(samplesToMix > samplesLoaded && samplesToMix <= loadEnd) LIKELY
{ {
const size_t dstOffset{samplesToMix - samplesLoaded}; const size_t dstOffset{samplesToMix - samplesLoaded};
const size_t srcOffset{(dstOffset*increment + fracPos) >> MixerFracBits}; const size_t srcOffset{(dstOffset*increment + fracPos) >> MixerFracBits};
@ -1046,7 +1046,7 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi
mFlags.set(VoiceIsFading); mFlags.set(VoiceIsFading);
/* Don't update positions and buffers if we were stopping. */ /* Don't update positions and buffers if we were stopping. */
if(vstate == Stopping) [[unlikely]] if(vstate == Stopping) UNLIKELY
{ {
mPlayState.store(Stopped, std::memory_order_release); mPlayState.store(Stopped, std::memory_order_release);
return; return;
@ -1059,7 +1059,7 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi
DataPosFrac &= MixerFracMask; DataPosFrac &= MixerFracMask;
uint buffers_done{0u}; uint buffers_done{0u};
if(BufferListItem && DataPosInt >= 0) [[likely]] if(BufferListItem && DataPosInt >= 0) LIKELY
{ {
if(mFlags.test(VoiceIsStatic)) if(mFlags.test(VoiceIsStatic))
{ {
@ -1168,7 +1168,7 @@ void Voice::prepare(DeviceBase *device)
*/ */
uint num_channels{(mFmtChannels == FmtUHJ2 || mFmtChannels == FmtSuperStereo) ? 3 : uint num_channels{(mFmtChannels == FmtUHJ2 || mFmtChannels == FmtSuperStereo) ? 3 :
ChannelsFromFmt(mFmtChannels, minu(mAmbiOrder, device->mAmbiOrder))}; ChannelsFromFmt(mFmtChannels, minu(mAmbiOrder, device->mAmbiOrder))};
if(num_channels > device->mSampleData.size()) [[unlikely]] if(num_channels > device->mSampleData.size()) UNLIKELY
{ {
ERR("Unexpected channel count: %u (limit: %zu, %d:%d)\n", num_channels, ERR("Unexpected channel count: %u (limit: %zu, %d:%d)\n", num_channels,
device->mSampleData.size(), mFmtChannels, mAmbiOrder); device->mSampleData.size(), mFmtChannels, mAmbiOrder);