]>
Commit | Line | Data |
---|---|---|
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 | // printf( "thread exit proc.\n" ); | |
41 | ||
42 | if (fid != p_thrd_pipe[0]) | |
43 | return; | |
44 | ||
45 | if (read(fid, &ptr, sizeof(ptr)) == sizeof(ptr)) | |
46 | { | |
47 | // printf( "calling OnExit %p\n", ptr); | |
48 | ptr->OnExit(); | |
49 | } | |
50 | else | |
51 | { | |
52 | // printf( "this should never happen\n" ); | |
53 | } | |
54 | } | |
55 | ||
56 | // Global initialization | |
57 | static void wxThreadGuiInit() | |
58 | { | |
59 | pipe(p_thrd_pipe); | |
60 | p_thrd_inid = gdk_input_add(p_thrd_pipe[0], GDK_INPUT_READ, | |
61 | ThreadExitProc, 0); | |
62 | } | |
63 | ||
64 | // Global cleanup | |
65 | static void wxThreadGuiExit() | |
66 | { | |
67 | gdk_input_remove(p_thrd_inid); | |
68 | close(p_thrd_pipe[0]); | |
69 | close(p_thrd_pipe[1]); | |
70 | } | |
71 | ||
72 | void wxMutexGuiEnter() | |
73 | { | |
74 | wxMainMutex->Lock(); | |
75 | } | |
76 | ||
77 | void wxMutexGuiLeave() | |
78 | { | |
79 | wxMainMutex->Unlock(); | |
80 | } | |
81 |