[all] provide conditional path optimization hints to the compiler

This commit is contained in:
Geoffrey McRae
2023-11-12 18:26:08 +11:00
parent 7bea919352
commit 929e88b9d3
8 changed files with 117 additions and 94 deletions

View File

@@ -457,7 +457,7 @@ static CaptureResult nvfbc_capture(void)
unsigned int width, height;
getDesktopSize(&width, &height);
if (this->width != width || this->height != height)
if (unlikely(this->width != width || this->height != height))
{
this->resChanged = true;
this->width = width;
@@ -476,7 +476,7 @@ static CaptureResult nvfbc_capture(void)
&grabInfo
);
if (result != CAPTURE_RESULT_OK)
if (unlikely(result != CAPTURE_RESULT_OK))
return result;
bool changed = false;
@@ -651,15 +651,15 @@ done:
static CaptureResult nvfbc_waitFrame(CaptureFrame * frame,
const size_t maxFrameSize)
{
if (this->stop)
if (unlikely(this->stop))
return CAPTURE_RESULT_REINIT;
if (
if (unlikely(
this->grabInfo.dwWidth != this->grabWidth ||
this->grabInfo.dwHeight != this->grabHeight ||
this->grabInfo.dwBufferWidth != this->grabStride ||
this->grabInfo.bIsHDR != this->isHDR ||
this->resChanged)
this->resChanged))
{
this->grabWidth = this->grabInfo.dwWidth;
this->grabHeight = this->grabInfo.dwHeight;
@@ -820,11 +820,11 @@ static CaptureResult nvfbc_getFrame(FrameBuffer * frame, int frameIndex)
static int pointerThread(void * unused)
{
while (!this->stop)
while (likely(!this->stop))
{
lgWaitEvent(this->cursorEvent, TIMEOUT_INFINITE);
if (this->stop)
if (unlikely(this->stop))
break;
CaptureResult result;
@@ -832,14 +832,14 @@ static int pointerThread(void * unused)
void * data;
uint32_t size;
if (!this->getPointerBufferFn(&data, &size))
if (unlikely(!this->getPointerBufferFn(&data, &size)))
{
DEBUG_WARN("failed to get a pointer buffer");
continue;
}
result = NvFBCToSysGetCursor(this->nvfbc, &pointer, data, size);
if (result != CAPTURE_RESULT_OK)
if (unlikely(result != CAPTURE_RESULT_OK))
{
DEBUG_WARN("NvFBCToSysGetCursor failed");
continue;

View File

@@ -927,14 +927,16 @@ int app_main(int argc, char * argv[])
}
}
while(app.state != APP_STATE_SHUTDOWN && (
while(likely(app.state != APP_STATE_SHUTDOWN && (
lgmpHostQueueHasSubs(app.pointerQueue) ||
lgmpHostQueueHasSubs(app.frameQueue)))
lgmpHostQueueHasSubs(app.frameQueue))))
{
if (app.state == APP_STATE_RESTART || app.state == APP_STATE_REINIT)
if (unlikely(
app.state == APP_STATE_RESTART ||
app.state == APP_STATE_REINIT))
break;
if (lgmpHostQueueNewSubs(app.pointerQueue) > 0)
if (unlikely(lgmpHostQueueNewSubs(app.pointerQueue) > 0))
{
LG_LOCK(app.pointerLock);
sendPointer(true);
@@ -951,32 +953,37 @@ int app_main(int argc, char * argv[])
}
const uint64_t captureStart = microtime();
switch(app.iface->capture())
const CaptureResult result = app.iface->capture();
if (likely(result == CAPTURE_RESULT_OK))
previousFrameTime = captureStart;
else if (likely(result == CAPTURE_RESULT_TIMEOUT))
{
case CAPTURE_RESULT_OK:
previousFrameTime = captureStart;
break;
if (!app.iface->asyncCapture)
if (unlikely(app.frameValid &&
lgmpHostQueueNewSubs(app.frameQueue) > 0))
{
LGMP_STATUS status;
if ((status = lgmpHostQueuePost(app.frameQueue, 0,
app.frameMemory[app.frameIndex])) != LGMP_OK)
DEBUG_ERROR("%s", lgmpStatusString(status));
}
}
else
{
switch(result)
{
case CAPTURE_RESULT_REINIT:
app.state = APP_STATE_RESTART;
continue;
case CAPTURE_RESULT_TIMEOUT:
if (!app.iface->asyncCapture)
if (app.frameValid && lgmpHostQueueNewSubs(app.frameQueue) > 0)
{
LGMP_STATUS status;
if ((status = lgmpHostQueuePost(app.frameQueue, 0,
app.frameMemory[app.frameIndex])) != LGMP_OK)
DEBUG_ERROR("%s", lgmpStatusString(status));
}
case CAPTURE_RESULT_ERROR:
DEBUG_ERROR("Capture interface reported a fatal error");
exitcode = LG_HOST_EXIT_FAILED;
goto fail_capture;
continue;
case CAPTURE_RESULT_REINIT:
app.state = APP_STATE_RESTART;
continue;
case CAPTURE_RESULT_ERROR:
DEBUG_ERROR("Capture interface reported a fatal error");
exitcode = LG_HOST_EXIT_FAILED;
goto fail_capture;
default:
DEBUG_ASSERT("Invalid capture result");
}
}
if (!app.iface->asyncCapture)