Merge pull request #1562 from Kijewski/the-first-two-commits-of-the-branch-issue-198

posix: minor pthread_barrier clean up
dev/timer
René Kijewski 9 years ago
commit 89a26b7331

@ -40,6 +40,14 @@ int pthread_barrier_destroy(pthread_barrier_t *barrier)
return 0;
}
static inline int priority_min(int a, int b)
{
if (a == -1) {
return b;
}
return a < b ? a : b;
}
int pthread_barrier_wait(pthread_barrier_t *barrier)
{
/* Idea: the count is decreased by every thread that waits on the barrier.
@ -50,6 +58,8 @@ int pthread_barrier_wait(pthread_barrier_t *barrier)
DEBUG("%s: hit a synchronization barrier. pid=%" PRIkernel_pid"\n",
sched_active_thread->name, sched_active_thread->pid);
int switch_prio = -1;
if (--barrier->count > 0) {
/* need to wait for further threads */
@ -87,14 +97,21 @@ int pthread_barrier_wait(pthread_barrier_t *barrier)
pthread_barrier_waiting_node_t *next;
for (next = barrier->next; next; next = next->next) {
++count;
next->cont = 1;
sched_set_status((tcb_t *) sched_threads[next->pid], STATUS_PENDING);
tcb_t *other = (tcb_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;
}

@ -5,17 +5,9 @@ include ../Makefile.tests_common
# exclude boards with insufficient RAM
BOARD_INSUFFICIENT_RAM := stm32f0discovery
## Modules to include.
# Modules to include.
USEMODULE += pthread
USEMODULE += random
USEMODULE += vtimer
CFLAGS += -isystem $(RIOTBASE)/sys/posix/pthread/include
CFLAGS += -isystem $(RIOTBASE)/sys/posix/include
INCLUDES += -I$(RIOTBASE)/sys/posix/pthread/include
INCLUDES += -I$(RIOTBASE)/sys/posix/include
CFLAGS += -ggdb3 -O0
include $(RIOTBASE)/Makefile.include

Loading…
Cancel
Save