After finding the right thread library (containing e.g. pthread_create) we
authorSebastian Wilhelmi <wilhelmi@ira.uka.de>
Thu, 23 Mar 2000 16:23:50 +0000 (16:23 +0000)
committerSebastian Wilhelmi <wilhelmi@src.gnome.org>
Thu, 23 Mar 2000 16:23:50 +0000 (16:23 +0000)
2000-03-23  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>

* configure.in: After finding the right thread library (containing
e.g. pthread_create) we now search for the right realtime library
(containing e.g. sched_get_priority_max). Makes the output of the
thread related libraries correct.

* gtimer.c (g_usleep): The current implementation of g_usleep
(simply calling select) doesn't work reliable for multi-threaded
programs on some platforms (bad omen for the main loop....), so I
changed the implementation for thread-using programs to wait for a
GCond for the specified amount of time (NB: sleep and usleep are
not MT-safe in general, because they often use signals).

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
configure.in
glib/gtimer.c
gtimer.c

index c38b90e97e4c8437f64665c207c9a7bf5b500828..01eee2172eca0b6ec70242afe2581d283741dbc4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2000-03-23  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * configure.in: After finding the right thread library (containing
+       e.g. pthread_create) we now search for the right realtime library
+       (containing e.g. sched_get_priority_max). Makes the output of the
+       thread related libraries correct. 
+
+       * gtimer.c (g_usleep): The current implementation of g_usleep
+       (simply calling select) doesn't work reliable for multi-threaded
+       programs on some platforms (bad omen for the main loop....), so I
+       changed the implementation for thread-using programs to wait for a
+       GCond for the specified amount of time (NB: sleep and usleep are
+       not MT-safe in general, because they often use signals).
+
 Wed Mar 22 16:49:57 2000  Owen Taylor  <otaylor@redhat.com>
 
        * gmem.c (g_mem_chunk_area_compare): Fix indentation.
index c38b90e97e4c8437f64665c207c9a7bf5b500828..01eee2172eca0b6ec70242afe2581d283741dbc4 100644 (file)
@@ -1,3 +1,17 @@
+2000-03-23  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * configure.in: After finding the right thread library (containing
+       e.g. pthread_create) we now search for the right realtime library
+       (containing e.g. sched_get_priority_max). Makes the output of the
+       thread related libraries correct. 
+
+       * gtimer.c (g_usleep): The current implementation of g_usleep
+       (simply calling select) doesn't work reliable for multi-threaded
+       programs on some platforms (bad omen for the main loop....), so I
+       changed the implementation for thread-using programs to wait for a
+       GCond for the specified amount of time (NB: sleep and usleep are
+       not MT-safe in general, because they often use signals).
+
 Wed Mar 22 16:49:57 2000  Owen Taylor  <otaylor@redhat.com>
 
        * gmem.c (g_mem_chunk_area_compare): Fix indentation.
index c38b90e97e4c8437f64665c207c9a7bf5b500828..01eee2172eca0b6ec70242afe2581d283741dbc4 100644 (file)
@@ -1,3 +1,17 @@
+2000-03-23  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * configure.in: After finding the right thread library (containing
+       e.g. pthread_create) we now search for the right realtime library
+       (containing e.g. sched_get_priority_max). Makes the output of the
+       thread related libraries correct. 
+
+       * gtimer.c (g_usleep): The current implementation of g_usleep
+       (simply calling select) doesn't work reliable for multi-threaded
+       programs on some platforms (bad omen for the main loop....), so I
+       changed the implementation for thread-using programs to wait for a
+       GCond for the specified amount of time (NB: sleep and usleep are
+       not MT-safe in general, because they often use signals).
+
 Wed Mar 22 16:49:57 2000  Owen Taylor  <otaylor@redhat.com>
 
        * gmem.c (g_mem_chunk_area_compare): Fix indentation.
index c38b90e97e4c8437f64665c207c9a7bf5b500828..01eee2172eca0b6ec70242afe2581d283741dbc4 100644 (file)
@@ -1,3 +1,17 @@
+2000-03-23  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * configure.in: After finding the right thread library (containing
+       e.g. pthread_create) we now search for the right realtime library
+       (containing e.g. sched_get_priority_max). Makes the output of the
+       thread related libraries correct. 
+
+       * gtimer.c (g_usleep): The current implementation of g_usleep
+       (simply calling select) doesn't work reliable for multi-threaded
+       programs on some platforms (bad omen for the main loop....), so I
+       changed the implementation for thread-using programs to wait for a
+       GCond for the specified amount of time (NB: sleep and usleep are
+       not MT-safe in general, because they often use signals).
+
 Wed Mar 22 16:49:57 2000  Owen Taylor  <otaylor@redhat.com>
 
        * gmem.c (g_mem_chunk_area_compare): Fix indentation.
index c38b90e97e4c8437f64665c207c9a7bf5b500828..01eee2172eca0b6ec70242afe2581d283741dbc4 100644 (file)
@@ -1,3 +1,17 @@
+2000-03-23  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * configure.in: After finding the right thread library (containing
+       e.g. pthread_create) we now search for the right realtime library
+       (containing e.g. sched_get_priority_max). Makes the output of the
+       thread related libraries correct. 
+
+       * gtimer.c (g_usleep): The current implementation of g_usleep
+       (simply calling select) doesn't work reliable for multi-threaded
+       programs on some platforms (bad omen for the main loop....), so I
+       changed the implementation for thread-using programs to wait for a
+       GCond for the specified amount of time (NB: sleep and usleep are
+       not MT-safe in general, because they often use signals).
+
 Wed Mar 22 16:49:57 2000  Owen Taylor  <otaylor@redhat.com>
 
        * gmem.c (g_mem_chunk_area_compare): Fix indentation.
index c38b90e97e4c8437f64665c207c9a7bf5b500828..01eee2172eca0b6ec70242afe2581d283741dbc4 100644 (file)
@@ -1,3 +1,17 @@
+2000-03-23  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * configure.in: After finding the right thread library (containing
+       e.g. pthread_create) we now search for the right realtime library
+       (containing e.g. sched_get_priority_max). Makes the output of the
+       thread related libraries correct. 
+
+       * gtimer.c (g_usleep): The current implementation of g_usleep
+       (simply calling select) doesn't work reliable for multi-threaded
+       programs on some platforms (bad omen for the main loop....), so I
+       changed the implementation for thread-using programs to wait for a
+       GCond for the specified amount of time (NB: sleep and usleep are
+       not MT-safe in general, because they often use signals).
+
 Wed Mar 22 16:49:57 2000  Owen Taylor  <otaylor@redhat.com>
 
        * gmem.c (g_mem_chunk_area_compare): Fix indentation.
index c38b90e97e4c8437f64665c207c9a7bf5b500828..01eee2172eca0b6ec70242afe2581d283741dbc4 100644 (file)
@@ -1,3 +1,17 @@
+2000-03-23  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * configure.in: After finding the right thread library (containing
+       e.g. pthread_create) we now search for the right realtime library
+       (containing e.g. sched_get_priority_max). Makes the output of the
+       thread related libraries correct. 
+
+       * gtimer.c (g_usleep): The current implementation of g_usleep
+       (simply calling select) doesn't work reliable for multi-threaded
+       programs on some platforms (bad omen for the main loop....), so I
+       changed the implementation for thread-using programs to wait for a
+       GCond for the specified amount of time (NB: sleep and usleep are
+       not MT-safe in general, because they often use signals).
+
 Wed Mar 22 16:49:57 2000  Owen Taylor  <otaylor@redhat.com>
 
        * gmem.c (g_mem_chunk_area_compare): Fix indentation.
index c38b90e97e4c8437f64665c207c9a7bf5b500828..01eee2172eca0b6ec70242afe2581d283741dbc4 100644 (file)
@@ -1,3 +1,17 @@
+2000-03-23  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * configure.in: After finding the right thread library (containing
+       e.g. pthread_create) we now search for the right realtime library
+       (containing e.g. sched_get_priority_max). Makes the output of the
+       thread related libraries correct. 
+
+       * gtimer.c (g_usleep): The current implementation of g_usleep
+       (simply calling select) doesn't work reliable for multi-threaded
+       programs on some platforms (bad omen for the main loop....), so I
+       changed the implementation for thread-using programs to wait for a
+       GCond for the specified amount of time (NB: sleep and usleep are
+       not MT-safe in general, because they often use signals).
+
 Wed Mar 22 16:49:57 2000  Owen Taylor  <otaylor@redhat.com>
 
        * gmem.c (g_mem_chunk_area_compare): Fix indentation.
index 7531b4369a823471e5fc422032be9bf334130044..b1a074acc18e384caa5d58333c0dcc4c692a5014 100644 (file)
@@ -733,8 +733,6 @@ case $have_threads in
                G_THREAD_LIBS=error
                glib_save_LIBS="$LIBS"
                for thread_lib in "" pthread pthreads c_r thread dce; do
-                       # This is not AC_CHECK_LIB to also work with function
-                       # name mangling in header files.
                        if test x"$thread_lib" = x; then
                                add_thread_lib=""
                                IN=""
@@ -763,6 +761,31 @@ case $have_threads in
                                break],
                                [AC_MSG_RESULT(no)])
                done
+               for thread_lib in "" rt; do
+                       if test x"$thread_lib" = x; then
+                               add_thread_lib=""
+                               IN=""
+                       else
+                               add_thread_lib="-l$thread_lib"
+                               IN=" in -l$thread_lib"
+                       fi
+                       LIBS="$glib_save_LIBS $add_thread_lib"
+                       
+                       AC_MSG_CHECKING(for sched_get_priority_min$IN)
+                       AC_TRY_RUN([#include <sched.h>
+                               #include <errno.h>
+                               int main() {
+                               errno = 0;
+                                return sched_get_priority_min(SCHED_OTHER)==-1
+                                       && errno != 0;
+                               }],
+                               [AC_MSG_RESULT(yes)
+                               G_THREAD_LIBS="$G_THREAD_LIBS $add_thread_lib"
+                               posix_priority_min="sched_get_priority_min(SCHED_OTHER)"
+                               posix_priority_max="sched_get_priority_max(SCHED_OTHER)"
+                               break],
+                               [AC_MSG_RESULT(no)])
+               done
                LIBS="$glib_save_LIBS"
                 mutex_has_default=yes
                 mutex_default_type='pthread_mutex_t'
@@ -884,8 +907,8 @@ if test x"$enable_threads" = xyes; then
                        # The signature for the POSIX version is:
                        # int getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **)
                        AC_TRY_COMPILE([#include <pwd.h>
-                                        #include <sys/types.h>
-                                        #include <stdlib.h>],
+                               #include <sys/types.h>
+                               #include <stdlib.h>],
                                [getpwuid_r((uid_t)0, NULL, NULL, (size_t)0, NULL);],
                                [AC_DEFINE(HAVE_GETPWUID_R_POSIX)
                                AC_MSG_RESULT(yes)],
@@ -907,26 +930,7 @@ if test x"$enable_threads" = xyes; then
                        [AC_MSG_RESULT(yes)
                        AC_DEFINE(HAVE_PTHREAD_ATTR_SETSTACKSIZE)],
                        [AC_MSG_RESULT(no)])
-               # If sched_get_priority_min(SCHED_OTHER) returns something 
-               # negative, we ignore it.
                AC_MSG_CHECKING(for minimal/maximal thread priority)
-               AC_TRY_RUN([#include <pthread.h>
-                    int main () 
-                    { return sched_get_priority_min(SCHED_OTHER) == -1;}],
-                    [posix_priority_min="sched_get_priority_min(SCHED_OTHER)"
-                    posix_priority_max="sched_get_priority_max(SCHED_OTHER)"],
-                    [posix_priority_min=none])
-               # On some platforms we need to link to -lrt to use the 
-               # sched_* functions
-               LIBS="$LIBS -lrt"
-               AC_TRY_RUN([#include <pthread.h>
-                    int main () 
-                    { return sched_get_priority_min(SCHED_OTHER) == -1;}],
-                    [posix_priority_min="sched_get_priority_min(SCHED_OTHER)"
-                    posix_priority_max="sched_get_priority_max(SCHED_OTHER)"
-                    G_THREAD_LIBS="$G_THREAD_LIBS -lrt"],
-                    [posix_priority_min=none])
-               LIBS="$glib_save_LIBS $G_THREAD_LIBS"
                if test x"$posix_priority_min" = xnone; then
                        AC_EGREP_CPP(PX_PRIO_MIN,[#include <pthread.h>
                                PX_PRIO_MIN],,[
@@ -939,7 +943,7 @@ if test x"$enable_threads" = xyes; then
                                posix_priority_min=PRI_OTHER_MIN        
                                posix_priority_max=PRI_OTHER_MAX])
                fi
-               if test x"$posix_priority_min" = xnone; then
+               if test x"$posix_priority_min" = x; then
                        AC_MSG_RESULT(none found)
                        AC_MSG_WARN($POSIX_NO_PRIORITIES)
                        posix_priority_min=-1
index d613a5094df78f58900ed883bd847a0dfbef7287..4d68b772c7dc76ca179f20e60df8b71d1beb9543 100644 (file)
@@ -205,10 +205,41 @@ g_usleep (gulong microseconds)
 #ifdef G_OS_WIN32
   Sleep (microseconds / 1000);
 #else
-  struct timeval tv;
-  tv.tv_sec = microseconds / G_MICROSEC;
-  tv.tv_usec = microseconds % G_MICROSEC;
-  select(0, NULL, NULL, NULL, &tv);
+  if (g_thread_supported ())
+    {
+      static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+      static GCond* cond = NULL;
+      GTimeVal end_time;
+      
+      g_get_current_time (&end_time);
+      
+      end_time.tv_sec += microseconds / G_MICROSEC;
+      end_time.tv_usec += microseconds % G_MICROSEC;
+      
+      if (end_time.tv_usec >= G_MICROSEC)
+       {
+         end_time.tv_usec -= G_MICROSEC;
+         end_time.tv_sec += 1;
+       }
+      
+      g_static_mutex_lock (&mutex);
+      
+      if (!cond)
+       cond = g_cond_new ();
+      
+      while (g_cond_timed_wait (cond, g_static_mutex_get_mutex (&mutex), 
+                               &end_time))
+       /* do nothing */;
+      
+      g_static_mutex_unlock (&mutex);
+    }
+  else
+    {
+      struct timeval tv;
+      tv.tv_sec = microseconds / G_MICROSEC;
+      tv.tv_usec = microseconds % G_MICROSEC;
+      select(0, NULL, NULL, NULL, &tv);
+    }
 #endif
 }
 
index d613a5094df78f58900ed883bd847a0dfbef7287..4d68b772c7dc76ca179f20e60df8b71d1beb9543 100644 (file)
--- a/gtimer.c
+++ b/gtimer.c
@@ -205,10 +205,41 @@ g_usleep (gulong microseconds)
 #ifdef G_OS_WIN32
   Sleep (microseconds / 1000);
 #else
-  struct timeval tv;
-  tv.tv_sec = microseconds / G_MICROSEC;
-  tv.tv_usec = microseconds % G_MICROSEC;
-  select(0, NULL, NULL, NULL, &tv);
+  if (g_thread_supported ())
+    {
+      static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+      static GCond* cond = NULL;
+      GTimeVal end_time;
+      
+      g_get_current_time (&end_time);
+      
+      end_time.tv_sec += microseconds / G_MICROSEC;
+      end_time.tv_usec += microseconds % G_MICROSEC;
+      
+      if (end_time.tv_usec >= G_MICROSEC)
+       {
+         end_time.tv_usec -= G_MICROSEC;
+         end_time.tv_sec += 1;
+       }
+      
+      g_static_mutex_lock (&mutex);
+      
+      if (!cond)
+       cond = g_cond_new ();
+      
+      while (g_cond_timed_wait (cond, g_static_mutex_get_mutex (&mutex), 
+                               &end_time))
+       /* do nothing */;
+      
+      g_static_mutex_unlock (&mutex);
+    }
+  else
+    {
+      struct timeval tv;
+      tv.tv_sec = microseconds / G_MICROSEC;
+      tv.tv_usec = microseconds % G_MICROSEC;
+      select(0, NULL, NULL, NULL, &tv);
+    }
 #endif
 }