+ else
+ {
+#ifdef _POSIX_PRIORITY_SCHEDULING
+#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
+ pthread_t thread_id = pthread_self ();
+ int policy;
+ struct sched_param params;
+ int priority_min, priority_max;
+
+ if (pthread_getschedparam (thread_id, &policy, ¶ms) == 0)
+ {
+ if ((priority_max = sched_get_priority_max (policy)) == -1)
+ return -1;
+
+ if ((priority_min = sched_get_priority_min (policy)) == -1)
+ return -1;
+
+ if (priority > priority_max)
+ priority = priority_max;
+ else if (priority < priority_min)
+ priority = priority_min;
+ params.sched_priority = priority;
+
+ /*
+ * The solaris 7 and several other man pages incorrectly state that
+ * this should be a pointer to policy but pthread.h is universally
+ * at odds with this.
+ */
+ if (pthread_setschedparam (thread_id, policy, ¶ms) == 0)
+ return 0;
+ }
+#endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
+#endif /* _POSIX_PRIORITY_SCHEDULING */
+ return -1;
+ }