Add a surrogate for thread priorities using PID niceness for systems with

2000-11-21  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>

	* configure.in: Add a surrogate for thread priorities using PID
	niceness for systems with no thread priorities and different PIDs
	for threads of the same process (most notably: Linux). Define
	G_THREAD_USE_PID_SURROGATE in that case, as used by
	gthread-posix.c. Also make the system thread bigger by
	sizeof (long) to contain the thread's PID.

	* gfileutils.c: Include stdlib.h for mkstemp prototype.

	* gthread.c: Add priority range checks to the affected functions.

	* gthreadpool.c: Remove unused variable.

	* gthread-impl.c, gthread-posix.c, gthread-solaris.c: Removed
	g_thread_map_priority function in favour of the
	g_thread_priority_map array.  Initialize the array with
	PRIORITY_{...}_VALUE, if available and interpolate beetween the
	bounds if .._NORMAL_.. and .._HIGH_.. are not available.

	* gthread-posix.c: If we should use the PID niceness as a
	surrogate for thread priorities (G_THREAD_USE_PID_SURROGATE is
	defined), then disable normal priority handling and use PIDs and
	setpriority() instead. Depends on the thread to write its PID into
	the place after the thread id right after thread creation.
This commit is contained in:
Sebastian Wilhelmi
2000-11-21 15:27:44 +00:00
committed by Sebastian Wilhelmi
parent 55bdf1322b
commit a3036a5bd2
19 changed files with 292 additions and 56 deletions

View File

@@ -38,12 +38,28 @@
#include <glib.h>
static gboolean thread_system_already_initialized = FALSE;
static gint g_thread_map_priority (GThreadPriority priority);
static gint g_thread_min_priority = 0;
static gint g_thread_max_priority = 0;
static gint g_thread_priority_map [G_THREAD_PRIORITY_URGENT];
#include G_THREAD_SOURCE
#ifndef PRIORITY_LOW_VALUE
# define PRIORITY_LOW_VALUE 0
#endif
#ifndef PRIORITY_URGENT_VALUE
# define PRIORITY_URGENT_VALUE 0
#endif
#ifndef PRIORITY_NORMAL_VALUE
# define PRIORITY_NORMAL_VALUE \
PRIORITY_LOW_VALUE + (PRIORITY_URGENT_VALUE - PRIORITY_LOW_VALUE) * 40 / 100
#endif /* PRIORITY_NORMAL_VALUE */
#ifndef PRIORITY_HIGH_VALUE
# define PRIORITY_HIGH_VALUE \
PRIORITY_LOW_VALUE + (PRIORITY_URGENT_VALUE - PRIORITY_LOW_VALUE) * 80 / 100
#endif /* PRIORITY_HIGH_VALUE */
void g_mutex_init (void);
void g_mem_init (void);
void g_messages_init (void);
@@ -258,6 +274,11 @@ g_thread_init (GThreadFunctions* init)
g_thread_impl_init();
#endif
g_thread_priority_map [G_THREAD_PRIORITY_LOW] = PRIORITY_LOW_VALUE;
g_thread_priority_map [G_THREAD_PRIORITY_NORMAL] = PRIORITY_NORMAL_VALUE;
g_thread_priority_map [G_THREAD_PRIORITY_HIGH] = PRIORITY_HIGH_VALUE;
g_thread_priority_map [G_THREAD_PRIORITY_URGENT] = PRIORITY_URGENT_VALUE;
/* now call the thread initialization functions of the different
* glib modules. order does matter, g_mutex_init MUST come first.
*/
@@ -273,18 +294,3 @@ g_thread_init (GThreadFunctions* init)
/* we want the main thread to run with normal priority */
g_thread_set_priority (g_thread_self(), G_THREAD_PRIORITY_NORMAL);
}
static gint
g_thread_map_priority (GThreadPriority priority)
{
guint procent;
switch (priority)
{
case G_THREAD_PRIORITY_LOW: procent = 0; break;
default: case G_THREAD_PRIORITY_NORMAL: procent = 40; break;
case G_THREAD_PRIORITY_HIGH: procent = 80; break;
case G_THREAD_PRIORITY_URGENT: procent = 100; break;
}
return g_thread_min_priority +
(g_thread_max_priority - g_thread_min_priority) * procent / 100;
}