#include "glib.h"
#include "gthreadprivate.h"
-static gint g_thread_priority_map [G_THREAD_PRIORITY_URGENT + 1];
-
#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 * 6 + PRIORITY_URGENT_VALUE * 4) / 10)
-#endif /* PRIORITY_NORMAL_VALUE */
-
-#ifndef PRIORITY_HIGH_VALUE
-# define PRIORITY_HIGH_VALUE \
- ((PRIORITY_NORMAL_VALUE + PRIORITY_URGENT_VALUE * 2) / 3)
-#endif /* PRIORITY_HIGH_VALUE */
-
void
g_thread_init (GThreadFunctions *init)
{
#endif /* HAVE_G_THREAD_IMPL_INIT */
g_thread_functions_for_glib_use = g_thread_functions_for_glib_use_default;
-
- 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;
-
g_thread_init_glib ();
}
# 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;
{
struct sched_param sched;
posix_check_cmd (pthread_attr_getschedparam (&attr, &sched));
- sched.sched_priority = g_thread_priority_map [priority];
+ sched.sched_priority = g_thread_priority_map (priority);
posix_check_cmd_prio (pthread_attr_setschedparam (&attr, &sched));
}
#endif /* HAVE_PRIORITIES */
int policy;
posix_check_cmd (pthread_getschedparam (*(pthread_t*)thread, &policy,
&sched));
- sched.sched_priority = g_thread_priority_map [priority];
+ sched.sched_priority = g_thread_priority_map (priority);
posix_check_cmd_prio (pthread_setschedparam (*(pthread_t*)thread, policy,
&sched));
}
#define G_MUTEX_SIZE (sizeof (gpointer))
-#define PRIORITY_LOW_VALUE THREAD_PRIORITY_BELOW_NORMAL
-#define PRIORITY_NORMAL_VALUE THREAD_PRIORITY_NORMAL
-#define PRIORITY_HIGH_VALUE THREAD_PRIORITY_ABOVE_NORMAL
-#define PRIORITY_URGENT_VALUE THREAD_PRIORITY_HIGHEST
-
static DWORD g_thread_self_tls;
static DWORD g_private_tls;
static DWORD g_cond_event_tls;
g_thread_set_priority_win32_impl (gpointer thread, GThreadPriority priority)
{
GThreadData *target = *(GThreadData **)thread;
+ gint native_prio;
- g_return_if_fail (priority >= G_THREAD_PRIORITY_LOW);
- g_return_if_fail (priority <= G_THREAD_PRIORITY_URGENT);
+ 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,
- g_thread_priority_map [priority]));
+ win32_check_for_error (SetThreadPriority (target->thread, native_prio));
}
static void