hw/xwin: Hoist clipboard thread restart up one level

Hoist clipboard thread restart up one level.

Note that currently g_fClipboardLaunched is set the first time in the
winProcEstablishConnection wrapper, and subsequent times when the clipboard
thread restarts itself.

Try to clarify this and just set g_fClipboardLaunched before starting the
thread.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
This commit is contained in:
Jon TURNEY 2013-06-16 23:57:17 +01:00
parent 0bb6eae4e3
commit 91e55691ef
4 changed files with 43 additions and 39 deletions

View File

@ -60,16 +60,12 @@
#ifdef HAS_DEVWINDOWS
#define WIN_MSG_QUEUE_FNAME "/dev/windows"
#endif
#define WIN_CONNECT_RETRIES 40
#define WIN_CONNECT_DELAY 4
#define WIN_JMP_OKAY 0
#define WIN_JMP_ERROR_IO 2
#define WIN_LOCAL_PROPERTY "CYGX_CUT_BUFFER"
#define WIN_XEVENTS_SUCCESS 0
#define WIN_XEVENTS_CONVERT 2
#define WIN_XEVENTS_NOTIFY 3
#define WIN_CLIPBOARD_RETRIES 40
#define WIN_CLIPBOARD_DELAY 1
#define WM_WM_REINIT (WM_USER + 1)

View File

@ -31,9 +31,16 @@
#ifdef HAVE_XWIN_CONFIG_H
#include <xwin-config.h>
#endif
#include <unistd.h>
#include <pthread.h>
#include "dixstruct.h"
#include "winclipboard.h"
#define WIN_CLIPBOARD_RETRIES 40
#define WIN_CLIPBOARD_DELAY 1
/*
* Local typedefs
*/
@ -58,6 +65,38 @@ extern Bool g_fClipboardStarted;
static pthread_t g_ptClipboardProc;
/*
*
*/
static void *
winClipboardThreadProc(void *arg)
{
int clipboardRestarts = 0;
while (1)
{
++clipboardRestarts;
/* Flag that clipboard client has been launched */
g_fClipboardLaunched = TRUE;
winClipboardProc(arg);
/* checking if we need to restart */
if (clipboardRestarts >= WIN_CLIPBOARD_RETRIES) {
/* terminates clipboard thread but the main server still lives */
ErrorF("winClipboardProc - the clipboard thread has restarted %d times and seems to be unstable, disabling clipboard integration\n", clipboardRestarts);
g_fClipboard = FALSE;
break;
}
sleep(WIN_CLIPBOARD_DELAY);
ErrorF("winClipboardProc - trying to restart clipboard thread \n");
}
return NULL;
}
/*
* Intialize the Clipboard module
*/
@ -74,7 +113,7 @@ winInitClipboard(void)
}
/* Spawn a thread for the Clipboard module */
if (pthread_create(&g_ptClipboardProc, NULL, winClipboardProc, NULL)) {
if (pthread_create(&g_ptClipboardProc, NULL, winClipboardThreadProc, NULL)) {
/* Bail if thread creation failed */
ErrorF("winInitClipboard - pthread_create failed.\n");
return FALSE;

View File

@ -44,6 +44,9 @@
#endif
#include "misc.h"
#define WIN_CONNECT_RETRIES 40
#define WIN_CONNECT_DELAY 4
/*
* References to external symbols
*/
@ -61,7 +64,6 @@ extern Window g_iClipboardWindow;
*/
static jmp_buf g_jmpEntry;
static int clipboardRestarts = 0;
static XIOErrorHandler g_winClipboardOldIOErrorHandler;
static pthread_t g_winClipboardProcThread;
@ -104,7 +106,6 @@ winClipboardProc(void *pvNotUsed)
int iSelectError;
winDebug("winClipboardProc - Hello\n");
++clipboardRestarts;
/* Do we use Unicode clipboard? */
fUseUnicode = g_fUnicodeClipboard;
@ -400,35 +401,6 @@ winClipboardProc(void *pvNotUsed)
g_pClipboardDisplay = NULL;
g_hwndClipboard = NULL;
/* checking if we need to restart */
if (clipboardRestarts >= WIN_CLIPBOARD_RETRIES) {
/* terminates clipboard thread but the main server still lives */
ErrorF
("winClipboardProc - the clipboard thread has restarted %d times and seems to be unstable, disabling clipboard integration\n",
clipboardRestarts);
g_fClipboard = FALSE;
return NULL;
}
if (g_fClipboard) {
sleep(WIN_CLIPBOARD_DELAY);
ErrorF("winClipboardProc - trying to restart clipboard thread \n");
/* Create the clipboard client thread */
if (!winInitClipboard()) {
ErrorF("winClipboardProc - winClipboardInit failed.\n");
return NULL;
}
winDebug("winClipboardProc - winInitClipboard returned.\n");
/* Flag that clipboard client has been launched */
g_fClipboardLaunched = TRUE;
}
else {
ErrorF("winClipboardProc - Clipboard disabled - Exit from server \n");
/* clipboard thread has exited, stop server as well */
raise(SIGTERM);
}
return NULL;
}

View File

@ -163,9 +163,6 @@ winProcEstablishConnection(ClientPtr client)
ErrorF("winProcEstablishConnection - winInitClipboard returned.\n");
}
/* Flag that clipboard client has been launched */
g_fClipboardLaunched = TRUE;
return iReturn;
}