+2001-02-15 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+
+ * acconfig.h, configure.in: Reverted the changes necessary to
+ enlarge the system thread for G_THREAD_USE_PID_SURROGATE.
+
+ * gthread.c: Now implement G_THREAD_USE_PID_SURROGATE in gthread.c
+ instead of gthread/gthread-posix.c. While the latter has the
+ advantage, that it is conceptually cleaner, it makes
+ g_thread_self_posix_impl _very_ slow and that hurts
+ GStaticRecMutex and other things. So the new version is less
+ clean, but faster.
+
2001-02-09 Havoc Pennington <hp@redhat.com>
* gconvert.c (g_convert): don't overwrite errors
+2001-02-15 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+
+ * acconfig.h, configure.in: Reverted the changes necessary to
+ enlarge the system thread for G_THREAD_USE_PID_SURROGATE.
+
+ * gthread.c: Now implement G_THREAD_USE_PID_SURROGATE in gthread.c
+ instead of gthread/gthread-posix.c. While the latter has the
+ advantage, that it is conceptually cleaner, it makes
+ g_thread_self_posix_impl _very_ slow and that hurts
+ GStaticRecMutex and other things. So the new version is less
+ clean, but faster.
+
2001-02-09 Havoc Pennington <hp@redhat.com>
* gconvert.c (g_convert): don't overwrite errors
+2001-02-15 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+
+ * acconfig.h, configure.in: Reverted the changes necessary to
+ enlarge the system thread for G_THREAD_USE_PID_SURROGATE.
+
+ * gthread.c: Now implement G_THREAD_USE_PID_SURROGATE in gthread.c
+ instead of gthread/gthread-posix.c. While the latter has the
+ advantage, that it is conceptually cleaner, it makes
+ g_thread_self_posix_impl _very_ slow and that hurts
+ GStaticRecMutex and other things. So the new version is less
+ clean, but faster.
+
2001-02-09 Havoc Pennington <hp@redhat.com>
* gconvert.c (g_convert): don't overwrite errors
+2001-02-15 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+
+ * acconfig.h, configure.in: Reverted the changes necessary to
+ enlarge the system thread for G_THREAD_USE_PID_SURROGATE.
+
+ * gthread.c: Now implement G_THREAD_USE_PID_SURROGATE in gthread.c
+ instead of gthread/gthread-posix.c. While the latter has the
+ advantage, that it is conceptually cleaner, it makes
+ g_thread_self_posix_impl _very_ slow and that hurts
+ GStaticRecMutex and other things. So the new version is less
+ clean, but faster.
+
2001-02-09 Havoc Pennington <hp@redhat.com>
* gconvert.c (g_convert): don't overwrite errors
+2001-02-15 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+
+ * acconfig.h, configure.in: Reverted the changes necessary to
+ enlarge the system thread for G_THREAD_USE_PID_SURROGATE.
+
+ * gthread.c: Now implement G_THREAD_USE_PID_SURROGATE in gthread.c
+ instead of gthread/gthread-posix.c. While the latter has the
+ advantage, that it is conceptually cleaner, it makes
+ g_thread_self_posix_impl _very_ slow and that hurts
+ GStaticRecMutex and other things. So the new version is less
+ clean, but faster.
+
2001-02-09 Havoc Pennington <hp@redhat.com>
* gconvert.c (g_convert): don't overwrite errors
+2001-02-15 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+
+ * acconfig.h, configure.in: Reverted the changes necessary to
+ enlarge the system thread for G_THREAD_USE_PID_SURROGATE.
+
+ * gthread.c: Now implement G_THREAD_USE_PID_SURROGATE in gthread.c
+ instead of gthread/gthread-posix.c. While the latter has the
+ advantage, that it is conceptually cleaner, it makes
+ g_thread_self_posix_impl _very_ slow and that hurts
+ GStaticRecMutex and other things. So the new version is less
+ clean, but faster.
+
2001-02-09 Havoc Pennington <hp@redhat.com>
* gconvert.c (g_convert): don't overwrite errors
+2001-02-15 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+
+ * acconfig.h, configure.in: Reverted the changes necessary to
+ enlarge the system thread for G_THREAD_USE_PID_SURROGATE.
+
+ * gthread.c: Now implement G_THREAD_USE_PID_SURROGATE in gthread.c
+ instead of gthread/gthread-posix.c. While the latter has the
+ advantage, that it is conceptually cleaner, it makes
+ g_thread_self_posix_impl _very_ slow and that hurts
+ GStaticRecMutex and other things. So the new version is less
+ clean, but faster.
+
2001-02-09 Havoc Pennington <hp@redhat.com>
* gconvert.c (g_convert): don't overwrite errors
+2001-02-15 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+
+ * acconfig.h, configure.in: Reverted the changes necessary to
+ enlarge the system thread for G_THREAD_USE_PID_SURROGATE.
+
+ * gthread.c: Now implement G_THREAD_USE_PID_SURROGATE in gthread.c
+ instead of gthread/gthread-posix.c. While the latter has the
+ advantage, that it is conceptually cleaner, it makes
+ g_thread_self_posix_impl _very_ slow and that hurts
+ GStaticRecMutex and other things. So the new version is less
+ clean, but faster.
+
2001-02-09 Havoc Pennington <hp@redhat.com>
* gconvert.c (g_convert): don't overwrite errors
#undef ENABLE_NLS
#undef GETTEXT_PACKAGE
-#undef GLIB_SIZEOF_SYSTEM_THREAD
#undef GLIB_LOCALE_DIR
#undef HAVE_GETTEXT
#undef HAVE_LC_MESSAGES
glib_save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $GTHREAD_COMPILE_IMPL_DEFINES"
dnl we might grow sizeof(pthread_t) later on, so use a dummy name here
- GLIB_SIZEOF([#include <pthread.h>], pthread_t, core_system_thread)
+ GLIB_SIZEOF([#include <pthread.h>], 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)
CPPFLAGS="$glib_save_CPPFLAGS"
AC_MSG_CHECKING(whether to use the PID niceness surrogate for thread priorities)
- glib_system_thread_size_growth=0
AC_TRY_RUN([#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>
}],
[AC_MSG_RESULT(yes),
AC_DEFINE(G_THREAD_USE_PID_SURROGATE, 1, [whether to use the PID niceness surrogate for thread priorities])
- glib_system_thread_size_growth=$ac_cv_sizeof_long
],
[AC_MSG_RESULT(no)])
- dnl make sure both glib_cv_sizeof_system_thread and GLIB_SIZEOF_SYSTEM_THREAD are setup
- glib_cv_sizeof_system_thread=`expr $glib_cv_sizeof_core_system_thread + $glib_system_thread_size_growth`
- AC_DEFINE_UNQUOTED(GLIB_SIZEOF_SYSTEM_THREAD, $glib_cv_sizeof_system_thread)
else # solaris threads
GLIB_SIZEOF([#include <thread.h>], thread_t, system_thread)
fi
#include "config.h"
#include "glib.h"
+#ifdef G_THREAD_USE_PID_SURROGATE
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <errno.h>
+#endif /* G_THREAD_USE_PID_SURROGATE */
+
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
gpointer arg;
gpointer private_data;
GSystemThread system_thread;
+#ifdef G_THREAD_USE_PID_SURROGATE
+ pid_t pid;
+#endif /* G_THREAD_USE_PID_SURROGATE */
};
+#ifdef G_THREAD_USE_PID_SURROGATE
+static gint priority_map[] = { 15, 0, -15, -20 };
+static gboolean prio_warned = FALSE;
+# define SET_PRIO(pid, prio) G_STMT_START{ \
+ gint error = setpriority (PRIO_PROCESS, (pid), priority_map[prio]); \
+ if (error == -1 && errno == EACCES && !prio_warned) \
+ { \
+ prio_warned = TRUE; \
+ g_warning ("Priorities can only be increased by root."); \
+ } \
+ }G_STMT_END
+#endif /* G_THREAD_USE_PID_SURROGATE */
+
typedef struct _GStaticPrivateNode GStaticPrivateNode;
struct _GStaticPrivateNode
{
g_assert (data);
+#ifdef G_THREAD_USE_PID_SURROGATE
+ thread->pid = getpid ();
+#endif /* G_THREAD_USE_PID_SURROGATE */
+
/* This has to happen before G_LOCK, as that might call g_thread_self */
g_private_set (g_thread_specific_private, data);
before thread->func is called. See g_thread_create. */
G_LOCK (g_thread);
G_UNLOCK (g_thread);
+
+ if (g_thread_use_default_impl)
+ SET_PRIO (thread->pid, thread->thread.priority);
thread->func (thread->arg);
}
g_return_if_fail (priority <= G_THREAD_PRIORITY_URGENT);
thread->priority = priority;
- G_THREAD_CF (thread_set_priority, (void)0, (&real->system_thread, priority));
+
+#ifdef G_THREAD_USE_PID_SURROGATE
+ if (g_thread_use_default_impl)
+ SET_PRIO (real->pid, priority);
+ else
+#endif /* G_THREAD_USE_PID_SURROGATE */
+ G_THREAD_CF (thread_set_priority, (void)0,
+ (&real->system_thread, priority));
}
GThread*
if (g_thread_supported ())
G_THREAD_UF (thread_self, (&thread->system_thread));
+#ifdef G_THREAD_USE_PID_SURROGATE
+ thread->pid = getpid ();
+#endif /* G_THREAD_USE_PID_SURROGATE */
+
g_private_set (g_thread_specific_private, thread);
G_LOCK (g_thread);
#include "config.h"
#include "glib.h"
+#ifdef G_THREAD_USE_PID_SURROGATE
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <errno.h>
+#endif /* G_THREAD_USE_PID_SURROGATE */
+
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
gpointer arg;
gpointer private_data;
GSystemThread system_thread;
+#ifdef G_THREAD_USE_PID_SURROGATE
+ pid_t pid;
+#endif /* G_THREAD_USE_PID_SURROGATE */
};
+#ifdef G_THREAD_USE_PID_SURROGATE
+static gint priority_map[] = { 15, 0, -15, -20 };
+static gboolean prio_warned = FALSE;
+# define SET_PRIO(pid, prio) G_STMT_START{ \
+ gint error = setpriority (PRIO_PROCESS, (pid), priority_map[prio]); \
+ if (error == -1 && errno == EACCES && !prio_warned) \
+ { \
+ prio_warned = TRUE; \
+ g_warning ("Priorities can only be increased by root."); \
+ } \
+ }G_STMT_END
+#endif /* G_THREAD_USE_PID_SURROGATE */
+
typedef struct _GStaticPrivateNode GStaticPrivateNode;
struct _GStaticPrivateNode
{
g_assert (data);
+#ifdef G_THREAD_USE_PID_SURROGATE
+ thread->pid = getpid ();
+#endif /* G_THREAD_USE_PID_SURROGATE */
+
/* This has to happen before G_LOCK, as that might call g_thread_self */
g_private_set (g_thread_specific_private, data);
before thread->func is called. See g_thread_create. */
G_LOCK (g_thread);
G_UNLOCK (g_thread);
+
+ if (g_thread_use_default_impl)
+ SET_PRIO (thread->pid, thread->thread.priority);
thread->func (thread->arg);
}
g_return_if_fail (priority <= G_THREAD_PRIORITY_URGENT);
thread->priority = priority;
- G_THREAD_CF (thread_set_priority, (void)0, (&real->system_thread, priority));
+
+#ifdef G_THREAD_USE_PID_SURROGATE
+ if (g_thread_use_default_impl)
+ SET_PRIO (real->pid, priority);
+ else
+#endif /* G_THREAD_USE_PID_SURROGATE */
+ G_THREAD_CF (thread_set_priority, (void)0,
+ (&real->system_thread, priority));
}
GThread*
if (g_thread_supported ())
G_THREAD_UF (thread_self, (&thread->system_thread));
+#ifdef G_THREAD_USE_PID_SURROGATE
+ thread->pid = getpid ();
+#endif /* G_THREAD_USE_PID_SURROGATE */
+
g_private_set (g_thread_specific_private, thread);
G_LOCK (g_thread);
+2001-02-15 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+
+ * gthread-posix.c: Removed the G_THREAD_USE_PID_SURROGATE
+ implementation, which is now in gthread.c.
+
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* gthread-impl.c (g_thread_init_with_errorcheck_mutexes): Call
#include <sched.h>
#endif
-#ifdef G_THREAD_USE_PID_SURROGATE
-# include <sys/resource.h>
-# define PID_IN_THREAD(thread) (*(pid_t*)(((gchar*)thread)+sizeof(pthread_t)))
-# define SET_PRIO(pid, prio) \
- posix_check_cmd_prio ((setpriority (PRIO_PROCESS, (pid), \
- g_thread_priority_map [prio]) == -1) ? \
- (errno == EACCES ? EPERM : errno ): 0)
-#endif /* G_THREAD_USE_PID_SURROGATE */
-
#define posix_check_err(err, name) G_STMT_START{ \
int error = (err); \
if (error) \
# error This should not happen. Contact the GLib team.
#endif
-#ifdef G_THREAD_USE_PID_SURROGATE
-# define PRIORITY_LOW_VALUE 15
-# define PRIORITY_NORMAL_VALUE 0
-# define PRIORITY_HIGH_VALUE -15
-# define PRIORITY_URGENT_VALUE -20
-#elif defined (POSIX_MIN_PRIORITY) && defined (POSIX_MAX_PRIORITY)
+#if defined (POSIX_MIN_PRIORITY) && defined (POSIX_MAX_PRIORITY)
# define HAVE_PRIORITIES 1
# define PRIORITY_LOW_VALUE POSIX_MIN_PRIORITY
# define PRIORITY_URGENT_VALUE POSIX_MAX_PRIORITY
#endif
}
-#ifdef G_THREAD_USE_PID_SURROGATE
-struct proxy_data
-{
- GThreadFunc thread_func;
- gpointer arg;
- gpointer thread;
- GThreadPriority priority;
-};
-
-static void
-g_thread_create_posix_impl_proxy (struct proxy_data *data)
-{
- GThreadFunc thread_func = data->thread_func;
- GThreadFunc arg = data->arg;
- PID_IN_THREAD (data->thread) = getpid();
- SET_PRIO (PID_IN_THREAD (data->thread), data->priority);
- g_free (data);
- thread_func (arg);
-}
-#endif /* G_THREAD_USE_PID_SURROGATE */
-
static void
g_thread_create_posix_impl (GThreadFunc thread_func,
gpointer arg,
joinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED));
#endif /* G_THREADS_IMPL_POSIX */
-#ifdef G_THREAD_USE_PID_SURROGATE
- {
- struct proxy_data *data = g_new (struct proxy_data, 1);
- data->thread_func = thread_func;
- data->arg = arg;
- data->thread = thread;
- data->priority = priority;
- PID_IN_THREAD (thread) = 0;
- ret = posix_error (pthread_create (thread, &attr, (void* (*)(void*))
- g_thread_create_posix_impl_proxy,
- data));
- }
-#else /* G_THREAD_USE_PID_SURROGATE */
-# ifdef HAVE_PRIORITIES
-# ifdef G_THREADS_IMPL_POSIX
+#ifdef HAVE_PRIORITIES
+# ifdef G_THREADS_IMPL_POSIX
{
struct sched_param sched;
posix_check_cmd (pthread_attr_getschedparam (&attr, &sched));
sched.sched_priority = g_thread_priority_map [priority];
posix_check_cmd_prio (pthread_attr_setschedparam (&attr, &sched));
}
-# else /* G_THREADS_IMPL_DCE */
+# else /* G_THREADS_IMPL_DCE */
posix_check_cmd_prio
(pthread_attr_setprio (&attr, g_thread_priority_map [priority]));
-# endif /* G_THREADS_IMPL_DCE */
-# endif /* HAVE_PRIORITIES */
+# endif /* G_THREADS_IMPL_DCE */
+#endif /* HAVE_PRIORITIES */
ret = posix_error (pthread_create (thread, &attr,
(void* (*)(void*))thread_func, arg));
-#endif /* !G_THREAD_USE_PID_SURROGATE */
posix_check_cmd (pthread_attr_destroy (&attr));
posix_check_cmd_prio (pthread_setprio (*(pthread_t*)thread,
g_thread_priority_map [priority]));
# endif
-#elif defined (G_THREAD_USE_PID_SURROGATE)
- /* If the addressed thread hasn't yet been able to provide it's pid,
- * we ignore the request. Should be more than rare */
- if (PID_IN_THREAD (thread) != 0)
- SET_PRIO (PID_IN_THREAD (thread), priority);
-#endif /* G_THREAD_USE_PID_SURROGATE */
+#endif /* HAVE_PRIORITIES */
}
static void
g_thread_self_posix_impl (gpointer thread)
{
*(pthread_t*)thread = pthread_self();
-#ifdef G_THREAD_USE_PID_SURROGATE
- PID_IN_THREAD (thread) = getpid();
-#endif /* G_THREAD_USE_PID_SURROGATE */
}
static GThreadFunctions g_thread_functions_for_glib_use_default =