summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon TURNEY <jon.turney@dronecode.org.uk>2013-06-12 16:51:17 +0100
committerJon TURNEY <jon.turney@dronecode.org.uk>2013-06-12 16:51:17 +0100
commit341040f37e15ec07bec42bff9976a57a5c68f3fe (patch)
tree21e81a9fcadf44f60b6b1ca436959359d3042aa6
parent6e59bcae602813a5985dae58e433614e82545f3f (diff)
Hoist up winclip thread restart one level
and clean up a bit the idempotency and shutdown logic This needs cleaning up so it's clear we start the thread once when the wrapper tells us to (wrapper turns itself off thereafter so should be easy) and we wait for thread to exit on server restart
-rw-r--r--hw/xwin/InitOutput.c40
-rw-r--r--hw/xwin/winclipboard.h2
-rw-r--r--hw/xwin/winclipboardinit.c67
-rw-r--r--hw/xwin/winclipboardthread.c32
-rw-r--r--hw/xwin/winclipboardwrappers.c3
5 files changed, 64 insertions, 80 deletions
diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c
index 9afd6a72b..91a711709 100644
--- a/hw/xwin/InitOutput.c
+++ b/hw/xwin/InitOutput.c
@@ -63,27 +63,12 @@ typedef WINAPI HRESULT(*SHGETFOLDERPATHPROC) (HWND hwndOwner,
/*
* References to external symbols
*/
-#ifdef XWIN_CLIPBOARD
-extern Bool g_fUnicodeClipboard;
-extern Bool g_fClipboardLaunched;
-extern Bool g_fClipboardStarted;
-extern pthread_t g_ptClipboardProc;
-extern HWND g_hwndClipboard;
-extern Bool g_fClipboard;
-#endif
-
extern Bool noRRXineramaExtension;
/*
* Function prototypes
*/
-#ifdef XWIN_CLIPBOARD
-static void
- winClipboardShutdown(void);
-#endif
-
-
void
winLogCommandLine(int argc, char *argv[]);
@@ -127,31 +112,6 @@ static PixmapFormatRec g_PixmapFormats[] = {
const int NUMFORMATS = sizeof(g_PixmapFormats) / sizeof(g_PixmapFormats[0]);
-#ifdef XWIN_CLIPBOARD
-static void
-winClipboardShutdown(void)
-{
- /* Close down clipboard resources */
- if (g_fClipboard && g_fClipboardLaunched && g_fClipboardStarted) {
- /* Synchronously destroy the clipboard window */
- if (g_hwndClipboard != NULL) {
- SendMessage(g_hwndClipboard, WM_DESTROY, 0, 0);
- /* NOTE: g_hwndClipboard is set to NULL in winclipboardthread.c */
- }
- else
- return;
-
- /* Wait for the clipboard thread to exit */
- pthread_join(g_ptClipboardProc, NULL);
-
- g_fClipboardLaunched = FALSE;
- g_fClipboardStarted = FALSE;
-
- winDebug("winClipboardShutdown - Clipboard thread has exited.\n");
- }
-}
-#endif
-
static const ExtensionModule xwinExtensions[] = {
#ifdef GLXEXT
{ GlxExtensionInit, "GLX", &noGlxExtension },
diff --git a/hw/xwin/winclipboard.h b/hw/xwin/winclipboard.h
index b77a58a95..3db9cb270 100644
--- a/hw/xwin/winclipboard.h
+++ b/hw/xwin/winclipboard.h
@@ -72,8 +72,6 @@
#define WIN_XEVENTS_SHUTDOWN 1
#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)
diff --git a/hw/xwin/winclipboardinit.c b/hw/xwin/winclipboardinit.c
index 70f106ec9..ad12d206f 100644
--- a/hw/xwin/winclipboardinit.c
+++ b/hw/xwin/winclipboardinit.c
@@ -28,14 +28,18 @@
* Authors: Harold L Hunt II
*/
-#include <assert.h>
-
#ifdef HAVE_XWIN_CONFIG_H
#include <xwin-config.h>
#endif
+#include <assert.h>
+#include <unistd.h>
+
#include "winclipboard.h"
+#define WIN_CLIPBOARD_RETRIES 40
+#define WIN_CLIPBOARD_DELAY 1
+
/*
* References to external symbols
*/
@@ -43,6 +47,40 @@
extern pthread_t g_ptClipboardProc;
extern Bool g_fClipboard;
extern HWND g_hwndClipboard;
+extern Bool g_fClipboardLaunched;
+extern Bool g_fClipboardStarted;
+
+/*
+ *
+ */
+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
@@ -54,7 +92,7 @@ winInitClipboard(void)
winDebug("winInitClipboard ()\n");
/* 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;
@@ -63,6 +101,29 @@ winInitClipboard(void)
return TRUE;
}
+void
+winClipboardShutdown(void)
+{
+ /* Close down clipboard resources */
+ if (g_fClipboard && g_fClipboardLaunched && g_fClipboardStarted) {
+ /* Synchronously destroy the clipboard window */
+ if (g_hwndClipboard != NULL) {
+ SendMessage(g_hwndClipboard, WM_DESTROY, 0, 0);
+ /* NOTE: g_hwndClipboard is set to NULL in winclipboardthread.c */
+ }
+ else
+ return;
+
+ /* Wait for the clipboard thread to exit */
+ pthread_join(g_ptClipboardProc, NULL);
+
+ g_fClipboardLaunched = FALSE;
+ g_fClipboardStarted = FALSE;
+
+ winDebug("winClipboardShutdown - Clipboard thread has exited.\n");
+ }
+}
+
/*
* Create the Windows window that we use to recieve Windows messages
*/
diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c
index 351a13624..335607ed6 100644
--- a/hw/xwin/winclipboardthread.c
+++ b/hw/xwin/winclipboardthread.c
@@ -71,7 +71,6 @@ extern Window g_iClipboardWindow;
* Global variables
*/
-static int clipboardRestarts = 0;
int xfixes_event_base;
/*
@@ -167,7 +166,6 @@ winClipboardProc(void *pvNotUsed)
pthread_cleanup_push(&winClipboardThreadExit, NULL);
winDebug("winClipboardProc - Hello\n");
- ++clipboardRestarts;
/* Use our generated cookie for authentication */
winSetAuthorization();
@@ -469,36 +467,6 @@ winClipboardProc(void *pvNotUsed)
g_pClipboardConn = NULL;
g_hwndClipboard = NULL;
- //XXX: hoist this restart checking up to next level
- /* 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);
- }
-
pthread_cleanup_pop(0);
return NULL;
}
diff --git a/hw/xwin/winclipboardwrappers.c b/hw/xwin/winclipboardwrappers.c
index efa86aba5..054c007ca 100644
--- a/hw/xwin/winclipboardwrappers.c
+++ b/hw/xwin/winclipboardwrappers.c
@@ -156,8 +156,5 @@ winProcEstablishConnection(ClientPtr client)
ErrorF("winProcEstablishConnection - winInitClipboard returned.\n");
}
- /* Flag that clipboard client has been launched */
- g_fClipboardLaunched = TRUE;
-
return iReturn;
}