int ACE_Sched_Params::previous_priority (const Policy policy, const int priority, const int scope) { #if defined (ACE_HAS_WTHREADS) ACE_UNUSED_ARG (policy); ACE_UNUSED_ARG (scope); switch (priority) { case THREAD_PRIORITY_IDLE: return THREAD_PRIORITY_IDLE; case THREAD_PRIORITY_LOWEST: return THREAD_PRIORITY_IDLE; case THREAD_PRIORITY_BELOW_NORMAL: return THREAD_PRIORITY_LOWEST; case THREAD_PRIORITY_NORMAL: return THREAD_PRIORITY_BELOW_NORMAL; case THREAD_PRIORITY_ABOVE_NORMAL: return THREAD_PRIORITY_NORMAL; case THREAD_PRIORITY_HIGHEST: return THREAD_PRIORITY_ABOVE_NORMAL; case THREAD_PRIORITY_TIME_CRITICAL: return THREAD_PRIORITY_HIGHEST; default: return priority; // unknown priority: should never get here } #elif defined(ACE_HAS_THREADS) && \ (!defined(ACE_LACKS_SETSCHED) || defined (ACE_TANDEM_T1248_PTHREADS) || \ defined (ACE_HAS_PTHREAD_SCHEDPARAM)) // including STHREADS and PTHREADS int const min = priority_min (policy, scope); return priority > min ? priority - 1 : min; #elif defined (ACE_VXWORKS) return priority < priority_min (policy, scope) ? priority + 1 : priority_min (policy, scope); #else ACE_UNUSED_ARG (policy); ACE_UNUSED_ARG (scope); ACE_UNUSED_ARG (priority); ACE_NOTSUP_RETURN (-1); #endif /* ACE_HAS_THREADS */ }
int pthread_barrier_wait(pthread_barrier_t *barrier) { /* Idea: the count is decreased by every thread that waits on the barrier. * If the value is bigger than zero afterwards, then the thread has to wait * to be woken up. Once the value reaches zero, everyone gets woken up. */ mutex_lock(&barrier->mutex); DEBUG("%s: hit a synchronization barrier. pid=%" PRIkernel_pid"\n", sched_active_thread->name, sched_active_pid); int switch_prio = -1; if (--barrier->count > 0) { /* need to wait for further threads */ DEBUG("%s: waiting for %u threads. pid=%" PRIkernel_pid "\n", sched_active_thread->name, barrier->count, sched_active_pid); pthread_barrier_waiting_node_t node; node.pid = sched_active_pid; node.next = barrier->next; node.cont = 0; barrier->next = &node; mutex_unlock(&barrier->mutex); while (1) { /* The mutex is reacquired before checking if we should continue, * so that the waiting thread don't accidentially run before the * wake up loop has ended. Otherwise the thread could run into the * the barrier again before `barrier->count` was reset. */ mutex_lock(&barrier->mutex); if (node.cont) { break; } mutex_unlock_and_sleep(&barrier->mutex); } } else { /* all threads have arrived, wake everybody up */ DEBUG("%s: waking every other thread up. pid=%" PRIkernel_pid "\n", sched_active_thread->name, sched_active_pid); int count = 1; /* Count number of woken up threads. * The first thread is the current thread. */ pthread_barrier_waiting_node_t *next; for (next = barrier->next; next; next = next->next) { ++count; next->cont = 1; thread_t *other = (thread_t *) sched_threads[next->pid]; switch_prio = priority_min(switch_prio, other->priority); sched_set_status(other, STATUS_PENDING); } barrier->next = NULL; barrier->count = count; } mutex_unlock(&barrier->mutex); if (switch_prio != -1) { sched_switch(switch_prio); } return 0; }