#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))
#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
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));
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));
}
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)
{
*(pthread_t*)thread = pthread_self();
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,
};
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)
{
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;
}
*(GThreadData **)thread = retval;
-
- g_thread_set_priority_win32_impl (thread, priority);
}
void
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
};
* @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,
* @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
* @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
* @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
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)
{
/**
* 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));
}
/**
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;
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,
#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,
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;