Renamed GLIB_SIZEOF_PTHREAD_T to GLIB_SIZEOF_SYSTEM_THREAD to reflect
authorSebastian Wilhelmi <wilhelmi@ira.uka.de>
Tue, 16 Nov 1999 10:30:25 +0000 (10:30 +0000)
committerSebastian Wilhelmi <wilhelmi@src.gnome.org>
Tue, 16 Nov 1999 10:30:25 +0000 (10:30 +0000)
1999-11-16  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>

        * acconfig.h, config.h.win32.in, configure.in: Renamed
        GLIB_SIZEOF_PTHREAD_T to GLIB_SIZEOF_SYSTEM_THREAD to reflect
        changed meaning.

        * configure.in: Cope with systems, that have a pthread_t type,
        that is not a pointer. Hint from Karl Nelson
        <kenelson@ece.ucdavis.edu>. Define GLIB_SIZEOF_SYSTEM_THREAD to 4
        for Solaris. Cope with systems, that have no default mutex
        initialize, like obviously most DCE systems.

        * glib.h, gthread.c: Changed the prototype of thread_create and
        thread_self to return the system thread into provided memory
        instead of a return value. This is necessary, as HPUX has a
        pthread_t, that is bigger than the biggest integral type there.

        * gthread.c: system_thread is no longer a pointer, but an memory
        area of size GLIB_SIZEOF_SYSTEM_THREAD. Changed the
        zeroinitialization and the tests for zeroness accordingly.

15 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
acconfig.h
config.h.win32.in
configure.in
glib.h
glib/glib.h
glib/gthread.c
gthread.c

index 1305e4d7a7812778845143c2d2281470d852cda5..dbe1b94ee598027c118efc000a0dfdff4c80df7f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+1999-11-16  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * acconfig.h, config.h.win32.in, configure.in: Renamed
+       GLIB_SIZEOF_PTHREAD_T to GLIB_SIZEOF_SYSTEM_THREAD to reflect
+       changed meaning.
+
+       * configure.in: Cope with systems, that have a pthread_t type,
+       that is not a pointer. Hint from Karl Nelson
+       <kenelson@ece.ucdavis.edu>. Define GLIB_SIZEOF_SYSTEM_THREAD to 4
+       for Solaris. Cope with systems, that have no default mutex
+       initialize, like obviously most DCE systems.
+
+       * glib.h, gthread.c: Changed the prototype of thread_create and
+       thread_self to return the system thread into provided memory
+       instead of a return value. This is necessary, as HPUX has a
+       pthread_t, that is bigger than the biggest integral type there.
+
+       * gthread.c: system_thread is no longer a pointer, but an memory
+       area of size GLIB_SIZEOF_SYSTEM_THREAD. Changed the
+       zeroinitialization and the tests for zeroness accordingly.
+
 1999-11-09  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * configure.in: Create docs/glib-config.1 from
index 1305e4d7a7812778845143c2d2281470d852cda5..dbe1b94ee598027c118efc000a0dfdff4c80df7f 100644 (file)
@@ -1,3 +1,24 @@
+1999-11-16  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * acconfig.h, config.h.win32.in, configure.in: Renamed
+       GLIB_SIZEOF_PTHREAD_T to GLIB_SIZEOF_SYSTEM_THREAD to reflect
+       changed meaning.
+
+       * configure.in: Cope with systems, that have a pthread_t type,
+       that is not a pointer. Hint from Karl Nelson
+       <kenelson@ece.ucdavis.edu>. Define GLIB_SIZEOF_SYSTEM_THREAD to 4
+       for Solaris. Cope with systems, that have no default mutex
+       initialize, like obviously most DCE systems.
+
+       * glib.h, gthread.c: Changed the prototype of thread_create and
+       thread_self to return the system thread into provided memory
+       instead of a return value. This is necessary, as HPUX has a
+       pthread_t, that is bigger than the biggest integral type there.
+
+       * gthread.c: system_thread is no longer a pointer, but an memory
+       area of size GLIB_SIZEOF_SYSTEM_THREAD. Changed the
+       zeroinitialization and the tests for zeroness accordingly.
+
 1999-11-09  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * configure.in: Create docs/glib-config.1 from
index 1305e4d7a7812778845143c2d2281470d852cda5..dbe1b94ee598027c118efc000a0dfdff4c80df7f 100644 (file)
@@ -1,3 +1,24 @@
+1999-11-16  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * acconfig.h, config.h.win32.in, configure.in: Renamed
+       GLIB_SIZEOF_PTHREAD_T to GLIB_SIZEOF_SYSTEM_THREAD to reflect
+       changed meaning.
+
+       * configure.in: Cope with systems, that have a pthread_t type,
+       that is not a pointer. Hint from Karl Nelson
+       <kenelson@ece.ucdavis.edu>. Define GLIB_SIZEOF_SYSTEM_THREAD to 4
+       for Solaris. Cope with systems, that have no default mutex
+       initialize, like obviously most DCE systems.
+
+       * glib.h, gthread.c: Changed the prototype of thread_create and
+       thread_self to return the system thread into provided memory
+       instead of a return value. This is necessary, as HPUX has a
+       pthread_t, that is bigger than the biggest integral type there.
+
+       * gthread.c: system_thread is no longer a pointer, but an memory
+       area of size GLIB_SIZEOF_SYSTEM_THREAD. Changed the
+       zeroinitialization and the tests for zeroness accordingly.
+
 1999-11-09  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * configure.in: Create docs/glib-config.1 from
index 1305e4d7a7812778845143c2d2281470d852cda5..dbe1b94ee598027c118efc000a0dfdff4c80df7f 100644 (file)
@@ -1,3 +1,24 @@
+1999-11-16  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * acconfig.h, config.h.win32.in, configure.in: Renamed
+       GLIB_SIZEOF_PTHREAD_T to GLIB_SIZEOF_SYSTEM_THREAD to reflect
+       changed meaning.
+
+       * configure.in: Cope with systems, that have a pthread_t type,
+       that is not a pointer. Hint from Karl Nelson
+       <kenelson@ece.ucdavis.edu>. Define GLIB_SIZEOF_SYSTEM_THREAD to 4
+       for Solaris. Cope with systems, that have no default mutex
+       initialize, like obviously most DCE systems.
+
+       * glib.h, gthread.c: Changed the prototype of thread_create and
+       thread_self to return the system thread into provided memory
+       instead of a return value. This is necessary, as HPUX has a
+       pthread_t, that is bigger than the biggest integral type there.
+
+       * gthread.c: system_thread is no longer a pointer, but an memory
+       area of size GLIB_SIZEOF_SYSTEM_THREAD. Changed the
+       zeroinitialization and the tests for zeroness accordingly.
+
 1999-11-09  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * configure.in: Create docs/glib-config.1 from
index 1305e4d7a7812778845143c2d2281470d852cda5..dbe1b94ee598027c118efc000a0dfdff4c80df7f 100644 (file)
@@ -1,3 +1,24 @@
+1999-11-16  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * acconfig.h, config.h.win32.in, configure.in: Renamed
+       GLIB_SIZEOF_PTHREAD_T to GLIB_SIZEOF_SYSTEM_THREAD to reflect
+       changed meaning.
+
+       * configure.in: Cope with systems, that have a pthread_t type,
+       that is not a pointer. Hint from Karl Nelson
+       <kenelson@ece.ucdavis.edu>. Define GLIB_SIZEOF_SYSTEM_THREAD to 4
+       for Solaris. Cope with systems, that have no default mutex
+       initialize, like obviously most DCE systems.
+
+       * glib.h, gthread.c: Changed the prototype of thread_create and
+       thread_self to return the system thread into provided memory
+       instead of a return value. This is necessary, as HPUX has a
+       pthread_t, that is bigger than the biggest integral type there.
+
+       * gthread.c: system_thread is no longer a pointer, but an memory
+       area of size GLIB_SIZEOF_SYSTEM_THREAD. Changed the
+       zeroinitialization and the tests for zeroness accordingly.
+
 1999-11-09  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * configure.in: Create docs/glib-config.1 from
index 1305e4d7a7812778845143c2d2281470d852cda5..dbe1b94ee598027c118efc000a0dfdff4c80df7f 100644 (file)
@@ -1,3 +1,24 @@
+1999-11-16  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * acconfig.h, config.h.win32.in, configure.in: Renamed
+       GLIB_SIZEOF_PTHREAD_T to GLIB_SIZEOF_SYSTEM_THREAD to reflect
+       changed meaning.
+
+       * configure.in: Cope with systems, that have a pthread_t type,
+       that is not a pointer. Hint from Karl Nelson
+       <kenelson@ece.ucdavis.edu>. Define GLIB_SIZEOF_SYSTEM_THREAD to 4
+       for Solaris. Cope with systems, that have no default mutex
+       initialize, like obviously most DCE systems.
+
+       * glib.h, gthread.c: Changed the prototype of thread_create and
+       thread_self to return the system thread into provided memory
+       instead of a return value. This is necessary, as HPUX has a
+       pthread_t, that is bigger than the biggest integral type there.
+
+       * gthread.c: system_thread is no longer a pointer, but an memory
+       area of size GLIB_SIZEOF_SYSTEM_THREAD. Changed the
+       zeroinitialization and the tests for zeroness accordingly.
+
 1999-11-09  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * configure.in: Create docs/glib-config.1 from
index 1305e4d7a7812778845143c2d2281470d852cda5..dbe1b94ee598027c118efc000a0dfdff4c80df7f 100644 (file)
@@ -1,3 +1,24 @@
+1999-11-16  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * acconfig.h, config.h.win32.in, configure.in: Renamed
+       GLIB_SIZEOF_PTHREAD_T to GLIB_SIZEOF_SYSTEM_THREAD to reflect
+       changed meaning.
+
+       * configure.in: Cope with systems, that have a pthread_t type,
+       that is not a pointer. Hint from Karl Nelson
+       <kenelson@ece.ucdavis.edu>. Define GLIB_SIZEOF_SYSTEM_THREAD to 4
+       for Solaris. Cope with systems, that have no default mutex
+       initialize, like obviously most DCE systems.
+
+       * glib.h, gthread.c: Changed the prototype of thread_create and
+       thread_self to return the system thread into provided memory
+       instead of a return value. This is necessary, as HPUX has a
+       pthread_t, that is bigger than the biggest integral type there.
+
+       * gthread.c: system_thread is no longer a pointer, but an memory
+       area of size GLIB_SIZEOF_SYSTEM_THREAD. Changed the
+       zeroinitialization and the tests for zeroness accordingly.
+
 1999-11-09  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * configure.in: Create docs/glib-config.1 from
index 1305e4d7a7812778845143c2d2281470d852cda5..dbe1b94ee598027c118efc000a0dfdff4c80df7f 100644 (file)
@@ -1,3 +1,24 @@
+1999-11-16  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * acconfig.h, config.h.win32.in, configure.in: Renamed
+       GLIB_SIZEOF_PTHREAD_T to GLIB_SIZEOF_SYSTEM_THREAD to reflect
+       changed meaning.
+
+       * configure.in: Cope with systems, that have a pthread_t type,
+       that is not a pointer. Hint from Karl Nelson
+       <kenelson@ece.ucdavis.edu>. Define GLIB_SIZEOF_SYSTEM_THREAD to 4
+       for Solaris. Cope with systems, that have no default mutex
+       initialize, like obviously most DCE systems.
+
+       * glib.h, gthread.c: Changed the prototype of thread_create and
+       thread_self to return the system thread into provided memory
+       instead of a return value. This is necessary, as HPUX has a
+       pthread_t, that is bigger than the biggest integral type there.
+
+       * gthread.c: system_thread is no longer a pointer, but an memory
+       area of size GLIB_SIZEOF_SYSTEM_THREAD. Changed the
+       zeroinitialization and the tests for zeroness accordingly.
+
 1999-11-09  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * configure.in: Create docs/glib-config.1 from
index c7167830d44129a09a9cc5d7a1d027145b70db86..d73fc50a08830f94ef9de30427d6082dcb2e57f2 100644 (file)
@@ -45,9 +45,9 @@
 
 #undef GLIB_SIZEOF_GMUTEX
 #undef GLIB_SIZEOF_INTMAX_T
-#undef GLIB_SIZEOF_PTHREAD_T
 #undef GLIB_SIZEOF_PTRDIFF_T
 #undef GLIB_SIZEOF_SIZE_T
+#undef GLIB_SIZEOF_SYSTEM_THREAD
 
 #undef GLIB_BYTE_CONTENTS_GMUTEX
 #undef GLIB_BYTE_CONTENTS_GRECMUTEX
index c4c1d6db4a0cdbd418a61dc03ff1088c3e813db1..f7422fbde87519c4febb28369305124a02d18e4e 100644 (file)
@@ -60,7 +60,7 @@
 #define GLIB_INTERFACE_AGE @GLIB_INTERFACE_AGE@
 #define GLIB_BINARY_AGE @GLIB_BINARY_AGE@
 
-#define GLIB_SIZEOF_PTHREAD_T 4
+#define GLIB_SIZEOF_SYSTEM_THREAD 4
 #define GLIB_SIZEOF_SIZE_T 4
 #define GLIB_SIZEOF_PTRDIFF_T 4
 #define GLIB_SIZEOF_INTMAX_T 4
index a4ff76052c0c645678d1027f37b1b661db3eab91..0a43716c2c0bbbe238599a3240593003812759a7 100644 (file)
@@ -736,7 +736,7 @@ case $have_threads in
                        
                        AC_MSG_CHECKING(for pthread_join$IN)
                        AC_TRY_LINK([#include <pthread.h>],
-                               [pthread_join(NULL,NULL)],
+                               [pthread_t t; pthread_join(t,NULL)],
                                [AC_MSG_RESULT(yes)
                                G_THREAD_LIBS="$add_thread_lib"
                                break],
@@ -876,12 +876,12 @@ if test x"$enable_threads" = xyes; then
        if test x"$have_threads" = xposix; then
                GLIB_SIZEOF([#include <pthread.h>],
                        pthread_t,
-                       pthread_t)
+                       system_thread)
                # This is not AC_CHECK_FUNC to also work with function
                # name mangling in header files.
                AC_MSG_CHECKING(for pthread_attr_setstacksize)
                AC_TRY_LINK([#include <pthread.h>],
-                       [pthread_attr_setstacksize(NULL,0)],
+                       [pthread_attr_t t; pthread_attr_setstacksize(&t,0)],
                        [AC_MSG_RESULT(yes)
                        AC_DEFINE(HAVE_PTHREAD_ATTR_SETSTACKSIZE)],
                        [AC_MSG_RESULT(no)])
@@ -942,7 +942,12 @@ if test x"$enable_threads" = xyes; then
                        posix_yield_func="$posix_yield_func()"
                fi
                AC_DEFINE_UNQUOTED(POSIX_YIELD_FUNC,$posix_yield_func)
+       else
+               # for now, the only other implementation is solaris 
+               # -> there 4 bytes are enough
+               AC_DEFINE_UNQUOTED(GLIB_SIZEOF_SYSTEM_THREAD, 4)
        fi
+
        LIBS="$glib_save_LIBS"
        CFLAGS="$glib_save_CFLAGS"
 
@@ -978,6 +983,9 @@ GLIB_IF_VAR_EQ(mutex_has_default, yes,
                           gmutex,
                           $glib_cv_sizeof_gmutex,
                           $mutex_default_init)
+       if test x"$glib_cv_byte_contents_gmutex" = xno; then
+               mutex_has_default=no
+       fi
        if test x"$have_threads" = xposix; then 
                GLIB_BYTE_CONTENTS([#define __USE_GNU
 #include <$mutex_header_file>],
@@ -1182,7 +1190,7 @@ _______EOF
                # typedef GStaticMutex GStaticRecMutex to avoid silent
                # compilation, when a GStaticRecMutex is used where a
                # GStaticMutex should have been used and vice versa,
-               # because that micht fail on other platforms.
+               # because that might fail on other platforms.
                cat >>$outfile <<_______EOF
 typedef struct _GStaticRecMutex GStaticRecMutex;
 struct _GStaticRecMutex
diff --git a/glib.h b/glib.h
index 909880d53640b508912a0bac4a6cf8bdd9640724..616974c2e0deb39feb46aafc774fce655fbdfa29 100644 (file)
--- a/glib.h
+++ b/glib.h
@@ -2934,18 +2934,19 @@ struct _GThreadFunctions
   gpointer  (*private_get)        (GPrivate            *private_key);
   void      (*private_set)        (GPrivate            *private_key,
                                   gpointer              data);
-  gpointer  (*thread_create)      (GThreadFunc                  thread_func,
+  void      (*thread_create)      (GThreadFunc                  thread_func,
                                   gpointer              arg,
                                   gulong                stack_size,
                                   gboolean              joinable,
                                   gboolean              bound,
-                                  GThreadPriority       priority);
+                                  GThreadPriority       priority,
+                                  gpointer              thread);
   void      (*thread_yield)       (void);
   void      (*thread_join)        (gpointer             thread);
   void      (*thread_exit)        (void);
   void      (*thread_set_priority)(gpointer             thread, 
                                   GThreadPriority       priority);
-  gpointer  (*thread_self)        (void);
+  void      (*thread_self)        (gpointer              thread);
 };
 
 GUTILS_C_VAR GThreadFunctions  g_thread_functions_for_glib_use;
index 909880d53640b508912a0bac4a6cf8bdd9640724..616974c2e0deb39feb46aafc774fce655fbdfa29 100644 (file)
@@ -2934,18 +2934,19 @@ struct _GThreadFunctions
   gpointer  (*private_get)        (GPrivate            *private_key);
   void      (*private_set)        (GPrivate            *private_key,
                                   gpointer              data);
-  gpointer  (*thread_create)      (GThreadFunc                  thread_func,
+  void      (*thread_create)      (GThreadFunc                  thread_func,
                                   gpointer              arg,
                                   gulong                stack_size,
                                   gboolean              joinable,
                                   gboolean              bound,
-                                  GThreadPriority       priority);
+                                  GThreadPriority       priority,
+                                  gpointer              thread);
   void      (*thread_yield)       (void);
   void      (*thread_join)        (gpointer             thread);
   void      (*thread_exit)        (void);
   void      (*thread_set_priority)(gpointer             thread, 
                                   GThreadPriority       priority);
-  gpointer  (*thread_self)        (void);
+  void      (*thread_self)        (gpointer              thread);
 };
 
 GUTILS_C_VAR GThreadFunctions  g_thread_functions_for_glib_use;
index d0d8c7ab35991b48fe167d3ea9a913db7c26e0c2..bf539f1e566f457329a1ac8c0cdb4eea72ca4d87 100644 (file)
 #include <unistd.h>
 #endif
 
+typedef union _SystemThread SystemThread;
+
+/* This represents a system thread as used by the implementation. An
+ * alien implementaion, as loaded by g_thread_init can only count on
+ * "sizeof (gpointer)" bytes to store their info. We however need more
+ * for some of our native implementations. */
+union _SystemThread
+{
+  guchar   data[GLIB_SIZEOF_SYSTEM_THREAD];
+  gdouble  double_dummy; /* These are used for the right alignment */
+  gpointer pointer_dummy;
+#ifdef G_HAVE_GINT64
+  guint64  long_dummy;
+#else
+  guint32  long_dummy;  
+#endif
+};
+
 typedef struct _GRealThread GRealThread;
 
 struct  _GRealThread
@@ -46,10 +64,35 @@ struct  _GRealThread
   GThread thread;
   GThreadFunc func;
   gpointer arg;
-  gpointer system_thread;
   gpointer private_data;
+  SystemThread system_thread;
 };
 
+#if (GLIB_SIZEOF_SYSTEM_THREAD <= 8 && defined(G_HAVE_GINT64))               \
+  || (GLIB_SIZEOF_SYSTEM_THREAD <= 4)
+/* We can use fast setting and checks */
+#  define set_system_thread_to_zero(t) (t->system_thread.long_dummy=0)
+#  define system_thread_is_not_zero(t) (t->system_thread.long_dummy)
+#else
+/* We have to do it the hard way and hope the compiler will optimize a bit */
+static inline void
+set_system_thread_to_zero(GRealThread* thread)
+{ 
+  int i; 
+  for (i = 0; i < GLIB_SIZEOF_SYSTEM_THREAD; i++)
+    thread->system_thread.data[i] = 0;
+}
+
+static inline gboolean
+system_thread_is_not_zero(GRealThread* thread)
+{
+  int i; 
+  for (i = 0; i < GLIB_SIZEOF_SYSTEM_THREAD; i++)
+    if (thread->system_thread.data[i]) return FALSE;
+  return TRUE;
+}
+#endif
+
 typedef struct _GStaticPrivateNode GStaticPrivateNode;
 
 struct _GStaticPrivateNode
@@ -84,9 +127,9 @@ GThreadFunctions g_thread_functions_for_glib_use = {
   (GPrivate*(*)(GDestroyNotify))g_thread_fail, /* private_new */
   NULL,                                        /* private_get */
   NULL,                                        /* private_set */
-  (gpointer(*)(GThreadFunc, gpointer, gulong, 
-              gboolean, gboolean
-              GThreadPriority))g_thread_fail, /* thread_create */
+  (void(*)(GThreadFunc, gpointer, gulong, 
+          gboolean, gboolean, GThreadPriority
+          gpointer))g_thread_fail,            /* thread_create */
   NULL,                                        /* thread_yield */
   NULL,                                        /* thread_join */
   NULL,                                        /* thread_exit */
@@ -298,7 +341,7 @@ g_thread_cleanup (gpointer data)
       if (!thread->thread.joinable)
        {
          /* Just to make sure, this isn't used any more */
-         thread->system_thread = NULL;
+         set_system_thread_to_zero(thread);
          g_free (thread);
        }
     }
@@ -347,10 +390,9 @@ g_thread_create (GThreadFunc                thread_func,
   result->func = thread_func;
   result->arg = arg;
   G_LOCK (g_thread_create);
-  result->system_thread = G_THREAD_UF (thread_create, (g_thread_create_proxy, 
-                                                      result, stack_size, 
-                                                      joinable, bound, 
-                                                      priority));
+  G_THREAD_UF (thread_create, (g_thread_create_proxy, result, stack_size, 
+                              joinable, bound, priority,
+                              &result->system_thread));
   G_UNLOCK (g_thread_create);
   return (GThread*) result;
 }
@@ -359,16 +401,17 @@ void
 g_thread_join (GThread* thread)
 {
   GRealThread* real = (GRealThread*) thread;
+  
 
   g_return_if_fail (thread);
   g_return_if_fail (thread->joinable);
-  g_return_if_fail (real->system_thread);
+  g_return_if_fail (system_thread_is_not_zero (real));
 
-  G_THREAD_UF (thread_join, (real->system_thread));
+  G_THREAD_UF (thread_join, (&real->system_thread));
 
   /* Just to make sure, this isn't used any more */
   thread->joinable = 0;
-  real->system_thread = NULL;
+  set_system_thread_to_zero (real);
 
   /* the thread structure for non-joinable threads is freed upon
      thread end. We free the memory here. This will leave loose end,
@@ -384,10 +427,10 @@ g_thread_set_priority (GThread* thread,
   GRealThread* real = (GRealThread*) thread;
 
   g_return_if_fail (thread);
-  g_return_if_fail (real->system_thread);
+  g_return_if_fail (system_thread_is_not_zero (real));
 
   thread->priority = priority;
-  G_THREAD_CF (thread_set_priority, (void)0, (real->system_thread, priority));
+  G_THREAD_CF (thread_set_priority, (void)0, (&real->system_thread, priority));
 }
 
 GThread*
@@ -407,14 +450,14 @@ g_thread_self()
                                                             just a guess */
       thread->func = NULL;
       thread->arg = NULL;
-      thread->system_thread = NULL;
+      set_system_thread_to_zero (thread);
       thread->private_data = NULL;
       g_private_set (g_thread_specific_private, thread);
     }
      
-  if (g_thread_supported () && !thread->system_thread)
+  if (g_thread_supported () && !system_thread_is_not_zero(thread))
     {
-      thread->system_thread = g_thread_functions_for_glib_use.thread_self();
+      g_thread_functions_for_glib_use.thread_self(&thread->system_thread);
     }
 
   return (GThread*)thread;
index d0d8c7ab35991b48fe167d3ea9a913db7c26e0c2..bf539f1e566f457329a1ac8c0cdb4eea72ca4d87 100644 (file)
--- a/gthread.c
+++ b/gthread.c
 #include <unistd.h>
 #endif
 
+typedef union _SystemThread SystemThread;
+
+/* This represents a system thread as used by the implementation. An
+ * alien implementaion, as loaded by g_thread_init can only count on
+ * "sizeof (gpointer)" bytes to store their info. We however need more
+ * for some of our native implementations. */
+union _SystemThread
+{
+  guchar   data[GLIB_SIZEOF_SYSTEM_THREAD];
+  gdouble  double_dummy; /* These are used for the right alignment */
+  gpointer pointer_dummy;
+#ifdef G_HAVE_GINT64
+  guint64  long_dummy;
+#else
+  guint32  long_dummy;  
+#endif
+};
+
 typedef struct _GRealThread GRealThread;
 
 struct  _GRealThread
@@ -46,10 +64,35 @@ struct  _GRealThread
   GThread thread;
   GThreadFunc func;
   gpointer arg;
-  gpointer system_thread;
   gpointer private_data;
+  SystemThread system_thread;
 };
 
+#if (GLIB_SIZEOF_SYSTEM_THREAD <= 8 && defined(G_HAVE_GINT64))               \
+  || (GLIB_SIZEOF_SYSTEM_THREAD <= 4)
+/* We can use fast setting and checks */
+#  define set_system_thread_to_zero(t) (t->system_thread.long_dummy=0)
+#  define system_thread_is_not_zero(t) (t->system_thread.long_dummy)
+#else
+/* We have to do it the hard way and hope the compiler will optimize a bit */
+static inline void
+set_system_thread_to_zero(GRealThread* thread)
+{ 
+  int i; 
+  for (i = 0; i < GLIB_SIZEOF_SYSTEM_THREAD; i++)
+    thread->system_thread.data[i] = 0;
+}
+
+static inline gboolean
+system_thread_is_not_zero(GRealThread* thread)
+{
+  int i; 
+  for (i = 0; i < GLIB_SIZEOF_SYSTEM_THREAD; i++)
+    if (thread->system_thread.data[i]) return FALSE;
+  return TRUE;
+}
+#endif
+
 typedef struct _GStaticPrivateNode GStaticPrivateNode;
 
 struct _GStaticPrivateNode
@@ -84,9 +127,9 @@ GThreadFunctions g_thread_functions_for_glib_use = {
   (GPrivate*(*)(GDestroyNotify))g_thread_fail, /* private_new */
   NULL,                                        /* private_get */
   NULL,                                        /* private_set */
-  (gpointer(*)(GThreadFunc, gpointer, gulong, 
-              gboolean, gboolean
-              GThreadPriority))g_thread_fail, /* thread_create */
+  (void(*)(GThreadFunc, gpointer, gulong, 
+          gboolean, gboolean, GThreadPriority
+          gpointer))g_thread_fail,            /* thread_create */
   NULL,                                        /* thread_yield */
   NULL,                                        /* thread_join */
   NULL,                                        /* thread_exit */
@@ -298,7 +341,7 @@ g_thread_cleanup (gpointer data)
       if (!thread->thread.joinable)
        {
          /* Just to make sure, this isn't used any more */
-         thread->system_thread = NULL;
+         set_system_thread_to_zero(thread);
          g_free (thread);
        }
     }
@@ -347,10 +390,9 @@ g_thread_create (GThreadFunc                thread_func,
   result->func = thread_func;
   result->arg = arg;
   G_LOCK (g_thread_create);
-  result->system_thread = G_THREAD_UF (thread_create, (g_thread_create_proxy, 
-                                                      result, stack_size, 
-                                                      joinable, bound, 
-                                                      priority));
+  G_THREAD_UF (thread_create, (g_thread_create_proxy, result, stack_size, 
+                              joinable, bound, priority,
+                              &result->system_thread));
   G_UNLOCK (g_thread_create);
   return (GThread*) result;
 }
@@ -359,16 +401,17 @@ void
 g_thread_join (GThread* thread)
 {
   GRealThread* real = (GRealThread*) thread;
+  
 
   g_return_if_fail (thread);
   g_return_if_fail (thread->joinable);
-  g_return_if_fail (real->system_thread);
+  g_return_if_fail (system_thread_is_not_zero (real));
 
-  G_THREAD_UF (thread_join, (real->system_thread));
+  G_THREAD_UF (thread_join, (&real->system_thread));
 
   /* Just to make sure, this isn't used any more */
   thread->joinable = 0;
-  real->system_thread = NULL;
+  set_system_thread_to_zero (real);
 
   /* the thread structure for non-joinable threads is freed upon
      thread end. We free the memory here. This will leave loose end,
@@ -384,10 +427,10 @@ g_thread_set_priority (GThread* thread,
   GRealThread* real = (GRealThread*) thread;
 
   g_return_if_fail (thread);
-  g_return_if_fail (real->system_thread);
+  g_return_if_fail (system_thread_is_not_zero (real));
 
   thread->priority = priority;
-  G_THREAD_CF (thread_set_priority, (void)0, (real->system_thread, priority));
+  G_THREAD_CF (thread_set_priority, (void)0, (&real->system_thread, priority));
 }
 
 GThread*
@@ -407,14 +450,14 @@ g_thread_self()
                                                             just a guess */
       thread->func = NULL;
       thread->arg = NULL;
-      thread->system_thread = NULL;
+      set_system_thread_to_zero (thread);
       thread->private_data = NULL;
       g_private_set (g_thread_specific_private, thread);
     }
      
-  if (g_thread_supported () && !thread->system_thread)
+  if (g_thread_supported () && !system_thread_is_not_zero(thread))
     {
-      thread->system_thread = g_thread_functions_for_glib_use.thread_self();
+      g_thread_functions_for_glib_use.thread_self(&thread->system_thread);
     }
 
   return (GThread*)thread;