fixed subsequent connection bug

This commit is contained in:
C-o-r-E
2012-08-20 18:19:17 -04:00
parent ebc699dde8
commit 93d57c5219
3 changed files with 59 additions and 40 deletions

View File

@@ -114,7 +114,7 @@ void wf_info_mirror_init(wfInfo * info, wfPeerContext* context)
//todo: i think i can replace all the context->info here with info
//in fact i may not even care about subscribers
//in fact it may not even care about subscribers
void wf_info_subscriber_release(wfInfo* info, wfPeerContext* context)
{
DWORD dRes;
@@ -122,29 +122,28 @@ void wf_info_subscriber_release(wfInfo* info, wfPeerContext* context)
WaitForSingleObject(info->mutex, INFINITE);
if (context && (info->subscribers == 1))
{
--info->subscribers;
//only the last peer needs to call this
wf_mirror_cleanup(context->wfInfo);
wf_disp_device_set_attatch(context->wfInfo, 0);
wf_update_mirror_drv(context->wfInfo, 1);
stream_free(context->s);
rfx_context_free(context->rfx_context);
printf("Stop encoder\n");
dRes = WaitForSingleObject(info->encodeMutex, INFINITE);
switch (dRes)
{
// The thread got ownership of the mutex
case WAIT_OBJECT_0:
printf("Thread %d locked encodeMutex...\n", GetCurrentThreadId());
--info->subscribers;
//only the last peer needs to call this
wf_mirror_cleanup(context->wfInfo);
wf_disp_device_set_attatch(context->wfInfo, 0);
wf_update_mirror_drv(context->wfInfo, 1);
stream_free(context->s);
rfx_context_free(context->rfx_context);
printf("Stop encoder\n");
break;
// The thread got ownership of an abandoned mutex
// The database is in an indeterminate state
default:
printf("Something else happened!!! dRes = %d\n", dRes);
printf("wf_info_subscriber_release: Something else happened!!! dRes = %d\n", dRes);
}
}
else
@@ -282,4 +281,22 @@ int wf_info_get_width(wfInfo* info)
ReleaseMutex(info->mutex);
return ret;
}
}
int wf_info_get_thread_count(wfInfo* info)
{
int ret;
WaitForSingleObject(info->mutex, INFINITE);
ret = info->threadCnt;
ReleaseMutex(info->mutex);
return ret;
}
void wf_info_set_thread_count(wfInfo* info, int count)
{
WaitForSingleObject(info->mutex, INFINITE);
info->threadCnt = count;
ReleaseMutex(info->mutex);
}

View File

@@ -57,6 +57,9 @@ wfInfo* wf_info_init(wfInfo* info);
void wf_info_mirror_init(wfInfo* info, wfPeerContext* context);
void wf_info_subscriber_release(wfInfo* info, wfPeerContext* context);
int wf_info_get_thread_count(wfInfo* info);
void wf_info_set_thread_count(wfInfo* info, int count);
BOOL wf_info_has_subscribers(wfInfo* info);
BOOL wf_info_have_updates(wfInfo* info);
void wf_info_updated(wfInfo* info);

View File

@@ -82,6 +82,7 @@ static DWORD WINAPI wf_peer_mirror_monitor(LPVOID lpParam)
}
_tprintf(_T("monitor thread terminating...\n"));
wf_info_set_thread_count(wfInfoSingleton, wf_info_get_thread_count(wfInfoSingleton) - 1 );
return 0;
}
@@ -98,20 +99,7 @@ void wf_rfx_encode(freerdp_peer* client)
long offset;
int dRes;
update = client->update;
wfp = (wfPeerContext*) client->context;
cmd = &update->surface_bits_command;
wfi = wfp->wfInfo;
buf = (GETCHANGESBUF*)wfi->changeBuffer;
/*
if( (wfp->activated == false) || (wf_info_has_subscribers(wfi) == false) )
return;
if ( !wf_info_have_invalid_region(wfi) )
return;
*/
dRes = WaitForSingleObject(wfInfoSingleton->encodeMutex, INFINITE);
switch(dRes)
@@ -121,18 +109,20 @@ void wf_rfx_encode(freerdp_peer* client)
wf_info_find_invalid_region(wfInfoSingleton);
if( (wfp->activated == false) ||
(wf_info_has_subscribers(wfi) == false) ||
!wf_info_have_invalid_region(wfi) )
(wf_info_has_subscribers(wfInfoSingleton) == false) ||
!wf_info_have_invalid_region(wfInfoSingleton) )
{
ReleaseMutex(wfInfoSingleton->encodeMutex);
break;
}
//printf("encode %d\n", wfi->nextUpdate - wfi->lastUpdate);
//printf("\tinvlaid region = (%d, %d), (%d, %d)\n", wfi->invalid_x1, wfi->invalid_y1, wfi->invalid_x2, wfi->invalid_y2);
update = client->update;
cmd = &update->surface_bits_command;
wfi = wfp->wfInfo;
buf = (GETCHANGESBUF*)wfi->changeBuffer;
//wfi->lastUpdate = wfi->nextUpdate;
//printf("encode %d\n", wfi->nextUpdate - wfi->lastUpdate);
//printf("\tinvlaid region = (%d, %d), (%d, %d)\n", wfi->invalid_x1, wfi->invalid_y1, wfi->invalid_x2, wfi->invalid_y2);
width = wfi->invalid_x2 - wfi->invalid_x1;
height = wfi->invalid_y2 - wfi->invalid_y1;
@@ -174,8 +164,13 @@ void wf_rfx_encode(freerdp_peer* client)
ReleaseMutex(wfInfoSingleton->encodeMutex);
break;
case WAIT_ABANDONED:
printf("\n\nwf_rfx_encode: Got ownership of abandoned mutex... releasing...\n", dRes);
ReleaseMutex(wfInfoSingleton->encodeMutex);
break;
default:
printf("\n\nSomething else happened!!! dRes = %d\n", dRes);
printf("\n\nwf_rfx_encode: Something else happened!!! dRes = %d\n", dRes);
}
}
@@ -189,11 +184,15 @@ void wf_peer_init(freerdp_peer* client)
client->ContextFree = (psPeerContextFree) wf_peer_context_free;
freerdp_peer_context_new(client);
_tprintf(_T("Trying to create a monitor thread...\n"));
if(!wf_info_get_thread_count(wfInfoSingleton))
{
_tprintf(_T("Trying to create a monitor thread...\n"));
if (CreateThread(NULL, 0, wf_peer_mirror_monitor, client, 0, NULL) != 0)
_tprintf(_T("Created!\n"));
if (CreateThread(NULL, 0, wf_peer_mirror_monitor, client, 0, NULL) != 0)
_tprintf(_T("Created!\n"));
wf_info_set_thread_count(wfInfoSingleton, wf_info_get_thread_count(wfInfoSingleton) + 1 );
}
}
boolean wf_peer_post_connect(freerdp_peer* client)
@@ -286,7 +285,7 @@ void wf_peer_send_changes(rdpUpdate* update)
default:
printf("Something else happened!!! dRes = %d\n", dRes);
printf("wf_peer_send_changes: Something else happened!!! dRes = %d\n", dRes);
}