]> Pileus Git - ~andy/gtk/commitdiff
Basic thread-awareness:
authorOwen Taylor <otaylor@gtk.org>
Sat, 16 May 1998 02:13:12 +0000 (02:13 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Sat, 16 May 1998 02:13:12 +0000 (02:13 +0000)
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))

21 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
acconfig.h
config.h.in
configure.in
gdk/Makefile.am
gdk/gdk.c
gdk/gdk.h
gdk/gdkglobals.c
gdk/gdkprivate.h
gdk/x11/gdkglobals-x11.c
gdk/x11/gdkmain-x11.c
gtk/Makefile.am
gtk/gtkmain.c
gtk/testgtk.c
tests/testgtk.c

index 1c4794eb3a688009624daff2c95e650f8400fe39..5bc1fa0030f786870973d42656a1c9d20e80f62e 100644 (file)
--- 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
index 1c4794eb3a688009624daff2c95e650f8400fe39..5bc1fa0030f786870973d42656a1c9d20e80f62e 100644 (file)
@@ -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
index 1c4794eb3a688009624daff2c95e650f8400fe39..5bc1fa0030f786870973d42656a1c9d20e80f62e 100644 (file)
@@ -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
index 1c4794eb3a688009624daff2c95e650f8400fe39..5bc1fa0030f786870973d42656a1c9d20e80f62e 100644 (file)
@@ -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
index 1c4794eb3a688009624daff2c95e650f8400fe39..5bc1fa0030f786870973d42656a1c9d20e80f62e 100644 (file)
@@ -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
index 1c4794eb3a688009624daff2c95e650f8400fe39..5bc1fa0030f786870973d42656a1c9d20e80f62e 100644 (file)
@@ -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
index 1c4794eb3a688009624daff2c95e650f8400fe39..5bc1fa0030f786870973d42656a1c9d20e80f62e 100644 (file)
@@ -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
index 600655efb2843d3f953275976c4d3bcc04354f34..82b3d6c73c49aac8bda0c78f06290a48d3a1a704 100644 (file)
@@ -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
index c606837d57c1297771b2aca93097ff978b34c338..b105985b058a723adfa64cf6a4bca97daa300ac8 100644 (file)
@@ -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
index 8a0baf923f73ea227255ddcaf8be6b09bed00af3..74f23e4f61020a1334154ad0994be8a7a5a3ce2b 100644 (file)
@@ -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)
index 3037fd6de7046e036df25f046ff1531ece69be52..634e6a916008cd2a74727852068a4427f1695703 100644 (file)
@@ -26,6 +26,7 @@ libgdk_1_1_la_SOURCES = \
        gdkrectangle.c  \
        gdkregion.c     \
        gdkselection.c  \
+       gdkthreads.c    \
        gdkvisual.c     \
        gdkwindow.c     \
        gdkxid.c        \
index 54fc747148e960e55a33eb32691ef7567e0c312d..eeefa4f1beadb9990c525bf7ff8dc8db1de288b5 100644 (file)
--- 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;
 
index 9be074e392a27057259e8d7228543d27214a5394..092226d8b3b47829e50b0ab39e903719915be1d3 100644 (file)
--- 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
 }
index 6e34bfa8832595c5fccf38ebb9394918ba090a49..82b67a823f433c38d37de2895d5cb5ffccdd901d 100644 (file)
@@ -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
+
+
index 555c8c382043f6163c6446efaa14097792439bac..fcfca025bf3cbf84fced8e6c85db76fcccabf744 100644 (file)
@@ -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 */
 
index 6e34bfa8832595c5fccf38ebb9394918ba090a49..82b67a823f433c38d37de2895d5cb5ffccdd901d 100644 (file)
@@ -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
+
+
index 54fc747148e960e55a33eb32691ef7567e0c312d..eeefa4f1beadb9990c525bf7ff8dc8db1de288b5 100644 (file)
@@ -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;
 
index 39703dc66ef0aeed1ff223936584329e5c3cfa93..71cb2f79bd7e554a77fb250a6a380e2984ddf4bc 100644 (file)
@@ -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)
 
index d2462787d9104132f542c670a233d9e18080629f..d2b651a278512d01528a347216471a5e2eb3c69e 100644 (file)
@@ -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;
 }
index 7478f335b8771cadef2bcf77688fc741bb015f75..b2a4ca8a71f8f4e6ae4afe4225e2195afbe537f6 100644 (file)
@@ -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
index 7478f335b8771cadef2bcf77688fc741bb015f75..b2a4ca8a71f8f4e6ae4afe4225e2195afbe537f6 100644 (file)
@@ -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