mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-12 21:50:36 +01:00
After finding the right thread library (containing e.g. pthread_create) we
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).
This commit is contained in:
parent
dd781b91ec
commit
ac4abbba3e
14
ChangeLog
14
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>
|
Wed Mar 22 16:49:57 2000 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* gmem.c (g_mem_chunk_area_compare): Fix indentation.
|
* gmem.c (g_mem_chunk_area_compare): Fix indentation.
|
||||||
|
@ -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>
|
Wed Mar 22 16:49:57 2000 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* gmem.c (g_mem_chunk_area_compare): Fix indentation.
|
* gmem.c (g_mem_chunk_area_compare): Fix indentation.
|
||||||
|
@ -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>
|
Wed Mar 22 16:49:57 2000 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* gmem.c (g_mem_chunk_area_compare): Fix indentation.
|
* gmem.c (g_mem_chunk_area_compare): Fix indentation.
|
||||||
|
@ -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>
|
Wed Mar 22 16:49:57 2000 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* gmem.c (g_mem_chunk_area_compare): Fix indentation.
|
* gmem.c (g_mem_chunk_area_compare): Fix indentation.
|
||||||
|
@ -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>
|
Wed Mar 22 16:49:57 2000 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* gmem.c (g_mem_chunk_area_compare): Fix indentation.
|
* gmem.c (g_mem_chunk_area_compare): Fix indentation.
|
||||||
|
@ -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>
|
Wed Mar 22 16:49:57 2000 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* gmem.c (g_mem_chunk_area_compare): Fix indentation.
|
* gmem.c (g_mem_chunk_area_compare): Fix indentation.
|
||||||
|
@ -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>
|
Wed Mar 22 16:49:57 2000 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* gmem.c (g_mem_chunk_area_compare): Fix indentation.
|
* gmem.c (g_mem_chunk_area_compare): Fix indentation.
|
||||||
|
@ -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>
|
Wed Mar 22 16:49:57 2000 Owen Taylor <otaylor@redhat.com>
|
||||||
|
|
||||||
* gmem.c (g_mem_chunk_area_compare): Fix indentation.
|
* gmem.c (g_mem_chunk_area_compare): Fix indentation.
|
||||||
|
52
configure.in
52
configure.in
@ -733,8 +733,6 @@ case $have_threads in
|
|||||||
G_THREAD_LIBS=error
|
G_THREAD_LIBS=error
|
||||||
glib_save_LIBS="$LIBS"
|
glib_save_LIBS="$LIBS"
|
||||||
for thread_lib in "" pthread pthreads c_r thread dce; do
|
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
|
if test x"$thread_lib" = x; then
|
||||||
add_thread_lib=""
|
add_thread_lib=""
|
||||||
IN=""
|
IN=""
|
||||||
@ -763,6 +761,31 @@ case $have_threads in
|
|||||||
break],
|
break],
|
||||||
[AC_MSG_RESULT(no)])
|
[AC_MSG_RESULT(no)])
|
||||||
done
|
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"
|
LIBS="$glib_save_LIBS"
|
||||||
mutex_has_default=yes
|
mutex_has_default=yes
|
||||||
mutex_default_type='pthread_mutex_t'
|
mutex_default_type='pthread_mutex_t'
|
||||||
@ -884,8 +907,8 @@ if test x"$enable_threads" = xyes; then
|
|||||||
# The signature for the POSIX version is:
|
# The signature for the POSIX version is:
|
||||||
# int getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **)
|
# int getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **)
|
||||||
AC_TRY_COMPILE([#include <pwd.h>
|
AC_TRY_COMPILE([#include <pwd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <stdlib.h>],
|
#include <stdlib.h>],
|
||||||
[getpwuid_r((uid_t)0, NULL, NULL, (size_t)0, NULL);],
|
[getpwuid_r((uid_t)0, NULL, NULL, (size_t)0, NULL);],
|
||||||
[AC_DEFINE(HAVE_GETPWUID_R_POSIX)
|
[AC_DEFINE(HAVE_GETPWUID_R_POSIX)
|
||||||
AC_MSG_RESULT(yes)],
|
AC_MSG_RESULT(yes)],
|
||||||
@ -907,26 +930,7 @@ if test x"$enable_threads" = xyes; then
|
|||||||
[AC_MSG_RESULT(yes)
|
[AC_MSG_RESULT(yes)
|
||||||
AC_DEFINE(HAVE_PTHREAD_ATTR_SETSTACKSIZE)],
|
AC_DEFINE(HAVE_PTHREAD_ATTR_SETSTACKSIZE)],
|
||||||
[AC_MSG_RESULT(no)])
|
[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_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
|
if test x"$posix_priority_min" = xnone; then
|
||||||
AC_EGREP_CPP(PX_PRIO_MIN,[#include <pthread.h>
|
AC_EGREP_CPP(PX_PRIO_MIN,[#include <pthread.h>
|
||||||
PX_PRIO_MIN],,[
|
PX_PRIO_MIN],,[
|
||||||
@ -939,7 +943,7 @@ if test x"$enable_threads" = xyes; then
|
|||||||
posix_priority_min=PRI_OTHER_MIN
|
posix_priority_min=PRI_OTHER_MIN
|
||||||
posix_priority_max=PRI_OTHER_MAX])
|
posix_priority_max=PRI_OTHER_MAX])
|
||||||
fi
|
fi
|
||||||
if test x"$posix_priority_min" = xnone; then
|
if test x"$posix_priority_min" = x; then
|
||||||
AC_MSG_RESULT(none found)
|
AC_MSG_RESULT(none found)
|
||||||
AC_MSG_WARN($POSIX_NO_PRIORITIES)
|
AC_MSG_WARN($POSIX_NO_PRIORITIES)
|
||||||
posix_priority_min=-1
|
posix_priority_min=-1
|
||||||
|
@ -205,10 +205,41 @@ g_usleep (gulong microseconds)
|
|||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
Sleep (microseconds / 1000);
|
Sleep (microseconds / 1000);
|
||||||
#else
|
#else
|
||||||
struct timeval tv;
|
if (g_thread_supported ())
|
||||||
tv.tv_sec = microseconds / G_MICROSEC;
|
{
|
||||||
tv.tv_usec = microseconds % G_MICROSEC;
|
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
||||||
select(0, NULL, NULL, NULL, &tv);
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
39
gtimer.c
39
gtimer.c
@ -205,10 +205,41 @@ g_usleep (gulong microseconds)
|
|||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
Sleep (microseconds / 1000);
|
Sleep (microseconds / 1000);
|
||||||
#else
|
#else
|
||||||
struct timeval tv;
|
if (g_thread_supported ())
|
||||||
tv.tv_sec = microseconds / G_MICROSEC;
|
{
|
||||||
tv.tv_usec = microseconds % G_MICROSEC;
|
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
||||||
select(0, NULL, NULL, NULL, &tv);
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user