mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 11:26:16 +01:00
GThread: deprecate thread priorities
Thread priorities were already documented as not working on Solaris, and they are meaningless on Linux unless the process separately requests realtime scheduling (and even then, it appears only to work as root). We can safely put a NULL into the vtable for set_priority since nothing outside of gthread.c ever calls this (and that call is gone).
This commit is contained in:
parent
a10306060c
commit
51d92adeee
@ -480,74 +480,6 @@ g_private_set (GPrivate *key,
|
||||
|
||||
#define posix_check_cmd(cmd) posix_check_err (cmd, #cmd)
|
||||
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
static gboolean posix_check_cmd_prio_warned = FALSE;
|
||||
# define posix_check_cmd_prio(cmd) G_STMT_START{ \
|
||||
int err = (cmd); \
|
||||
if (err == EPERM) \
|
||||
{ \
|
||||
if (!posix_check_cmd_prio_warned) \
|
||||
{ \
|
||||
posix_check_cmd_prio_warned = TRUE; \
|
||||
g_warning ("Priorities can only be changed " \
|
||||
"(resp. increased) by root."); \
|
||||
} \
|
||||
} \
|
||||
else \
|
||||
posix_check_err (err, #cmd); \
|
||||
}G_STMT_END
|
||||
#else /* G_ENABLE_DEBUG */
|
||||
# define posix_check_cmd_prio(cmd) G_STMT_START{ \
|
||||
int err = (cmd); \
|
||||
if (err != EPERM) \
|
||||
posix_check_err (err, #cmd); \
|
||||
}G_STMT_END
|
||||
#endif /* G_ENABLE_DEBUG */
|
||||
|
||||
#if defined (POSIX_MIN_PRIORITY) && defined (POSIX_MAX_PRIORITY)
|
||||
# define HAVE_PRIORITIES 1
|
||||
static gint priority_normal_value;
|
||||
# ifdef __FreeBSD__
|
||||
/* FreeBSD threads use different priority values from the POSIX_
|
||||
* defines so we just set them here. The corresponding macros
|
||||
* PTHREAD_MIN_PRIORITY and PTHREAD_MAX_PRIORITY are implied to be
|
||||
* exported by the docs, but they aren't.
|
||||
*/
|
||||
# define PRIORITY_LOW_VALUE 0
|
||||
# define PRIORITY_URGENT_VALUE 31
|
||||
# else /* !__FreeBSD__ */
|
||||
# define PRIORITY_LOW_VALUE POSIX_MIN_PRIORITY
|
||||
# define PRIORITY_URGENT_VALUE POSIX_MAX_PRIORITY
|
||||
# endif /* !__FreeBSD__ */
|
||||
# define PRIORITY_NORMAL_VALUE priority_normal_value
|
||||
|
||||
# define PRIORITY_HIGH_VALUE \
|
||||
((PRIORITY_NORMAL_VALUE + PRIORITY_URGENT_VALUE * 2) / 3)
|
||||
|
||||
static gint
|
||||
g_thread_priority_map (GThreadPriority priority)
|
||||
{
|
||||
switch (priority)
|
||||
{
|
||||
case G_THREAD_PRIORITY_LOW:
|
||||
return PRIORITY_LOW_VALUE;
|
||||
|
||||
case G_THREAD_PRIORITY_NORMAL:
|
||||
return PRIORITY_NORMAL_VALUE;
|
||||
|
||||
case G_THREAD_PRIORITY_HIGH:
|
||||
return PRIORITY_HIGH_VALUE;
|
||||
|
||||
case G_THREAD_PRIORITY_URGENT:
|
||||
return PRIORITY_URGENT_VALUE;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* POSIX_MIN_PRIORITY && POSIX_MAX_PRIORITY */
|
||||
|
||||
static gulong g_thread_min_stack_size = 0;
|
||||
|
||||
#define G_MUTEX_SIZE (sizeof (pthread_mutex_t))
|
||||
@ -558,14 +490,6 @@ _g_thread_impl_init(void)
|
||||
#ifdef _SC_THREAD_STACK_MIN
|
||||
g_thread_min_stack_size = MAX (sysconf (_SC_THREAD_STACK_MIN), 0);
|
||||
#endif /* _SC_THREAD_STACK_MIN */
|
||||
#ifdef HAVE_PRIORITIES
|
||||
{
|
||||
struct sched_param sched;
|
||||
int policy;
|
||||
posix_check_cmd (pthread_getschedparam (pthread_self(), &policy, &sched));
|
||||
priority_normal_value = sched.sched_priority;
|
||||
}
|
||||
#endif /* HAVE_PRIORITIES */
|
||||
}
|
||||
|
||||
static void
|
||||
@ -582,8 +506,6 @@ g_thread_create_posix_impl (GThreadFunc thread_func,
|
||||
gint ret;
|
||||
|
||||
g_return_if_fail (thread_func);
|
||||
g_return_if_fail (priority >= G_THREAD_PRIORITY_LOW);
|
||||
g_return_if_fail (priority <= G_THREAD_PRIORITY_URGENT);
|
||||
|
||||
posix_check_cmd (pthread_attr_init (&attr));
|
||||
|
||||
@ -607,14 +529,6 @@ g_thread_create_posix_impl (GThreadFunc thread_func,
|
||||
posix_check_cmd (pthread_attr_setdetachstate (&attr,
|
||||
joinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED));
|
||||
|
||||
#ifdef HAVE_PRIORITIES
|
||||
{
|
||||
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));
|
||||
}
|
||||
#endif /* HAVE_PRIORITIES */
|
||||
ret = pthread_create (thread, &attr, (void* (*)(void*))thread_func, arg);
|
||||
|
||||
posix_check_cmd (pthread_attr_destroy (&attr));
|
||||
@ -657,24 +571,6 @@ g_system_thread_exit (void)
|
||||
pthread_exit (NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
g_thread_set_priority_posix_impl (gpointer thread, GThreadPriority priority)
|
||||
{
|
||||
g_return_if_fail (priority >= G_THREAD_PRIORITY_LOW);
|
||||
g_return_if_fail (priority <= G_THREAD_PRIORITY_URGENT);
|
||||
#ifdef HAVE_PRIORITIES
|
||||
{
|
||||
struct sched_param sched;
|
||||
int policy;
|
||||
posix_check_cmd (pthread_getschedparam (*(pthread_t*)thread, &policy,
|
||||
&sched));
|
||||
sched.sched_priority = g_thread_priority_map (priority);
|
||||
posix_check_cmd_prio (pthread_setschedparam (*(pthread_t*)thread, policy,
|
||||
&sched));
|
||||
}
|
||||
#endif /* HAVE_PRIORITIES */
|
||||
}
|
||||
|
||||
static void
|
||||
g_thread_self_posix_impl (gpointer thread)
|
||||
{
|
||||
@ -709,7 +605,7 @@ GThreadFunctions g_thread_functions_for_glib_use =
|
||||
g_thread_yield,
|
||||
g_thread_join_posix_impl,
|
||||
g_system_thread_exit,
|
||||
g_thread_set_priority_posix_impl,
|
||||
NULL,
|
||||
g_thread_self_posix_impl,
|
||||
g_system_thread_equal,
|
||||
};
|
||||
|
@ -316,38 +316,6 @@ struct _GThreadData
|
||||
gboolean joinable;
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
g_thread_set_priority_win32_impl (gpointer thread, GThreadPriority priority)
|
||||
{
|
||||
GThreadData *target = *(GThreadData **)thread;
|
||||
gint native_prio;
|
||||
|
||||
switch (priority)
|
||||
{
|
||||
case G_THREAD_PRIORITY_LOW:
|
||||
native_prio = THREAD_PRIORITY_BELOW_NORMAL;
|
||||
break;
|
||||
|
||||
case G_THREAD_PRIORITY_NORMAL:
|
||||
native_prio = THREAD_PRIORITY_NORMAL;
|
||||
break;
|
||||
|
||||
case G_THREAD_PRIORITY_HIGH:
|
||||
native_prio = THREAD_PRIORITY_ABOVE_NORMAL;
|
||||
break;
|
||||
|
||||
case G_THREAD_PRIORITY_URGENT:
|
||||
native_prio = THREAD_PRIORITY_HIGHEST;
|
||||
break;
|
||||
|
||||
default:
|
||||
g_return_if_reached ();
|
||||
}
|
||||
|
||||
win32_check_for_error (SetThreadPriority (target->thread, native_prio));
|
||||
}
|
||||
|
||||
static void
|
||||
g_thread_self_win32_impl (gpointer thread)
|
||||
{
|
||||
@ -452,8 +420,6 @@ g_thread_create_win32_impl (GThreadFunc func,
|
||||
GThreadData *retval;
|
||||
|
||||
g_return_if_fail (func);
|
||||
g_return_if_fail (priority >= G_THREAD_PRIORITY_LOW);
|
||||
g_return_if_fail (priority <= G_THREAD_PRIORITY_URGENT);
|
||||
|
||||
retval = g_new(GThreadData, 1);
|
||||
retval->func = func;
|
||||
@ -475,8 +441,6 @@ g_thread_create_win32_impl (GThreadFunc func,
|
||||
}
|
||||
|
||||
*(GThreadData **)thread = retval;
|
||||
|
||||
g_thread_set_priority_win32_impl (thread, priority);
|
||||
}
|
||||
|
||||
void
|
||||
@ -808,7 +772,7 @@ GThreadFunctions g_thread_functions_for_glib_use =
|
||||
g_thread_yield,
|
||||
g_thread_join_win32_impl,
|
||||
g_system_thread_exit,
|
||||
g_thread_set_priority_win32_impl,
|
||||
NULL,
|
||||
g_thread_self_win32_impl,
|
||||
g_system_thread_equal
|
||||
};
|
||||
|
@ -621,13 +621,7 @@ static GThreadFunctions g_thread_functions_for_glib_use_old = {
|
||||
* @G_THREAD_PRIORITY_HIGH: a priority higher than normal
|
||||
* @G_THREAD_PRIORITY_URGENT: the highest priority
|
||||
*
|
||||
* Specifies the priority of a thread.
|
||||
*
|
||||
* <note><para>It is not guaranteed that threads with different priorities
|
||||
* really behave accordingly. On some systems (e.g. Linux) there are no
|
||||
* thread priorities. On other systems (e.g. Solaris) there doesn't
|
||||
* seem to be different scheduling for different priorities. All in all
|
||||
* try to avoid being dependent on priorities.</para></note>
|
||||
* Deprecated:2.32: thread priorities no longer have any effect.
|
||||
**/
|
||||
|
||||
(void(*)(GThreadFunc, gpointer, gulong,
|
||||
@ -1707,7 +1701,7 @@ g_thread_create_proxy (gpointer data)
|
||||
* @joinable: should this thread be joinable?
|
||||
* @error: return location for error, or %NULL
|
||||
*
|
||||
* This function creates a new thread with the default priority.
|
||||
* This function creates a new thread.
|
||||
*
|
||||
* If @joinable is %TRUE, you can wait for this threads termination
|
||||
* calling g_thread_join(). Otherwise the thread will just disappear
|
||||
@ -1729,14 +1723,14 @@ g_thread_create_proxy (gpointer data)
|
||||
* @stack_size: a stack size for the new thread.
|
||||
* @joinable: should this thread be joinable?
|
||||
* @bound: should this thread be bound to a system thread?
|
||||
* @priority: a priority for the thread.
|
||||
* @priority: ignored
|
||||
* @error: return location for error.
|
||||
* @Returns: the new #GThread on success.
|
||||
*
|
||||
* This function creates a new thread with the priority @priority. If
|
||||
* the underlying thread implementation supports it, the thread gets a
|
||||
* stack size of @stack_size or the default value for the current
|
||||
* platform, if @stack_size is 0.
|
||||
* This function creates a new thread. If the underlying thread
|
||||
* implementation supports it, the thread gets a stack size of
|
||||
* @stack_size or the default value for the current platform, if
|
||||
* @stack_size is 0.
|
||||
*
|
||||
* If @joinable is %TRUE, you can wait for this threads termination
|
||||
* calling g_thread_join(). Otherwise the thread will just disappear
|
||||
@ -1752,13 +1746,6 @@ g_thread_create_proxy (gpointer data)
|
||||
* @error can be %NULL to ignore errors, or non-%NULL to report errors.
|
||||
* The error is set, if and only if the function returns %NULL.
|
||||
*
|
||||
* <note><para>It is not guaranteed that threads with different priorities
|
||||
* really behave accordingly. On some systems (e.g. Linux) there are no
|
||||
* thread priorities. On other systems (e.g. Solaris) there doesn't
|
||||
* seem to be different scheduling for different priorities. All in all
|
||||
* try to avoid being dependent on priorities. Use
|
||||
* %G_THREAD_PRIORITY_NORMAL here as a default.</para></note>
|
||||
*
|
||||
* <note><para>Only use g_thread_create_full() if you really can't use
|
||||
* g_thread_create() instead. g_thread_create() does not take
|
||||
* @stack_size, @bound, and @priority as arguments, as they should only
|
||||
@ -1776,19 +1763,16 @@ g_thread_create_full (GThreadFunc func,
|
||||
GRealThread* result;
|
||||
GError *local_error = NULL;
|
||||
g_return_val_if_fail (func, NULL);
|
||||
g_return_val_if_fail (priority >= G_THREAD_PRIORITY_LOW, NULL);
|
||||
g_return_val_if_fail (priority <= G_THREAD_PRIORITY_URGENT, NULL);
|
||||
|
||||
result = g_new0 (GRealThread, 1);
|
||||
|
||||
result->thread.joinable = joinable;
|
||||
result->thread.priority = priority;
|
||||
result->thread.func = func;
|
||||
result->thread.data = data;
|
||||
result->private_data = NULL;
|
||||
G_LOCK (g_thread);
|
||||
G_THREAD_UF (thread_create, (g_thread_create_proxy, result,
|
||||
stack_size, joinable, bound, priority,
|
||||
stack_size, joinable, bound, 0,
|
||||
&result->system_thread, &local_error));
|
||||
if (!local_error)
|
||||
{
|
||||
@ -1894,31 +1878,16 @@ g_thread_join (GThread* thread)
|
||||
/**
|
||||
* g_thread_set_priority:
|
||||
* @thread: a #GThread.
|
||||
* @priority: a new priority for @thread.
|
||||
* @priority: ignored
|
||||
*
|
||||
* Changes the priority of @thread to @priority.
|
||||
* This function does nothing.
|
||||
*
|
||||
* <note><para>It is not guaranteed that threads with different
|
||||
* priorities really behave accordingly. On some systems (e.g. Linux)
|
||||
* there are no thread priorities. On other systems (e.g. Solaris) there
|
||||
* doesn't seem to be different scheduling for different priorities. All
|
||||
* in all try to avoid being dependent on priorities.</para></note>
|
||||
* Deprecated:2.32: Thread priorities no longer have any effect.
|
||||
**/
|
||||
void
|
||||
g_thread_set_priority (GThread* thread,
|
||||
GThreadPriority priority)
|
||||
g_thread_set_priority (GThread *thread,
|
||||
GThreadPriority priority)
|
||||
{
|
||||
GRealThread* real = (GRealThread*) thread;
|
||||
|
||||
g_return_if_fail (thread);
|
||||
g_return_if_fail (!g_system_thread_equal (&real->system_thread, &zero_thread));
|
||||
g_return_if_fail (priority >= G_THREAD_PRIORITY_LOW);
|
||||
g_return_if_fail (priority <= G_THREAD_PRIORITY_URGENT);
|
||||
|
||||
thread->priority = priority;
|
||||
|
||||
G_THREAD_CF (thread_set_priority, (void)0,
|
||||
(&real->system_thread, priority));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1940,8 +1909,6 @@ g_thread_self (void)
|
||||
created by GLib. */
|
||||
thread = g_new0 (GRealThread, 1);
|
||||
thread->thread.joinable = FALSE; /* This is a save guess */
|
||||
thread->thread.priority = G_THREAD_PRIORITY_NORMAL; /* This is
|
||||
just a guess */
|
||||
thread->thread.func = NULL;
|
||||
thread->thread.data = NULL;
|
||||
thread->private_data = NULL;
|
||||
|
@ -50,6 +50,9 @@ typedef enum
|
||||
|
||||
typedef gpointer (*GThreadFunc) (gpointer data);
|
||||
|
||||
/* This is "deprecated", but we can't actually remove it since
|
||||
* g_thread_create_full takes it.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
G_THREAD_PRIORITY_LOW,
|
||||
@ -188,9 +191,8 @@ GMutex* g_static_mutex_get_mutex_impl (GMutex **mutex);
|
||||
#define g_thread_supported() (g_threads_got_initialized)
|
||||
#endif
|
||||
|
||||
#define g_thread_create(func, data, joinable, error) \
|
||||
(g_thread_create_full (func, data, 0, joinable, FALSE, \
|
||||
G_THREAD_PRIORITY_NORMAL, error))
|
||||
#define g_thread_create(func, data, joinable, error) \
|
||||
(g_thread_create_full (func, data, 0, joinable, FALSE, 0, error))
|
||||
|
||||
GThread* g_thread_create_full (GThreadFunc func,
|
||||
gpointer data,
|
||||
@ -204,8 +206,10 @@ void g_thread_exit (gpointer retval);
|
||||
gpointer g_thread_join (GThread *thread);
|
||||
void g_thread_yield (void);
|
||||
|
||||
#ifndef G_DISABLE_DEPRECATED
|
||||
void g_thread_set_priority (GThread *thread,
|
||||
GThreadPriority priority);
|
||||
#endif
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
typedef GMutex * GStaticMutex;
|
||||
|
Loading…
Reference in New Issue
Block a user