]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/threadgui.inc
* Corrected #include "thread.h" => #include "wx/thread.h"
[wxWidgets.git] / src / gtk1 / threadgui.inc
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: threadgui.inc
3 // Purpose: GUI thread manager for GTK
4 // Author: Original from Wolfram Gloger/Guilhem Lavaux
5 // Modified by:
6 // Created: 04/22/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Wolfram Gloger (1996, 1997); Guilhem Lavaux (1998)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include <stdio.h>
13 #include <unistd.h>
14
15 // for select()
16 #include <sys/time.h>
17 #include <sys/types.h>
18 #ifdef __sgi
19 #include <bstring.h>
20 #endif
21
22 #include <gdk/gdk.h>
23
24
25 /////////////////////////////////////////////////////////////////////////////
26 // Static variables
27 /////////////////////////////////////////////////////////////////////////////
28
29 static int p_thrd_pipe[2] = { -1, -1 };
30 // WorkProc in GTK
31 static gint p_thrd_inid;
32
33 #define THREAD_SEND_EXIT_MSG(ptr) write(p_thrd_pipe[1], &ptr, sizeof(ptr));
34
35 static void
36 ThreadExitProc(gpointer WXUNUSED(client), gint fid,
37 GdkInputCondition WXUNUSED(cond))
38 {
39 wxThread* ptr;
40
41 if (fid != p_thrd_pipe[0])
42 return;
43 if (read(fid, &ptr, sizeof(ptr)) == sizeof(ptr)) {
44 //fprintf(stderr, "calling OnExit %p\n", ptr);
45 ptr->OnExit();
46 } else {
47 //fprintf(stderr, "this should never happen\n");
48 }
49 }
50
51 // Global initialization
52 static void wxThreadGuiInit()
53 {
54 pipe(p_thrd_pipe);
55 p_thrd_inid = gdk_input_add(p_thrd_pipe[0], GDK_INPUT_READ,
56 ThreadExitProc, 0);
57 }
58
59 // Global cleanup
60 static void wxThreadGuiExit()
61 {
62 gdk_input_remove(p_thrd_inid);
63 close(p_thrd_pipe[0]);
64 close(p_thrd_pipe[1]);
65 }