summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@gtk.org>1998-05-16 02:13:12 +0000
committerOwen Taylor <otaylor@src.gnome.org>1998-05-16 02:13:12 +0000
commit457148333e72c2bc607268ce4922c531aaf33181 (patch)
tree869e8cb6ad75e382de86fbce844141266171fca2
parent123e299bcf4a86e8078d77d4f3d4367638cded94 (diff)
downloadgtk+-457148333e72c2bc607268ce4922c531aaf33181.tar.gz
Basic thread-awareness:
Fri May 15 21:16:54 1998 Owen Taylor <otaylor@gtk.org> Basic thread-awareness: * acconfig.h configure.in: New option --with-threads=[yes/posix/no] * gdk/Makefile.am gdk/gdkthreads.c: Added new functions gdk_threads_[init/enter/leave] for applications, plus gdk_threads_wake to wake the mainloop thread out of the select(). * gtk/Makefile.am: gtk/testthreads.c: Test program for threads Fri May 15 12:08:48 1998 Owen Taylor <otaylor@gtk.org> * gtk/testgtk.c (list_clear): Account for the fact that gtk_list_clear_items is not inclusive. (Clears [start, end))
-rw-r--r--ChangeLog19
-rw-r--r--ChangeLog.pre-2-019
-rw-r--r--ChangeLog.pre-2-1019
-rw-r--r--ChangeLog.pre-2-219
-rw-r--r--ChangeLog.pre-2-419
-rw-r--r--ChangeLog.pre-2-619
-rw-r--r--ChangeLog.pre-2-819
-rw-r--r--acconfig.h3
-rw-r--r--config.h.in3
-rw-r--r--configure.in10
-rw-r--r--gdk/Makefile.am1
-rw-r--r--gdk/gdk.c23
-rw-r--r--gdk/gdk.h8
-rw-r--r--gdk/gdkglobals.c11
-rw-r--r--gdk/gdkprivate.h7
-rw-r--r--gdk/x11/gdkglobals-x11.c11
-rw-r--r--gdk/x11/gdkmain-x11.c23
-rw-r--r--gtk/Makefile.am4
-rw-r--r--gtk/gtkmain.c7
-rw-r--r--gtk/testgtk.c2
-rw-r--r--tests/testgtk.c2
21 files changed, 245 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 1c4794eb3a..5bc1fa0030 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+Fri May 15 21:16:54 1998 Owen Taylor <otaylor@gtk.org>
+
+ Basic thread-awareness:
+
+ * acconfig.h configure.in: New option --with-threads=[yes/posix/no]
+
+ * gdk/Makefile.am gdk/gdkthreads.c: Added new functions
+ gdk_threads_[init/enter/leave] for applications, plus
+ gdk_threads_wake to wake the mainloop thread out of
+ the select().
+
+ * gtk/Makefile.am: gtk/testthreads.c: Test program for threads
+
+Fri May 15 12:08:48 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gtk/testgtk.c (list_clear): Account for the fact
+ that gtk_list_clear_items is not inclusive. (Clears
+ [start, end))
+
Fri May 15 12:31:27 1998 rodo <doulik@karlin.mff.cuni.cz>
* gdk/gdk.c: include gdkkeysyms.h always
diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0
index 1c4794eb3a..5bc1fa0030 100644
--- a/ChangeLog.pre-2-0
+++ b/ChangeLog.pre-2-0
@@ -1,3 +1,22 @@
+Fri May 15 21:16:54 1998 Owen Taylor <otaylor@gtk.org>
+
+ Basic thread-awareness:
+
+ * acconfig.h configure.in: New option --with-threads=[yes/posix/no]
+
+ * gdk/Makefile.am gdk/gdkthreads.c: Added new functions
+ gdk_threads_[init/enter/leave] for applications, plus
+ gdk_threads_wake to wake the mainloop thread out of
+ the select().
+
+ * gtk/Makefile.am: gtk/testthreads.c: Test program for threads
+
+Fri May 15 12:08:48 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gtk/testgtk.c (list_clear): Account for the fact
+ that gtk_list_clear_items is not inclusive. (Clears
+ [start, end))
+
Fri May 15 12:31:27 1998 rodo <doulik@karlin.mff.cuni.cz>
* gdk/gdk.c: include gdkkeysyms.h always
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index 1c4794eb3a..5bc1fa0030 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,3 +1,22 @@
+Fri May 15 21:16:54 1998 Owen Taylor <otaylor@gtk.org>
+
+ Basic thread-awareness:
+
+ * acconfig.h configure.in: New option --with-threads=[yes/posix/no]
+
+ * gdk/Makefile.am gdk/gdkthreads.c: Added new functions
+ gdk_threads_[init/enter/leave] for applications, plus
+ gdk_threads_wake to wake the mainloop thread out of
+ the select().
+
+ * gtk/Makefile.am: gtk/testthreads.c: Test program for threads
+
+Fri May 15 12:08:48 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gtk/testgtk.c (list_clear): Account for the fact
+ that gtk_list_clear_items is not inclusive. (Clears
+ [start, end))
+
Fri May 15 12:31:27 1998 rodo <doulik@karlin.mff.cuni.cz>
* gdk/gdk.c: include gdkkeysyms.h always
diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2
index 1c4794eb3a..5bc1fa0030 100644
--- a/ChangeLog.pre-2-2
+++ b/ChangeLog.pre-2-2
@@ -1,3 +1,22 @@
+Fri May 15 21:16:54 1998 Owen Taylor <otaylor@gtk.org>
+
+ Basic thread-awareness:
+
+ * acconfig.h configure.in: New option --with-threads=[yes/posix/no]
+
+ * gdk/Makefile.am gdk/gdkthreads.c: Added new functions
+ gdk_threads_[init/enter/leave] for applications, plus
+ gdk_threads_wake to wake the mainloop thread out of
+ the select().
+
+ * gtk/Makefile.am: gtk/testthreads.c: Test program for threads
+
+Fri May 15 12:08:48 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gtk/testgtk.c (list_clear): Account for the fact
+ that gtk_list_clear_items is not inclusive. (Clears
+ [start, end))
+
Fri May 15 12:31:27 1998 rodo <doulik@karlin.mff.cuni.cz>
* gdk/gdk.c: include gdkkeysyms.h always
diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4
index 1c4794eb3a..5bc1fa0030 100644
--- a/ChangeLog.pre-2-4
+++ b/ChangeLog.pre-2-4
@@ -1,3 +1,22 @@
+Fri May 15 21:16:54 1998 Owen Taylor <otaylor@gtk.org>
+
+ Basic thread-awareness:
+
+ * acconfig.h configure.in: New option --with-threads=[yes/posix/no]
+
+ * gdk/Makefile.am gdk/gdkthreads.c: Added new functions
+ gdk_threads_[init/enter/leave] for applications, plus
+ gdk_threads_wake to wake the mainloop thread out of
+ the select().
+
+ * gtk/Makefile.am: gtk/testthreads.c: Test program for threads
+
+Fri May 15 12:08:48 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gtk/testgtk.c (list_clear): Account for the fact
+ that gtk_list_clear_items is not inclusive. (Clears
+ [start, end))
+
Fri May 15 12:31:27 1998 rodo <doulik@karlin.mff.cuni.cz>
* gdk/gdk.c: include gdkkeysyms.h always
diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6
index 1c4794eb3a..5bc1fa0030 100644
--- a/ChangeLog.pre-2-6
+++ b/ChangeLog.pre-2-6
@@ -1,3 +1,22 @@
+Fri May 15 21:16:54 1998 Owen Taylor <otaylor@gtk.org>
+
+ Basic thread-awareness:
+
+ * acconfig.h configure.in: New option --with-threads=[yes/posix/no]
+
+ * gdk/Makefile.am gdk/gdkthreads.c: Added new functions
+ gdk_threads_[init/enter/leave] for applications, plus
+ gdk_threads_wake to wake the mainloop thread out of
+ the select().
+
+ * gtk/Makefile.am: gtk/testthreads.c: Test program for threads
+
+Fri May 15 12:08:48 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gtk/testgtk.c (list_clear): Account for the fact
+ that gtk_list_clear_items is not inclusive. (Clears
+ [start, end))
+
Fri May 15 12:31:27 1998 rodo <doulik@karlin.mff.cuni.cz>
* gdk/gdk.c: include gdkkeysyms.h always
diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8
index 1c4794eb3a..5bc1fa0030 100644
--- a/ChangeLog.pre-2-8
+++ b/ChangeLog.pre-2-8
@@ -1,3 +1,22 @@
+Fri May 15 21:16:54 1998 Owen Taylor <otaylor@gtk.org>
+
+ Basic thread-awareness:
+
+ * acconfig.h configure.in: New option --with-threads=[yes/posix/no]
+
+ * gdk/Makefile.am gdk/gdkthreads.c: Added new functions
+ gdk_threads_[init/enter/leave] for applications, plus
+ gdk_threads_wake to wake the mainloop thread out of
+ the select().
+
+ * gtk/Makefile.am: gtk/testthreads.c: Test program for threads
+
+Fri May 15 12:08:48 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gtk/testgtk.c (list_clear): Account for the fact
+ that gtk_list_clear_items is not inclusive. (Clears
+ [start, end))
+
Fri May 15 12:31:27 1998 rodo <doulik@karlin.mff.cuni.cz>
* gdk/gdk.c: include gdkkeysyms.h always
diff --git a/acconfig.h b/acconfig.h
index 600655efb2..82b3d6c73c 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -31,6 +31,9 @@
#undef RESOURCE_BASE
+/* Define to enable POSIX threading awareness */
+#undef USE_PTHREADS
+
#undef XINPUT_NONE
#undef XINPUT_GXI
#undef XINPUT_XFREE
diff --git a/config.h.in b/config.h.in
index c606837d57..b105985b05 100644
--- a/config.h.in
+++ b/config.h.in
@@ -32,6 +32,9 @@
#undef RESOURCE_BASE
+/* Define to enable POSIX threading awareness */
+#undef USE_PTHREADS
+
#undef XINPUT_NONE
#undef XINPUT_GXI
#undef XINPUT_XFREE
diff --git a/configure.in b/configure.in
index 8a0baf923f..74f23e4f61 100644
--- a/configure.in
+++ b/configure.in
@@ -68,6 +68,7 @@ AC_ARG_ENABLE(xim, [ --enable-xim support XIM [default=yes]],
AC_ARG_WITH(locale, [ --with-locale=LOCALE locale name you want to use ])
AC_ARG_WITH(xinput, [ --with-xinput=[no/gxi/xfree] support XInput ])
+AC_ARG_WITH(threads, [ --with-threads=[posix] support threading ])
if test "x$enable_debug" = "xyes"; then
test "$cflags_set" = set || CFLAGS="$CFLAGS -g"
@@ -183,6 +184,15 @@ else
AC_DEFINE(XINPUT_NONE)
fi
+# Threads
+
+if test "x$with_threads" = "xposix" || test "x$with_threads" = "xyes"; then
+ AC_CHECK_LIB(pthread, pthread_create,
+ AC_DEFINE(USE_PTHREADS)
+ x_libs="$x_libs -lpthread"
+ CFLAGS="$CFLAGS -D_REENTRANT")
+fi
+
AC_SUBST(x_cflags)
AC_SUBST(x_includes)
AC_SUBST(x_ldflags)
diff --git a/gdk/Makefile.am b/gdk/Makefile.am
index 3037fd6de7..634e6a9160 100644
--- a/gdk/Makefile.am
+++ b/gdk/Makefile.am
@@ -26,6 +26,7 @@ libgdk_1_1_la_SOURCES = \
gdkrectangle.c \
gdkregion.c \
gdkselection.c \
+ gdkthreads.c \
gdkvisual.c \
gdkwindow.c \
gdkxid.c \
diff --git a/gdk/gdk.c b/gdk/gdk.c
index 54fc747148..eeefa4f1be 100644
--- a/gdk/gdk.c
+++ b/gdk/gdk.c
@@ -1606,8 +1606,31 @@ gdk_event_wait (void)
max_input = MAX (max_input, input->source);
}
+#ifdef USE_PTHREADS
+ if (gdk_using_threads)
+ {
+ gdk_select_waiting = TRUE;
+
+ FD_SET (gdk_threads_pipe[0], &readfds);
+ max_input = MAX (max_input, gdk_threads_pipe[0]);
+ gdk_threads_leave ();
+ }
+#endif
+
nfd = select (max_input+1, &readfds, &writefds, &exceptfds, timerp);
+#ifdef USE_PTHREADS
+ if (gdk_using_threads)
+ {
+ gchar c;
+ gdk_threads_enter ();
+ gdk_select_waiting = FALSE;
+
+ if (FD_ISSET (gdk_threads_pipe[0], &readfds))
+ read (gdk_threads_pipe[0], &c, 1);
+ }
+#endif
+
timerp = NULL;
timer_val = 0;
diff --git a/gdk/gdk.h b/gdk/gdk.h
index 9be074e392..092226d8b3 100644
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -801,6 +801,14 @@ GdkRegion* gdk_regions_subtract (GdkRegion *source1,
GdkRegion* gdk_regions_xor (GdkRegion *source1,
GdkRegion *source2);
+gboolean gdk_threads_init (void);
+void gdk_threads_enter (void);
+void gdk_threads_leave (void);
+
+/* If the mainloop thread is in its select, wake it up.
+ * For GTK's idle handling
+ */
+void gdk_threads_wake (void);
#ifdef __cplusplus
}
diff --git a/gdk/gdkglobals.c b/gdk/gdkglobals.c
index 6e34bfa883..82b67a823f 100644
--- a/gdk/gdkglobals.c
+++ b/gdk/gdkglobals.c
@@ -20,6 +20,7 @@
#include <X11/Xlib.h>
#include "gdktypes.h"
#include "gdkprivate.h"
+#include "../config.h"
guint gdk_debug_flags = 0;
gint gdk_use_xshm = TRUE;
@@ -53,3 +54,13 @@ gint gdk_error_code;
gint gdk_error_warnings = TRUE;
gint gdk_null_window_warnings = TRUE;
GList *gdk_default_filters = NULL;
+
+gboolean gdk_using_threads = FALSE;
+
+/* Used to signal the mainloop thread from its select() */
+#ifdef USE_PTHREADS
+gint gdk_threads_pipe[2];
+gboolean gdk_select_waiting = FALSE;
+#endif
+
+
diff --git a/gdk/gdkprivate.h b/gdk/gdkprivate.h
index 555c8c3820..fcfca025bf 100644
--- a/gdk/gdkprivate.h
+++ b/gdk/gdkprivate.h
@@ -268,6 +268,13 @@ extern gint gdk_error_code;
extern gint gdk_error_warnings;
extern gint gdk_null_window_warnings;
extern GList *gdk_default_filters;
+extern gboolean gdk_using_threads;
+
+/* Threading stuff */
+#ifdef USE_PTHREADS
+extern gint gdk_threads_pipe[2];
+extern gboolean gdk_select_waiting;
+#endif
/* Debugging support */
diff --git a/gdk/x11/gdkglobals-x11.c b/gdk/x11/gdkglobals-x11.c
index 6e34bfa883..82b67a823f 100644
--- a/gdk/x11/gdkglobals-x11.c
+++ b/gdk/x11/gdkglobals-x11.c
@@ -20,6 +20,7 @@
#include <X11/Xlib.h>
#include "gdktypes.h"
#include "gdkprivate.h"
+#include "../config.h"
guint gdk_debug_flags = 0;
gint gdk_use_xshm = TRUE;
@@ -53,3 +54,13 @@ gint gdk_error_code;
gint gdk_error_warnings = TRUE;
gint gdk_null_window_warnings = TRUE;
GList *gdk_default_filters = NULL;
+
+gboolean gdk_using_threads = FALSE;
+
+/* Used to signal the mainloop thread from its select() */
+#ifdef USE_PTHREADS
+gint gdk_threads_pipe[2];
+gboolean gdk_select_waiting = FALSE;
+#endif
+
+
diff --git a/gdk/x11/gdkmain-x11.c b/gdk/x11/gdkmain-x11.c
index 54fc747148..eeefa4f1be 100644
--- a/gdk/x11/gdkmain-x11.c
+++ b/gdk/x11/gdkmain-x11.c
@@ -1606,8 +1606,31 @@ gdk_event_wait (void)
max_input = MAX (max_input, input->source);
}
+#ifdef USE_PTHREADS
+ if (gdk_using_threads)
+ {
+ gdk_select_waiting = TRUE;
+
+ FD_SET (gdk_threads_pipe[0], &readfds);
+ max_input = MAX (max_input, gdk_threads_pipe[0]);
+ gdk_threads_leave ();
+ }
+#endif
+
nfd = select (max_input+1, &readfds, &writefds, &exceptfds, timerp);
+#ifdef USE_PTHREADS
+ if (gdk_using_threads)
+ {
+ gchar c;
+ gdk_threads_enter ();
+ gdk_select_waiting = FALSE;
+
+ if (FD_ISSET (gdk_threads_pipe[0], &readfds))
+ read (gdk_threads_pipe[0], &c, 1);
+ }
+#endif
+
timerp = NULL;
timer_val = 0;
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 39703dc66e..71cb2f79bd 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -225,7 +225,7 @@ EXTRA_DIST = \
INCLUDES = -I$(top_srcdir) -I../glib -I$(top_srcdir)/glib @x_cflags@
-noinst_PROGRAMS = testgtk testinput testselection simple
+noinst_PROGRAMS = testgtk testinput testselection testthreads simple
# FIXME, we currently rely on linking against libglib-1.1
@@ -243,11 +243,13 @@ LDADDS = \
testgtk_DEPENDENCIES = $(DEPS)
testinput_DEPENDENCIES = $(DEPS)
+testthreads_DEPENDENCIES = $(DEPS)
testselection_DEPENDENCIES = $(DEPS)
simple_DEPENDENCIES = $(DEPS)
testgtk_LDADD = $(LDADDS)
testinput_LDADD = $(LDADDS)
+testthreads_LDADD = $(LDADDS)
testselection_LDADD = $(LDADDS)
simple_LDADD = $(LDADDS)
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index d2462787d9..d2b651a278 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -1052,7 +1052,14 @@ gtk_idle_add_full (gint priority,
idlef->data = data;
idlef->destroy = destroy;
+ /* If we are adding the first idle function, possibly wake up
+ * the main thread out of its select().
+ */
+ if (!idle_functions)
+ gdk_threads_wake ();
+
idle_functions = g_list_insert_sorted (idle_functions, idlef, gtk_idle_compare);
+
return idlef->tag;
}
diff --git a/gtk/testgtk.c b/gtk/testgtk.c
index 7478f335b8..b2a4ca8a71 100644
--- a/gtk/testgtk.c
+++ b/gtk/testgtk.c
@@ -2815,7 +2815,7 @@ static void
list_clear (GtkWidget *widget,
GtkWidget *list)
{
- gtk_list_clear_items (GTK_LIST (list), 3 - 1, 5 - 1);
+ gtk_list_clear_items (GTK_LIST (list), 3 - 1, 6 - 1);
}
static void
diff --git a/tests/testgtk.c b/tests/testgtk.c
index 7478f335b8..b2a4ca8a71 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -2815,7 +2815,7 @@ static void
list_clear (GtkWidget *widget,
GtkWidget *list)
{
- gtk_list_clear_items (GTK_LIST (list), 3 - 1, 5 - 1);
+ gtk_list_clear_items (GTK_LIST (list), 3 - 1, 6 - 1);
}
static void