aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2021-10-03 06:41:14 -0700
committerChris Robinson <[email protected]>2021-10-03 06:41:14 -0700
commit38d3ea35017944929f9d52a1c840ace68846fee9 (patch)
tree3e667cfd07130b4e09d21658fdf48ba0d9e89163
parentc66e4f5bd447d2bb1a38446510bff87ada00fb9f (diff)
Make simpler likely/unlikely functions and use them in some places
-rw-r--r--al/error.cpp2
-rw-r--r--al/event.cpp8
-rw-r--r--al/extension.cpp2
-rw-r--r--alc/backends/pipewire.cpp12
-rw-r--r--common/opthelpers.h4
5 files changed, 16 insertions, 12 deletions
diff --git a/al/error.cpp b/al/error.cpp
index b5b6f430..8cabf8c3 100644
--- a/al/error.cpp
+++ b/al/error.cpp
@@ -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);
diff --git a/al/event.cpp b/al/event.cpp
index fd4667f7..2c5fa539 100644
--- a/al/event.cpp
+++ b/al/event.cpp
@@ -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};
diff --git a/al/extension.cpp b/al/extension.cpp
index d47bb576..5dda2a86 100644
--- a/al/extension.cpp
+++ b/al/extension.cpp
@@ -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");
diff --git a/alc/backends/pipewire.cpp b/alc/backends/pipewire.cpp
index 5c09a289..0015690b 100644
--- a/alc/backends/pipewire.cpp
+++ b/alc/backends/pipewire.cpp
@@ -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)};
diff --git a/common/opthelpers.h b/common/opthelpers.h
index bb0b63fe..87045739 100644
--- a/common/opthelpers.h
+++ b/common/opthelpers.h
@@ -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)