Make simpler likely/unlikely functions and use them in some places
This commit is contained in:
parent
c66e4f5bd4
commit
38d3ea3501
@ -85,7 +85,7 @@ AL_API ALenum AL_APIENTRY alGetError(void)
|
||||
START_API_FUNC
|
||||
{
|
||||
ContextRef context{GetContextRef()};
|
||||
if UNLIKELY(!context)
|
||||
if(unlikely(!context))
|
||||
{
|
||||
constexpr ALenum deferror{AL_INVALID_OPERATION};
|
||||
WARN("Querying error state on null context (implicitly 0x%04x)\n", deferror);
|
||||
|
@ -35,7 +35,7 @@ static int EventThread(ALCcontext *context)
|
||||
{
|
||||
RingBuffer *ring{context->mAsyncEvents.get()};
|
||||
bool quitnow{false};
|
||||
while LIKELY(!quitnow)
|
||||
while(likely(!quitnow))
|
||||
{
|
||||
auto evt_data = ring->getReadVector().first;
|
||||
if(evt_data.len == 0)
|
||||
@ -55,7 +55,7 @@ static int EventThread(ALCcontext *context)
|
||||
ring->readAdvance(1);
|
||||
|
||||
quitnow = evt.EnumType == EventType_KillThread;
|
||||
if UNLIKELY(quitnow) break;
|
||||
if(unlikely(quitnow)) break;
|
||||
|
||||
if(evt.EnumType == EventType_ReleaseEffectState)
|
||||
{
|
||||
@ -155,7 +155,7 @@ AL_API void AL_APIENTRY alEventControlSOFT(ALsizei count, const ALenum *types, A
|
||||
START_API_FUNC
|
||||
{
|
||||
ContextRef context{GetContextRef()};
|
||||
if UNLIKELY(!context) return;
|
||||
if(unlikely(!context)) return;
|
||||
|
||||
if(count < 0) context->setError(AL_INVALID_VALUE, "Controlling %d events", count);
|
||||
if(count <= 0) return;
|
||||
@ -210,7 +210,7 @@ AL_API void AL_APIENTRY alEventCallbackSOFT(ALEVENTPROCSOFT callback, void *user
|
||||
START_API_FUNC
|
||||
{
|
||||
ContextRef context{GetContextRef()};
|
||||
if UNLIKELY(!context) return;
|
||||
if(unlikely(!context)) return;
|
||||
|
||||
std::lock_guard<std::mutex> _{context->mPropLock};
|
||||
std::lock_guard<std::mutex> __{context->mEventCbLock};
|
||||
|
@ -37,7 +37,7 @@ AL_API ALboolean AL_APIENTRY alIsExtensionPresent(const ALchar *extName)
|
||||
START_API_FUNC
|
||||
{
|
||||
ContextRef context{GetContextRef()};
|
||||
if UNLIKELY(!context) return AL_FALSE;
|
||||
if(unlikely(!context)) return AL_FALSE;
|
||||
|
||||
if(!extName)
|
||||
SETERR_RETURN(context, AL_INVALID_VALUE, AL_FALSE, "NULL pointer");
|
||||
|
@ -333,7 +333,7 @@ struct EventManager {
|
||||
*/
|
||||
void waitForInit()
|
||||
{
|
||||
while UNLIKELY(!mInitDone.load(std::memory_order_acquire))
|
||||
while(unlikely(!mInitDone.load(std::memory_order_acquire)))
|
||||
mLoop.wait();
|
||||
}
|
||||
|
||||
@ -505,7 +505,7 @@ void NodeProxy::infoCallback(const pw_node_info *info)
|
||||
{
|
||||
/* Can this actually change? */
|
||||
const char *media_class{spa_dict_lookup(info->props, PW_KEY_MEDIA_CLASS)};
|
||||
if UNLIKELY(!media_class) return;
|
||||
if(unlikely(!media_class)) return;
|
||||
|
||||
bool isCapture{};
|
||||
if(al::strcasecmp(media_class, AudioSinkClass) == 0)
|
||||
@ -665,7 +665,7 @@ void NodeProxy::paramCallback(int, uint32_t id, uint32_t, uint32_t, const spa_po
|
||||
if(id == SPA_PARAM_EnumFormat)
|
||||
{
|
||||
DeviceNode *node{FindDeviceNode(mId)};
|
||||
if UNLIKELY(!node) return;
|
||||
if(unlikely(!node)) return;
|
||||
|
||||
if(const spa_pod_prop *prop{spa_pod_find_prop(param, nullptr, SPA_FORMAT_AUDIO_rate)})
|
||||
parse_srate(node, &prop->value);
|
||||
@ -1069,7 +1069,7 @@ void PipeWirePlayback::ioChangedCallback(uint32_t id, void *area, uint32_t size)
|
||||
void PipeWirePlayback::outputCallback()
|
||||
{
|
||||
pw_buffer *pw_buf{pw_stream_dequeue_buffer(mStream.get())};
|
||||
if UNLIKELY(!pw_buf) return;
|
||||
if(unlikely(!pw_buf)) return;
|
||||
|
||||
spa_buffer *spa_buf{pw_buf->buffer};
|
||||
uint length{mRateMatch ? mRateMatch->size : mDevice->UpdateSize};
|
||||
@ -1358,7 +1358,7 @@ ClockLatency PipeWirePlayback::getClockLatency()
|
||||
*/
|
||||
nanoseconds monoclock{seconds{tspec.tv_sec} + nanoseconds{tspec.tv_nsec}};
|
||||
nanoseconds curtic{}, delay{};
|
||||
if UNLIKELY(ptime.rate.denom < 1)
|
||||
if(unlikely(ptime.rate.denom < 1))
|
||||
{
|
||||
/* 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.
|
||||
@ -1464,7 +1464,7 @@ void PipeWireCapture::stateChangedCallback(pw_stream_state, pw_stream_state, con
|
||||
void PipeWireCapture::inputCallback()
|
||||
{
|
||||
pw_buffer *pw_buf{pw_stream_dequeue_buffer(mStream.get())};
|
||||
if UNLIKELY(!pw_buf) return;
|
||||
if(unlikely(!pw_buf)) return;
|
||||
|
||||
spa_data *bufdata{pw_buf->buffer->datas};
|
||||
const uint offset{minu(bufdata->chunk->offset, bufdata->maxsize)};
|
||||
|
@ -13,13 +13,17 @@
|
||||
* path at the expense of a less optimal false path.
|
||||
*/
|
||||
#define LIKELY(x) (__builtin_expect(!!(x), !false))
|
||||
constexpr bool likely(bool expr) { return __builtin_expect(expr, true); }
|
||||
/* The opposite of LIKELY, optimizing the case where the condition is false. */
|
||||
#define UNLIKELY(x) (__builtin_expect(!!(x), false))
|
||||
constexpr bool unlikely(bool expr) { return __builtin_expect(expr, false); }
|
||||
|
||||
#else
|
||||
|
||||
#define LIKELY(x) (!!(x))
|
||||
#define UNLIKELY(x) (!!(x))
|
||||
constexpr bool likely(bool expr) { return expr; }
|
||||
constexpr bool unlikely(bool expr) { return expr; }
|
||||
#endif
|
||||
|
||||
#if HAS_BUILTIN(__builtin_assume)
|
||||
|
Loading…
x
Reference in New Issue
Block a user