]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/threadgui.inc
Added wxMiniFrame
[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 // Static variables
26 /////////////////////////////////////////////////////////////////////////////
27
28 static int p_thrd_pipe[2] = { -1, -1 };
29 // WorkProc in GTK
30 static gint p_thrd_inid;
31
32 #define THREAD_SEND_EXIT_MSG(ptr) write(p_thrd_pipe[1], &ptr, sizeof(ptr));
33
34 static void
35 ThreadExitProc(gpointer WXUNUSED(client), gint fid,
36 GdkInputCondition WXUNUSED(cond))
37 {
38 wxThread* ptr;
39
40 if (fid != p_thrd_pipe[0])
41 return;
42 if (read(fid, &ptr, sizeof(ptr)) == sizeof(ptr)) {
43 //fprintf(stderr, "calling OnExit %p\n", ptr);
44 ptr->OnExit();
45 } else {
46 //fprintf(stderr, "this should never happen\n");
47 }
48 }
49
50 // Global initialization
51 static void wxThreadGuiInit()
52 {
53 pipe(p_thrd_pipe);
54 p_thrd_inid = gdk_input_add(p_thrd_pipe[0], GDK_INPUT_READ,
55 ThreadExitProc, 0);
56 }
57
58 // Global cleanup
59 static void wxThreadGuiExit()
60 {
61 gdk_input_remove(p_thrd_inid);
62 close(p_thrd_pipe[0]);
63 close(p_thrd_pipe[1]);
64 }
65
66 #ifdef NO_DEFINE_GDK_1_1
67
68 void wxMutexGuiEnter()
69 {
70 gdk_mutex_enter();
71 }
72
73 void wxMutexGuiLeave()
74 {
75 gdk_mutex_leave();
76 }
77
78 #else
79
80 void wxMutexGuiEnter()
81 {
82 wxMainMutex->Lock();
83 }
84
85 void wxMutexGuiLeave()
86 {
87 wxMainMutex->Unlock();
88 }
89
90 #endif