shadow: improve synchronization barrier usage

This commit is contained in:
Marc-André Moreau 2014-08-08 20:51:26 -04:00
parent 8b4cf07c8a
commit 54264936d1
5 changed files with 30 additions and 38 deletions

View File

@ -298,15 +298,12 @@ void* x11_shadow_subsystem_thread(x11ShadowSubsystem* subsystem)
int fps;
DWORD status;
DWORD nCount;
XEvent xevent;
UINT64 cTime;
DWORD dwTimeout;
DWORD dwInterval;
UINT64 frameTime;
HANDLE events[32];
HANDLE StopEvent;
int x, y, width, height;
XDamageNotifyEvent* notify;
StopEvent = subsystem->server->StopEvent;
@ -320,13 +317,8 @@ void* x11_shadow_subsystem_thread(x11ShadowSubsystem* subsystem)
while (1)
{
dwTimeout = INFINITE;
if (!subsystem->use_xdamage)
{
cTime = GetTickCount64();
dwTimeout = (cTime > frameTime) ? 0 : frameTime - cTime;
}
cTime = GetTickCount64();
dwTimeout = (cTime > frameTime) ? 0 : frameTime - cTime;
status = WaitForMultipleObjects(nCount, events, FALSE, dwTimeout);
@ -335,33 +327,12 @@ void* x11_shadow_subsystem_thread(x11ShadowSubsystem* subsystem)
break;
}
while (XPending(subsystem->display))
if ((status == WAIT_TIMEOUT) || (GetTickCount64() > frameTime))
{
ZeroMemory(&xevent, sizeof(xevent));
XNextEvent(subsystem->display, &xevent);
x11_shadow_screen_grab(subsystem);
if (xevent.type == subsystem->xdamage_notify_event)
{
notify = (XDamageNotifyEvent*) &xevent;
x = notify->area.x;
y = notify->area.y;
width = notify->area.width;
height = notify->area.height;
x11_shadow_invalidate_region(subsystem, x, y, width, height);
}
}
if (!subsystem->use_xdamage)
{
if ((status == WAIT_TIMEOUT) || (GetTickCount64() > frameTime))
{
x11_shadow_screen_grab(subsystem);
dwInterval = 1000 / fps;
frameTime += dwInterval;
}
dwInterval = 1000 / fps;
frameTime += dwInterval;
}
}

View File

@ -151,6 +151,9 @@ int shadow_capture_compare(BYTE* pData1, int nStep1, int nWidth, int nHeight, BY
printf("|%s|\n", rows[ty] ? "O" : "X");
}
printf("left: %d top: %d right: %d bottom: %d ncol: %d nrow: %d\n",
l, t, r, b, ncol, nrow);
}
return 1;

View File

@ -567,8 +567,8 @@ int shadow_client_send_surface_update(rdpShadowClient* client)
nWidth = extents->right - extents->left;
nHeight = extents->bottom - extents->top;
printf("shadow_client_send_surface_update: x: %d y: %d width: %d height: %d right: %d bottom: %d\n",
nXSrc, nYSrc, nWidth, nHeight, nXSrc + nWidth, nYSrc + nHeight);
//printf("shadow_client_send_surface_update: x: %d y: %d width: %d height: %d right: %d bottom: %d\n",
// nXSrc, nYSrc, nWidth, nHeight, nXSrc + nWidth, nYSrc + nHeight);
if (settings->RemoteFxCodec || settings->NSCodec)
{

View File

@ -29,6 +29,8 @@
#ifndef _WIN32
#include <errno.h>
BOOL WINAPI InitializeSynchronizationBarrier(LPSYNCHRONIZATION_BARRIER lpBarrier, LONG lTotalThreads, LONG lSpinCount)
{
int status;
@ -50,10 +52,22 @@ BOOL WINAPI InitializeSynchronizationBarrier(LPSYNCHRONIZATION_BARRIER lpBarrier
pBarrier->lTotalThreads = lTotalThreads;
pBarrier->lSpinCount = lSpinCount;
status = pthread_barrier_init(&(pBarrier->barrier), NULL, pBarrier->lTotalThreads);
status = pthread_barrierattr_init(&(pBarrier->attr));
if (status != 0)
{
fprintf(stderr, "pthread_barrierattr_init failure: %d\n", errno);
free(pBarrier);
return FALSE;
}
pthread_barrierattr_setpshared(&(pBarrier->attr), PTHREAD_PROCESS_SHARED);
status = pthread_barrier_init(&(pBarrier->barrier), &(pBarrier->attr), lTotalThreads);
if (status != 0)
{
fprintf(stderr, "pthread_barrier_init failure: %d\n", errno);
free(pBarrier);
return FALSE;
}
@ -89,6 +103,7 @@ BOOL WINAPI EnterSynchronizationBarrier(LPSYNCHRONIZATION_BARRIER lpBarrier, DWO
}
else
{
fprintf(stderr, "pthread_barrier_wait failure: %d\n", errno);
status = FALSE; /* failure */
}
@ -113,6 +128,8 @@ BOOL WINAPI DeleteSynchronizationBarrier(LPSYNCHRONIZATION_BARRIER lpBarrier)
pthread_barrier_destroy(&(pBarrier->barrier));
pthread_barrierattr_destroy(&(pBarrier->attr));
free(pBarrier);
ZeroMemory(lpBarrier, sizeof(SYNCHRONIZATION_BARRIER));

View File

@ -151,6 +151,7 @@ struct winpr_barrier
#if !defined(_WIN32)
pthread_barrier_t barrier;
pthread_barrierattr_t attr;
#elif (defined(_WIN32) && (_WIN32_WINNT < 0x0602))
HANDLE event;
DECLSPEC_ALIGN(4) LONG count;