wfreerdp-server: cleaned up synchronization code

This commit is contained in:
C-o-r-E 2012-08-30 15:50:46 -04:00
parent fdfc5f8f1c
commit 88ad2661bd
3 changed files with 25 additions and 30 deletions

View File

@ -31,11 +31,11 @@
extern wfInfo * wfInfoSingleton;
int wf_info_lock()
int wf_info_lock(DWORD ms)
{
DWORD dRes;
dRes = WaitForSingleObject(wfInfoSingleton->mutex, INFINITE);
dRes = WaitForSingleObject(wfInfoSingleton->mutex, ms);
switch(dRes)
{
@ -207,13 +207,6 @@ void wf_info_subscriber_release(wfInfo* wfi, wfPeerContext* context)
BOOL wf_info_has_subscribers(wfInfo* wfi)
{
int subs;
WaitForSingleObject(wfi->mutex, INFINITE);
subs = wfi->subscribers;
ReleaseMutex(wfi->mutex);
if (wfi->subscribers > 0)
return TRUE;
@ -223,37 +216,26 @@ BOOL wf_info_has_subscribers(wfInfo* wfi)
BOOL wf_info_have_updates(wfInfo* wfi)
{
BOOL status = TRUE;
WaitForSingleObject(wfi->mutex, INFINITE);
if (wfi->nextUpdate == wfi->lastUpdate)
status = FALSE;
ReleaseMutex(wfi->mutex);
return FALSE;
return status;
return TRUE;
}
void wf_info_updated(wfInfo* wfi)
{
WaitForSingleObject(wfi->mutex, INFINITE);
wfi->lastUpdate = wfi->nextUpdate;
ReleaseMutex(wfi->mutex);
}
void wf_info_update_changes(wfInfo* wfi)
{
GETCHANGESBUF* buf;
WaitForSingleObject(wfi->mutex, INFINITE);
buf = (GETCHANGESBUF*) wfi->changeBuffer;
wfi->nextUpdate = buf->buffer->counter;
ReleaseMutex(wfi->mutex);
}
void wf_info_find_invalid_region(wfInfo* wfi)
@ -261,7 +243,6 @@ void wf_info_find_invalid_region(wfInfo* wfi)
int i;
GETCHANGESBUF* buf;
WaitForSingleObject(wfi->mutex, INFINITE);
buf = (GETCHANGESBUF*) wfi->changeBuffer;
if (wfi->enc_data == FALSE)
@ -292,7 +273,6 @@ void wf_info_find_invalid_region(wfInfo* wfi)
if (wfi->invalid_y2 >= wfi->height)
wfi->invalid_y2 = wfi->height - 1;
ReleaseMutex(wfi->mutex);
}
void wf_info_clear_invalid_region(wfInfo* wfi)

View File

@ -53,7 +53,7 @@ struct wf_info
};
typedef struct wf_info wfInfo;
int wf_info_lock();
int wf_info_lock(DWORD ms);
int wf_info_unlock();
wfInfo* wf_info_init(wfInfo* wfi);

View File

@ -35,6 +35,7 @@
void wf_peer_context_new(freerdp_peer* client, wfPeerContext* context)
{
wfInfoSingleton = wf_info_init(wfInfoSingleton);
wf_info_mirror_init(wfInfoSingleton, context);
}
@ -55,21 +56,27 @@ static DWORD WINAPI wf_peer_mirror_monitor(LPVOID lpParam)
rate = 1000 / fps;
client = (freerdp_peer*) lpParam;
/* TODO: do not encode when no clients are connected */
/* TODO: refactor this */
while (wf_info_has_subscribers(wfInfoSingleton))
while (1)
{
beg = GetTickCount();
wf_info_lock(INFINITE);
if (wf_info_has_subscribers(wfInfoSingleton))
{
wf_info_update_changes(wfInfoSingleton);
wf_info_update_changes(wfInfoSingleton);
if (wf_info_have_updates(wfInfoSingleton))
{
wf_rfx_encode(client);
}
}
else
{
wf_info_unlock();
}
wf_info_unlock();
end = GetTickCount();
diff = end - beg;
@ -107,6 +114,9 @@ void wf_rfx_encode(freerdp_peer* client)
BYTE* srcp;
BYTE* dstp;
#endif
if(client->activated == FALSE)
return;
wfp = (wfPeerContext*) client->context;
dRes = WaitForSingleObject(wfInfoSingleton->encodeMutex, INFINITE);
@ -306,10 +316,14 @@ void wf_peer_send_changes(rdpUpdate* update)
case WAIT_OBJECT_0:
/* are there changes to send? */
if (!wf_info_have_updates(wfInfoSingleton) ||
if ( ((wf_info_lock(0) != 0)) ||
!wf_info_have_updates(wfInfoSingleton) ||
!wf_info_have_invalid_region(wfInfoSingleton) ||
(wfInfoSingleton->enc_data == FALSE))
{
//we dont send
wf_info_unlock();
ReleaseMutex(wfInfoSingleton->encodeMutex);
break;
}
@ -319,6 +333,7 @@ void wf_peer_send_changes(rdpUpdate* update)
update->SurfaceBits(update->context, &update->surface_bits_command);
wfInfoSingleton->enc_data = FALSE;
wf_info_unlock();
ReleaseMutex(wfInfoSingleton->encodeMutex);
break;