Browse Source

core: prefix API functions correctly

Also changed names for bitarithm functions and rename thread_pid to sched_active_pid.
dev/timer
Oleg Hahm 9 years ago
parent
commit
ef5ec344fd
  1. 6
      boards/avsextrem/drivers/avsextrem-smb380.c
  2. 9
      core/bitarithm.c
  3. 6
      core/include/bitarithm.h
  4. 4
      core/include/debug.h
  5. 6
      core/include/sched.h
  6. 2
      core/include/thread.h
  7. 52
      core/msg.c
  8. 27
      core/mutex.c
  9. 70
      core/sched.c
  10. 13
      core/thread.c
  11. 2
      cpu/arm_common/arm_cpu.c
  12. 16
      cpu/arm_common/common.s
  13. 2
      cpu/arm_common/syscalls.c
  14. 2
      cpu/cc430/cc430-gpioint.c
  15. 8
      cpu/cortexm_common/thread_arch.c
  16. 14
      cpu/lpc1768/atom.c
  17. 4
      cpu/lpc1768/cpu.c
  18. 2
      cpu/lpc1768/syscalls.c
  19. 2
      cpu/lpc2387/gpioint/lpc2387-gpioint.c
  20. 4
      cpu/msp430-common/cpu.c
  21. 4
      cpu/msp430-common/include/cpu.h
  22. 8
      cpu/native/irq_cpu.c
  23. 16
      cpu/native/native_cpu.c
  24. 6
      cpu/native/syscalls.c
  25. 2
      cpu/sam3x8e/syscalls.c
  26. 4
      drivers/cc110x/cc1100_phy.c
  27. 2
      sys/net/ccn_lite/ccn-lite-relay.c
  28. 6
      sys/posix/pthread/pthread.c
  29. 8
      sys/posix/pthread/pthread_barrier.c
  30. 10
      sys/posix/pthread/pthread_cond.c
  31. 10
      sys/posix/pthread/pthread_rwlock.c
  32. 14
      sys/posix/semaphore.c
  33. 4
      sys/ps/ps.c
  34. 2
      sys/vtimer/vtimer.c
  35. 2
      tests/test_pthread_rwlock/main.c
  36. 8
      tests/test_queue_fairness/main.c
  37. 2
      tests/test_thread_msg_block_w_queue/main.c
  38. 2
      tests/test_thread_msg_block_wo_queue/main.c
  39. 60
      tests/unittests/tests-core/tests-core-bitarithm.c

6
boards/avsextrem/drivers/avsextrem-smb380.c

@ -173,7 +173,7 @@ uint8_t SMB380_init_simple(uint16_t samplerate, uint8_t bandwidth, uint8_t
{
SSP0Init();
interruptTicksSMB380 = 0;
simple_pid = active_thread->pid;
simple_pid = sched_active_thread->pid;
gpioint_set(0, BIT1, GPIOINT_RISING_EDGE, &SMB380_simple_interrupthandler);
SMB380_softReset();
hwtimer_wait(HWTIMER_TICKS(100000));
@ -305,7 +305,7 @@ uint8_t getRingReadPointerforCurrentThread(void)
{
uint8_t pointerNo = 0;
while ((PointerList[pointerNo] != active_thread->pid) &&
while ((PointerList[pointerNo] != sched_active_thread->pid) &&
(pointerNo < SMB380_RING_BUFF_MAX_THREADS)) {
pointerNo++;
}
@ -327,7 +327,7 @@ uint8_t initRingReadPointerforCurrentThread(void)
return 0;
}
else {
PointerList[pointerNo] = active_thread->pid;
PointerList[pointerNo] = sched_active_thread->pid;
readPointerPos[pointerNo] = settings.writePointerPos;
return 1;
}

9
core/bitarithm.c

@ -21,8 +21,7 @@
#include <stdio.h>
unsigned
number_of_highest_bit(unsigned v)
unsigned bitarithm_msb(unsigned v)
{
register unsigned r; // result of log2(v) will go here
@ -45,8 +44,7 @@ number_of_highest_bit(unsigned v)
return r;
}
/*---------------------------------------------------------------------------*/
unsigned
number_of_lowest_bit(register unsigned v)
unsigned bitarithm_lsb(register unsigned v)
{
register unsigned r = 0;
@ -58,8 +56,7 @@ number_of_lowest_bit(register unsigned v)
return r;
}
/*---------------------------------------------------------------------------*/
unsigned
number_of_bits_set(unsigned v)
unsigned bitarithm_bits_set(unsigned v)
{
unsigned c; // c accumulates the total bits set in v

6
core/include/bitarithm.h

@ -94,7 +94,7 @@
*
* Source: http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious
*/
unsigned number_of_highest_bit(unsigned v);
unsigned bitarithm_msb(unsigned v);
/**
* @brief Returns the number of the lowest '1' bit in a value
@ -104,7 +104,7 @@ unsigned number_of_highest_bit(unsigned v);
*
* Source: http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious
*/
unsigned number_of_lowest_bit(register unsigned v);
unsigned bitarithm_lsb(register unsigned v);
/**
* @brief Returns the number of bits set in a value
@ -113,7 +113,7 @@ unsigned number_of_lowest_bit(register unsigned v);
*
* Source: http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious
*/
unsigned number_of_bits_set(unsigned v);
unsigned bitarithm_bits_set(unsigned v);
#endif /* BITARITHM_H_ */
/** @} */

4
core/include/debug.h

@ -39,7 +39,7 @@
#include "cpu-conf.h"
#define DEBUG_PRINT(...) \
do { \
if ((active_thread == NULL) || (active_thread->stack_size > KERNEL_CONF_STACKSIZE_PRINTF)) { \
if ((sched_active_thread == NULL) || (sched_active_thread->stack_size > KERNEL_CONF_STACKSIZE_PRINTF)) { \
printf(__VA_ARGS__); \
} \
else { \
@ -70,7 +70,7 @@
#define DEBUGF(...) \
do { \
DEBUG_PRINT("DEBUG(%s): %s:%d in %s: ", \
active_thread ? active_thread->name : "NO THREAD", \
sched_active_thread ? sched_active_thread->name : "NO THREAD", \
__FILE__, __LINE__, __func__); \
DEBUG_PRINT(__VA_ARGS__); \
} while (0)

6
core/include/sched.h

@ -82,17 +82,17 @@ extern volatile tcb_t *sched_threads[MAXTHREADS];
/**
* Currently active thread
*/
extern volatile tcb_t *active_thread;
extern volatile tcb_t *sched_active_thread;
/**
* Number of running (non-terminated) threads
*/
extern volatile int num_tasks;
extern volatile int sched_num_threads;
/**
* Process ID of active thread
*/
extern volatile int thread_pid;
extern volatile int sched_active_pid;
/**
* Process ID of the thread that was active before the current one

2
core/include/thread.h

@ -142,7 +142,7 @@ int thread_getlastpid(void);
*
* Only works if the thread was created with the flag CREATE_STACKTEST.
*
* @param[in] stack the stack you want to measure. try `active_thread->stack_start`
* @param[in] stack the stack you want to measure. try `sched_active_thread->stack_start`
*
* @return the amount of unused space of the thread's stack
*/

52
core/msg.c

@ -60,7 +60,7 @@ int msg_send(msg_t *m, unsigned int target_pid, bool block)
tcb_t *target = (tcb_t*) sched_threads[target_pid];
m->sender_pid = thread_pid;
m->sender_pid = sched_active_pid;
if (m->sender_pid == target_pid) {
return msg_send_to_self(m);
@ -72,51 +72,51 @@ int msg_send(msg_t *m, unsigned int target_pid, bool block)
dINT();
DEBUG("msg_send() %s:%i: Sending from %i to %i. block=%i src->state=%i target->state=%i\n", __FILE__, __LINE__, thread_pid, target_pid, block, active_thread->status, target->status);
DEBUG("msg_send() %s:%i: Sending from %i to %i. block=%i src->state=%i target->state=%i\n", __FILE__, __LINE__, sched_active_pid, target_pid, block, sched_active_thread->status, target->status);
if (target->status != STATUS_RECEIVE_BLOCKED) {
DEBUG("msg_send() %s:%i: Target %i is not RECEIVE_BLOCKED.\n", __FILE__, __LINE__, target_pid);
if (target->msg_array && queue_msg(target, m)) {
DEBUG("msg_send() %s:%i: Target %i has a msg_queue. Queueing message.\n", __FILE__, __LINE__, target_pid);
eINT();
if (active_thread->status == STATUS_REPLY_BLOCKED) {
if (sched_active_thread->status == STATUS_REPLY_BLOCKED) {
thread_yield();
}
return 1;
}
if (!block) {
DEBUG("msg_send: %s: Receiver not waiting, block=%u\n", active_thread->name, block);
DEBUG("msg_send: %s: Receiver not waiting, block=%u\n", sched_active_thread->name, block);
eINT();
return 0;
}
DEBUG("msg_send: %s: send_blocked.\n", active_thread->name);
DEBUG("msg_send: %s: send_blocked.\n", sched_active_thread->name);
queue_node_t n;
n.priority = active_thread->priority;
n.data = (unsigned int) active_thread;
n.priority = sched_active_thread->priority;
n.data = (unsigned int) sched_active_thread;
n.next = NULL;
DEBUG("msg_send: %s: Adding node to msg_waiters:\n", active_thread->name);
DEBUG("msg_send: %s: Adding node to msg_waiters:\n", sched_active_thread->name);
queue_priority_add(&(target->msg_waiters), &n);
active_thread->wait_data = (void*) m;
sched_active_thread->wait_data = (void*) m;
int newstatus;
if (active_thread->status == STATUS_REPLY_BLOCKED) {
if (sched_active_thread->status == STATUS_REPLY_BLOCKED) {
newstatus = STATUS_REPLY_BLOCKED;
}
else {
newstatus = STATUS_SEND_BLOCKED;
}
sched_set_status((tcb_t*) active_thread, newstatus);
sched_set_status((tcb_t*) sched_active_thread, newstatus);
DEBUG("msg_send: %s: Back from send block.\n", active_thread->name);
DEBUG("msg_send: %s: Back from send block.\n", sched_active_thread->name);
}
else {
DEBUG("msg_send: %s: Direct msg copy from %i to %i.\n", active_thread->name, thread_getpid(), target_pid);
DEBUG("msg_send: %s: Direct msg copy from %i to %i.\n", sched_active_thread->name, thread_getpid(), target_pid);
/* copy msg to target */
msg_t *target_message = (msg_t*) target->wait_data;
*target_message = *m;
@ -133,7 +133,7 @@ int msg_send_to_self(msg_t *m)
{
unsigned int state = disableIRQ();
int res = queue_msg((tcb_t *) active_thread, m);
int res = queue_msg((tcb_t *) sched_active_thread, m);
restoreIRQ(state);
return res;
@ -165,7 +165,7 @@ int msg_send_int(msg_t *m, unsigned int target_pid)
int msg_send_receive(msg_t *m, msg_t *reply, unsigned int target_pid)
{
dINT();
tcb_t *me = (tcb_t*) sched_threads[thread_pid];
tcb_t *me = (tcb_t*) sched_threads[sched_active_pid];
sched_set_status(me, STATUS_REPLY_BLOCKED);
me->wait_data = (void*) reply;
@ -181,17 +181,17 @@ int msg_reply(msg_t *m, msg_t *reply)
tcb_t *target = (tcb_t*) sched_threads[m->sender_pid];
if (!target) {
DEBUG("msg_reply(): %s: Target \"%" PRIu16 "\" not existing...dropping msg!\n", active_thread->name, m->sender_pid);
DEBUG("msg_reply(): %s: Target \"%" PRIu16 "\" not existing...dropping msg!\n", sched_active_thread->name, m->sender_pid);
return -1;
}
if (target->status != STATUS_REPLY_BLOCKED) {
DEBUG("msg_reply(): %s: Target \"%s\" not waiting for reply.", active_thread->name, target->name);
DEBUG("msg_reply(): %s: Target \"%s\" not waiting for reply.", sched_active_thread->name, target->name);
restoreIRQ(state);
return -1;
}
DEBUG("msg_reply(): %s: Direct msg copy.\n", active_thread->name);
DEBUG("msg_reply(): %s: Direct msg copy.\n", sched_active_thread->name);
/* copy msg to target */
msg_t *target_message = (msg_t*) target->wait_data;
*target_message = *reply;
@ -207,7 +207,7 @@ int msg_reply_int(msg_t *m, msg_t *reply)
tcb_t *target = (tcb_t*) sched_threads[m->sender_pid];
if (target->status != STATUS_REPLY_BLOCKED) {
DEBUG("msg_reply_int(): %s: Target \"%s\" not waiting for reply.", active_thread->name, target->name);
DEBUG("msg_reply_int(): %s: Target \"%s\" not waiting for reply.", sched_active_thread->name, target->name);
return -1;
}
@ -231,9 +231,9 @@ int msg_receive(msg_t *m)
static int _msg_receive(msg_t *m, int block)
{
dINT();
DEBUG("_msg_receive: %s: _msg_receive.\n", active_thread->name);
DEBUG("_msg_receive: %s: _msg_receive.\n", sched_active_thread->name);
tcb_t *me = (tcb_t*) sched_threads[thread_pid];
tcb_t *me = (tcb_t*) sched_threads[sched_active_pid];
int queue_index = -1;
@ -247,7 +247,7 @@ static int _msg_receive(msg_t *m, int block)
}
if (queue_index >= 0) {
DEBUG("_msg_receive: %s: _msg_receive(): We've got a queued message.\n", active_thread->name);
DEBUG("_msg_receive: %s: _msg_receive(): We've got a queued message.\n", sched_active_thread->name);
*m = me->msg_array[queue_index];
}
else {
@ -257,10 +257,10 @@ static int _msg_receive(msg_t *m, int block)
queue_node_t *node = queue_remove_head(&(me->msg_waiters));
if (node == NULL) {
DEBUG("_msg_receive: %s: _msg_receive(): No thread in waiting list.\n", active_thread->name);
DEBUG("_msg_receive: %s: _msg_receive(): No thread in waiting list.\n", sched_active_thread->name);
if (queue_index < 0) {
DEBUG("_msg_receive(): %s: No msg in queue. Going blocked.\n", active_thread->name);
DEBUG("_msg_receive(): %s: No msg in queue. Going blocked.\n", sched_active_thread->name);
sched_set_status(me, STATUS_RECEIVE_BLOCKED);
eINT();
@ -272,7 +272,7 @@ static int _msg_receive(msg_t *m, int block)
return 1;
}
else {
DEBUG("_msg_receive: %s: _msg_receive(): Waking up waiting thread.\n", active_thread->name);
DEBUG("_msg_receive: %s: _msg_receive(): Waking up waiting thread.\n", sched_active_thread->name);
tcb_t *sender = (tcb_t*) node->data;
if (queue_index >= 0) {
@ -301,7 +301,7 @@ int msg_init_queue(msg_t *array, int num)
{
/* check if num is a power of two by comparing to its complement */
if (num && (num & (num - 1)) == 0) {
tcb_t *me = (tcb_t*) active_thread;
tcb_t *me = (tcb_t*) sched_active_thread;
me->msg_array = array;
cib_init(&(me->msg_queue), num);
return 0;

27
core/mutex.c

@ -48,13 +48,13 @@ int mutex_init(struct mutex_t *mutex)
int mutex_trylock(struct mutex_t *mutex)
{
DEBUG("%s: trylocking to get mutex. val: %u\n", active_thread->name, mutex->val);
DEBUG("%s: trylocking to get mutex. val: %u\n", sched_active_thread->name, mutex->val);
return (atomic_set_return(&mutex->val, 1) == 0);
}
int mutex_lock(struct mutex_t *mutex)
{
DEBUG("%s: trying to get mutex. val: %u\n", active_thread->name, mutex->val);
DEBUG("%s: trying to get mutex. val: %u\n", sched_active_thread->name, mutex->val);
if (atomic_set_return(&mutex->val, 1) != 0) {
/* mutex was locked. */
@ -67,24 +67,24 @@ int mutex_lock(struct mutex_t *mutex)
static void mutex_wait(struct mutex_t *mutex)
{
int irqstate = disableIRQ();
DEBUG("%s: Mutex in use. %u\n", active_thread->name, mutex->val);
DEBUG("%s: Mutex in use. %u\n", sched_active_thread->name, mutex->val);
if (mutex->val == 0) {
/* somebody released the mutex. return. */
mutex->val = 1;
DEBUG("%s: mutex_wait early out. %u\n", active_thread->name, mutex->val);
DEBUG("%s: mutex_wait early out. %u\n", sched_active_thread->name, mutex->val);
restoreIRQ(irqstate);
return;
}
sched_set_status((tcb_t *) active_thread, STATUS_MUTEX_BLOCKED);
sched_set_status((tcb_t*) sched_active_thread, STATUS_MUTEX_BLOCKED);
queue_node_t n;
n.priority = (unsigned int) active_thread->priority;
n.data = (unsigned int) active_thread;
n.priority = (unsigned int) sched_active_thread->priority;
n.data = (unsigned int) sched_active_thread;
n.next = NULL;
DEBUG("%s: Adding node to mutex queue: prio: %" PRIu32 "\n", active_thread->name, n.priority);
DEBUG("%s: Adding node to mutex queue: prio: %" PRIu32 "\n", sched_active_thread->name, n.priority);
queue_priority_add(&(mutex->queue), &n);
@ -97,7 +97,7 @@ static void mutex_wait(struct mutex_t *mutex)
void mutex_unlock(struct mutex_t *mutex)
{
DEBUG("%s: unlocking mutex. val: %u pid: %u\n", active_thread->name, mutex->val, thread_pid);
DEBUG("%s: unlocking mutex. val: %u pid: %u\n", sched_active_thread->name, mutex->val, sched_active_pid);
int irqstate = disableIRQ();
if (mutex->val != 0) {
@ -107,7 +107,7 @@ void mutex_unlock(struct mutex_t *mutex)
DEBUG("%s: waking up waiter.\n", process->name);
sched_set_status(process, STATUS_PENDING);
sched_switch(active_thread->priority, process->priority);
sched_switch(sched_active_thread->priority, process->priority);
}
else {
mutex->val = 0;
@ -119,7 +119,7 @@ void mutex_unlock(struct mutex_t *mutex)
void mutex_unlock_and_sleep(struct mutex_t *mutex)
{
DEBUG("%s: unlocking mutex. val: %u pid: %u, and taking a nap\n", active_thread->name, mutex->val, thread_pid);
DEBUG("%s: unlocking mutex. val: %u pid: %u, and taking a nap\n", sched_active_thread->name, mutex->val, sched_active_pid);
int irqstate = disableIRQ();
if (mutex->val != 0) {
@ -133,9 +133,8 @@ void mutex_unlock_and_sleep(struct mutex_t *mutex)
mutex->val = 0;
}
}
DEBUG("%s: going to sleep.\n", active_thread->name);
sched_set_status((tcb_t *) active_thread, STATUS_SLEEPING);
DEBUG("%s: going to sleep.\n", sched_active_thread->name);
sched_set_status((tcb_t*) sched_active_thread, STATUS_SLEEPING);
restoreIRQ(irqstate);
thread_yield();
}

70
core/sched.c

@ -39,29 +39,29 @@
#define ENABLE_DEBUG (0)
#include "debug.h"
volatile int num_tasks = 0;
volatile int sched_num_threads = 0;
volatile unsigned int sched_context_switch_request;
volatile tcb_t *sched_threads[MAXTHREADS];
volatile tcb_t *active_thread;
volatile tcb_t *sched_active_thread;
volatile int thread_pid = -1;
volatile int last_pid = -1;
volatile int sched_active_pid = -1;
volatile int thread_last_pid = -1;
clist_node_t *runqueues[SCHED_PRIO_LEVELS];
clist_node_t *sched_runqueues[SCHED_PRIO_LEVELS];
static uint32_t runqueue_bitcache = 0;
#if SCHEDSTATISTICS
static void (*sched_cb) (uint32_t timestamp, uint32_t value) = NULL;
schedstat pidlist[MAXTHREADS];
schedstat sched_pidlist[MAXTHREADS];
#endif
void sched_run(void)
{
sched_context_switch_request = 0;
tcb_t *my_active_thread = (tcb_t *)active_thread;
tcb_t *my_active_thread = (tcb_t *)sched_active_thread;
if (my_active_thread) {
if (my_active_thread->status == STATUS_RUNNING) {
@ -81,18 +81,18 @@ void sched_run(void)
#ifdef SCHEDSTATISTICS
unsigned long time = hwtimer_now();
if (my_active_thread && (pidlist[my_active_thread->pid].laststart)) {
pidlist[my_active_thread->pid].runtime_ticks += time - pidlist[my_active_thread->pid].laststart;
if (my_active_thread && (sched_pidlist[my_active_thread->pid].laststart)) {
sched_pidlist[my_active_thread->pid].runtime_ticks += time - sched_pidlist[my_active_thread->pid].laststart;
}
#endif
DEBUG("\nscheduler: previous task: %s\n", (my_active_thread == NULL) ? "none" : my_active_thread->name);
if (num_tasks == 0) {
if (sched_num_threads == 0) {
DEBUG("scheduler: no tasks left.\n");
while (!num_tasks) {
while (!sched_num_threads) {
/* loop until a new task arrives */
;
}
@ -103,24 +103,24 @@ void sched_run(void)
my_active_thread = NULL;
while (!my_active_thread) {
int nextrq = number_of_lowest_bit(runqueue_bitcache);
clist_node_t next = *(runqueues[nextrq]);
int nextrq = bitarithm_lsb(runqueue_bitcache);
clist_node_t next = *(sched_runqueues[nextrq]);
DEBUG("scheduler: first in queue: %s\n", ((tcb_t *)next.data)->name);
clist_advance(&(runqueues[nextrq]));
clist_advance(&(sched_runqueues[nextrq]));
my_active_thread = (tcb_t *)next.data;
thread_pid = (volatile int) my_active_thread->pid;
sched_active_pid = (volatile int) my_active_thread->pid;
#if SCHEDSTATISTICS
pidlist[my_active_thread->pid].laststart = time;
pidlist[my_active_thread->pid].schedules++;
if ((sched_cb) && (my_active_thread->pid != last_pid)) {
sched_pidlist[my_active_thread->pid].laststart = time;
sched_pidlist[my_active_thread->pid].schedules++;
if ((sched_cb) && (my_active_thread->pid != thread_last_pid)) {
sched_cb(hwtimer_now(), my_active_thread->pid);
last_pid = my_active_thread->pid;
thread_last_pid = my_active_thread->pid;
}
#endif
#ifdef MODULE_NSS
if (active_thread && active_thread->pid != last_pid) {
last_pid = active_thread->pid;
if (sched_active_thread && sched_active_thread->pid != thread_last_pid) {
thread_last_pid = sched_active_thread->pid;
}
#endif
@ -128,17 +128,17 @@ void sched_run(void)
DEBUG("scheduler: next task: %s\n", my_active_thread->name);
if (my_active_thread != active_thread) {
if (active_thread != NULL) { /* TODO: necessary? */
if (active_thread->status == STATUS_RUNNING) {
active_thread->status = STATUS_PENDING ;
if (my_active_thread != sched_active_thread) {
if (sched_active_thread != NULL) { /* TODO: necessary? */
if (sched_active_thread->status == STATUS_RUNNING) {
sched_active_thread->status = STATUS_PENDING ;
}
}
sched_set_status((tcb_t *)my_active_thread, STATUS_RUNNING);
}
active_thread = (volatile tcb_t *) my_active_thread;
sched_active_thread = (volatile tcb_t *) my_active_thread;
DEBUG("scheduler: done.\n");
}
@ -155,16 +155,16 @@ void sched_set_status(tcb_t *process, unsigned int status)
if (status >= STATUS_ON_RUNQUEUE) {
if (!(process->status >= STATUS_ON_RUNQUEUE)) {
DEBUG("adding process %s to runqueue %u.\n", process->name, process->priority);
clist_add(&runqueues[process->priority], &(process->rq_entry));
clist_add(&sched_runqueues[process->priority], &(process->rq_entry));
runqueue_bitcache |= 1 << process->priority;
}
}
else {
if (process->status >= STATUS_ON_RUNQUEUE) {
DEBUG("removing process %s from runqueue %u.\n", process->name, process->priority);
clist_remove(&runqueues[process->priority], &(process->rq_entry));
clist_remove(&sched_runqueues[process->priority], &(process->rq_entry));
if (!runqueues[process->priority]) {
if (!sched_runqueues[process->priority]) {
runqueue_bitcache &= ~(1 << process->priority);
}
}
@ -177,7 +177,7 @@ void sched_switch(uint16_t current_prio, uint16_t other_prio)
{
int in_isr = inISR();
DEBUG("%s: %i %i %i\n", active_thread->name, (int)current_prio, (int)other_prio, in_isr);
DEBUG("%s: %i %i %i\n", sched_active_thread->name, (int)current_prio, (int)other_prio, in_isr);
if (current_prio >= other_prio) {
if (in_isr) {
@ -191,14 +191,14 @@ void sched_switch(uint16_t current_prio, uint16_t other_prio)
NORETURN void sched_task_exit(void)
{
DEBUG("sched_task_exit(): ending task %s...\n", active_thread->name);
DEBUG("sched_task_exit(): ending task %s...\n", sched_active_thread->name);
dINT();
sched_threads[active_thread->pid] = NULL;
num_tasks--;
sched_threads[sched_active_thread->pid] = NULL;
sched_num_threads--;
sched_set_status((tcb_t *)active_thread, STATUS_STOPPED);
sched_set_status((tcb_t *)sched_active_thread, STATUS_STOPPED);
active_thread = NULL;
sched_active_thread = NULL;
cpu_switch_context_exit();
}

13
core/thread.c

@ -34,12 +34,13 @@
inline int thread_getpid(void)
{
return active_thread->pid;
return sched_active_thread->pid;
}
int thread_getlastpid(void)
{
return last_pid;
extern int thread_last_pid;
return thread_last_pid;
}
int thread_getstatus(int pid)
@ -67,7 +68,7 @@ void thread_sleep(void)
}
dINT();
sched_set_status((tcb_t *)active_thread, STATUS_SLEEPING);
sched_set_status((tcb_t *)sched_active_thread, STATUS_SLEEPING);
eINT();
thread_yield();
}
@ -85,7 +86,7 @@ int thread_wakeup(int pid)
sched_set_status(other_thread, STATUS_RUNNING);
restoreIRQ(old_state);
sched_switch(active_thread->priority, other_thread->priority);
sched_switch(sched_active_thread->priority, other_thread->priority);
return 1;
}
@ -199,7 +200,7 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void (*f
cib_init(&(cb->msg_queue), 0);
cb->msg_array = NULL;
num_tasks++;
sched_num_threads++;
DEBUG("Created thread %s. PID: %u. Priority: %u.\n", name, cb->pid, priority);
@ -220,7 +221,7 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void (*f
}
}
if (!inISR() && active_thread != NULL) {
if (!inISR() && sched_active_thread != NULL) {
eINT();
}

2
cpu/arm_common/arm_cpu.c

@ -73,7 +73,7 @@ void thread_print_stack(void)
asm("mov %0, sp" : "=r"(stack));
register unsigned int *s = (unsigned int *)stack;
printf("task: %X SP: %X\n", (unsigned int) active_thread, (unsigned int) stack);
printf("task: %X SP: %X\n", (unsigned int) sched_active_thread, (unsigned int) stack);
register int i = 0;
s += 5;

16
cpu/arm_common/common.s

@ -22,7 +22,7 @@
/* External references */
.extern active_thread
.extern sched_active_thread
.extern sched_context_switch_request
.extern sched_run
.extern DEBUG_Routine
@ -79,15 +79,15 @@ ctx_switch2:
/* store return address and spsr on user mode stack */
stmfd lr!, {r0, r1}
/* save user mode stack pointer in *active_thread */
ldr r1, =active_thread /* r1 = &active_thread */
ldr r1, [r1] /* r1 = *r1 = active_thread */
/* save user mode stack pointer in *sched_active_thread */
ldr r1, =sched_active_thread /* r1 = &sched_active_thread */
ldr r1, [r1] /* r1 = *r1 = sched_active_thread */
str lr, [r1] /* store stack pointer in tasks tcb*/
/* now the calling task has all its registers saved on its stack and it's SP is saved in its tcb */
/* call scheduler so active_thread points to the next task */
/* call scheduler so sched_active_thread points to the next task */
bl sched_run
b task_return
/* never coming back */
@ -96,15 +96,15 @@ cpu_switch_context_exit:
mov r0, #NOINT|SVCMODE
msr cpsr, r0
/* call scheduler so active_thread points to the next task */
/* call scheduler so sched_active_thread points to the next task */
bl sched_run
/* continue in task_return: */
task_return:
/* load tcb->stackpointer in r0 */
ldr r0, =active_thread /* r0 = &active_thread */
ldr r0, [r0] /* r0 = *r0 = active_thread */
ldr r0, =sched_active_thread /* r0 = &sched_active_thread */
ldr r0, [r0] /* r0 = *r0 = sched_active_thread */
ldr r0, [r0]
/* restore saved spsr and return address from tasks stack */

2
cpu/arm_common/syscalls.c

@ -265,7 +265,7 @@ void _exit(int n)
/*---------------------------------------------------------------------------*/
int _getpid(void)
{
return active_thread->pid;
return sched_active_thread->pid;
}
/*---------------------------------------------------------------------------*/
int _kill_r(struct _reent *r, int pid, int sig)

2
cpu/cc430/cc430-gpioint.c

@ -68,7 +68,7 @@ bool gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback)
if ((port >= PORTINT_MIN) && (port <= PORTINT_MAX)) {
/* set the callback function */
base = number_of_highest_bit(bitmask);
base = bitarithm_msb(bitmask);
if (base >= 0) {
cb[port - PORTINT_MIN][base] = callback;

8
cpu/cortexm_common/thread_arch.c

@ -143,8 +143,8 @@ void enter_thread_mode(void)
__set_CONTROL(mode.w);
/* load pdc->stackpointer in r0 */
asm("ldr r0, =active_thread" ); /* r0 = &active_thread */
asm("ldr r0, [r0]" ); /* r0 = *r0 = active_thread */
asm("ldr r0, =sched_active_thread" ); /* r0 = &sched_active_thread */
asm("ldr r0, [r0]" ); /* r0 = *r0 = sched_active_thread */
asm("ldr sp, [r0]" ); /* sp = r0 restore stack pointer*/
asm("pop {r4}" ); /* skip exception return */
asm("pop {r4-r11}" );
@ -189,14 +189,14 @@ __attribute__((always_inline)) static __INLINE void context_save(void)
asm("stmdb r0!,{r4-r11}" ); /* save regs */
asm("stmdb r0!,{lr}" ); /* exception return value */
/* asm("vstmdb sp!, {s16-s31}" ); */ /* TODO save FPU registers if needed */
asm("ldr r1, =active_thread" ); /* load address of current tcb */
asm("ldr r1, =sched_active_thread" ); /* load address of current tcb */
asm("ldr r1, [r1]" ); /* dereference pdc */
asm("str r0, [r1]" ); /* write r0 to pdc->sp means current threads stack pointer */
}
__attribute__((always_inline)) static __INLINE void context_restore(void)
{
asm("ldr r0, =active_thread" ); /* load address of current TCB */
asm("ldr r0, =sched_active_thread" ); /* load address of current TCB */
asm("ldr r0, [r0]" ); /* dereference TCB */
asm("ldr r1, [r0]" ); /* load tcb->sp to register 1 */
asm("ldmia r1!, {r0}" ); /* restore exception return value from stack */

14
cpu/lpc1768/atom.c

@ -48,7 +48,7 @@ void SVC_Handler(void)
{
save_context();
asm("bl sched_run");
/* call scheduler update active_thread variable with pdc of next thread
/* call scheduler update sched_active_thread variable with pdc of next thread
* the thread that has higest priority and is in PENDING state */
restore_context();
}
@ -70,19 +70,19 @@ void ctx_switch(void)
asm("mov r12, sp");
asm("stmfd r12!, {r4-r11}");
/* save user mode stack pointer in *active_thread */
asm("ldr r1, =active_thread"); /* r1 = &active_thread */
asm("ldr r1, [r1]"); /* r1 = *r1 = active_thread */
/* save user mode stack pointer in *sched_active_thread */
asm("ldr r1, =sched_active_thread"); /* r1 = &sched_active_thread */
asm("ldr r1, [r1]"); /* r1 = *r1 = sched_active_thread */
asm("str r12, [r1]"); /* store stack pointer in tasks pdc*/
sched_task_return();
}
/* call scheduler so active_thread points to the next task */
/* call scheduler so sched_active_thread points to the next task */
NORETURN void sched_task_return(void)
{
/* load pdc->stackpointer in r0 */
asm("ldr r0, =active_thread"); /* r0 = &active_thread */
asm("ldr r0, [r0]"); /* r0 = *r0 = active_thread */
asm("ldr r0, =sched_active_thread"); /* r0 = &sched_active_thread */
asm("ldr r0, [r0]"); /* r0 = *r0 = sched_active_thread */
asm("ldr sp, [r0]"); /* sp = r0 restore stack pointer*/
asm("pop {r4}"); /* skip exception return */
asm(" pop {r4-r11}");

4
cpu/lpc1768/cpu.c

@ -89,7 +89,7 @@ void save_context(void)
asm("push {LR}");
/* save exception return value */
asm("ldr r1, =active_thread");
asm("ldr r1, =sched_active_thread");
/* load address of currend pdc */
asm("ldr r1, [r1]");
/* deref pdc */
@ -99,7 +99,7 @@ void save_context(void)
void restore_context(void)
{
asm("ldr r0, =active_thread");
asm("ldr r0, =sched_active_thread");
/* load address of currend pdc */
asm("ldr r0, [r0]");
/* deref pdc */

2
cpu/lpc1768/syscalls.c

@ -221,7 +221,7 @@ void _exit(int n)
/*---------------------------------------------------------------------------*/
int _getpid(void)
{
return active_thread->pid;
return sched_active_thread->pid;
}
/*---------------------------------------------------------------------------*/
int _kill_r(struct _reent *r, int pid, int sig)

2
cpu/lpc2387/gpioint/lpc2387-gpioint.c

@ -61,7 +61,7 @@ gpioint_set(int port, uint32_t bitmask, int flags, fp_irqcb callback)
volatile unsigned long *en_clr;
/* lookup registers */
bit = number_of_highest_bit(bitmask); /* get irq mapping table index */
bit = bitarithm_msb(bitmask); /* get irq mapping table index */
switch(port) {
case 0: /* PORT0 */

4
cpu/msp430-common/cpu.c

@ -25,7 +25,7 @@ void thread_yield(void)
__save_context();
dINT();
/* have active_thread point to the next thread */
/* have sched_active_thread point to the next thread */
sched_run();
eINT();
@ -34,7 +34,7 @@ void thread_yield(void)
NORETURN void cpu_switch_context_exit(void)
{
active_thread = sched_threads[0];
sched_active_thread = sched_threads[0];
sched_run();
__restore_context();

4
cpu/msp430-common/include/cpu.h

@ -57,12 +57,12 @@ inline void __save_context_isr(void)
__asm__("push r5");
__asm__("push r4");
__asm__("mov.w r1,%0" : "=r"(active_thread->sp));
__asm__("mov.w r1,%0" : "=r"(sched_active_thread->sp));
}
inline void __restore_context_isr(void)
{
__asm__("mov.w %0,r1" : : "m"(active_thread->sp));
__asm__("mov.w %0,r1" : : "m"(sched_active_thread->sp));
__asm__("pop r4");
__asm__("pop r5");

8
cpu/native/irq_cpu.c

@ -45,7 +45,7 @@
#define ENABLE_DEBUG (0)
#include "debug.h"
extern volatile tcb_t *active_thread;
extern volatile tcb_t *sched_active_thread;
volatile int native_interrupts_enabled;
volatile int _native_in_isr;
@ -303,9 +303,9 @@ void native_isr_entry(int sig, siginfo_t *info, void *context)
if (context == NULL) {
errx(EXIT_FAILURE, "native_isr_entry: context is null - unhandled");
}
if (active_thread == NULL) {
if (sched_active_thread == NULL) {
_native_in_isr++;
warnx("native_isr_entry: active_thread is null - unhandled");
warnx("native_isr_entry: sched_active_thread is null - unhandled");
_native_in_isr--;
return;
}
@ -330,7 +330,7 @@ void native_isr_entry(int sig, siginfo_t *info, void *context)
native_isr_context.uc_stack.ss_size = SIGSTKSZ;
native_isr_context.uc_stack.ss_flags = 0;
makecontext(&native_isr_context, native_irq_handler, 0);
_native_cur_ctx = (ucontext_t *)active_thread->sp;
_native_cur_ctx = (ucontext_t *)sched_active_thread->sp;
DEBUG("\n\n\t\treturn to _native_sig_leave_tramp\n\n");
/* disable interrupts in context */

16
cpu/native/native_cpu.c

@ -54,7 +54,7 @@
#define ENABLE_DEBUG (0)
#include "debug.h"
extern volatile tcb_t *active_thread;
extern volatile tcb_t *sched_active_thread;
ucontext_t end_context;
char __end_stack[SIGSTKSZ];
@ -129,12 +129,12 @@ void isr_cpu_switch_context_exit(void)
ucontext_t *ctx;
DEBUG("XXX: cpu_switch_context_exit()\n");
if ((sched_context_switch_request == 1) || (active_thread == NULL)) {
if ((sched_context_switch_request == 1) || (sched_active_thread == NULL)) {
sched_run();
}
DEBUG("XXX: cpu_switch_context_exit(): calling setcontext(%s)\n\n", active_thread->name);
ctx = (ucontext_t *)(active_thread->sp);
DEBUG("XXX: cpu_switch_context_exit(): calling setcontext(%s)\n\n", sched_active_thread->name);
ctx = (ucontext_t *)(sched_active_thread->sp);
/* the next context will have interrupts enabled due to ucontext */
DEBUG("XXX: cpu_switch_context_exit: native_interrupts_enabled = 1;\n");
@ -150,7 +150,7 @@ void isr_cpu_switch_context_exit(void)
void cpu_switch_context_exit(void)
{
#ifdef NATIVE_AUTO_EXIT
if (num_tasks <= 1) {
if (sched_num_threads <= 1) {
DEBUG("cpu_switch_context_exit(): last task has ended. exiting.\n");
exit(EXIT_SUCCESS);
}
@ -179,8 +179,8 @@ void isr_thread_yield(void)
DEBUG("isr_thread_yield()\n");
sched_run();
ucontext_t *ctx = (ucontext_t *)(active_thread->sp);
DEBUG("isr_thread_yield(): switching to(%s)\n\n", active_thread->name);
ucontext_t *ctx = (ucontext_t *)(sched_active_thread->sp);
DEBUG("isr_thread_yield(): switching to(%s)\n\n", sched_active_thread->name);
native_interrupts_enabled = 1;
_native_in_isr = 0;
@ -191,7 +191,7 @@ void isr_thread_yield(void)
void thread_yield(void)
{
ucontext_t *ctx = (ucontext_t *)(active_thread->sp);
ucontext_t *ctx = (ucontext_t *)(sched_active_thread->sp);
if (_native_in_isr == 0) {
_native_in_isr = 1;
dINT();

6
cpu/native/syscalls.c

@ -46,7 +46,7 @@
#endif
#include "debug.h"
extern volatile tcb_t *active_thread;
extern volatile tcb_t *sched_active_thread;
ssize_t (*real_read)(int fd, void *buf, size_t count);
ssize_t (*real_write)(int fd, const void *buf, size_t count);
@ -74,12 +74,12 @@ void _native_syscall_leave(void)
&& (_native_in_isr == 0)
&& (_native_in_syscall == 0)
&& (native_interrupts_enabled == 1)
&& (active_thread != NULL)
&& (sched_active_thread != NULL)
)
{
_native_in_isr = 1;
dINT();
_native_cur_ctx = (ucontext_t *)active_thread->sp;
_native_cur_ctx = (ucontext_t *)sched_active_thread->sp;
native_isr_context.uc_stack.ss_sp = __isr_stack;
native_isr_context.uc_stack.ss_size = SIGSTKSZ;
native_isr_context.uc_stack.ss_flags = 0;

2
cpu/sam3x8e/syscalls.c

@ -99,7 +99,7 @@ caddr_t _sbrk_r(struct _reent *r, size_t incr)
*/
int _getpid(void)
{
return active_thread->pid;
return sched_active_thread->pid;
}
/**

4
drivers/cc110x/cc1100_phy.c

@ -197,9 +197,9 @@ void cc1100_phy_init(void)
void cc1100_phy_mutex_lock(void)
{
if (active_thread->pid != cc1100_mutex_pid) {
if (sched_active_thread->pid != cc1100_mutex_pid) {
mutex_lock(&cc1100_mutex);
cc1100_mutex_pid = active_thread->pid;
cc1100_mutex_pid = sched_active_thread->pid;
}
}

2
sys/net/ccn_lite/ccn-lite-relay.c

@ -427,7 +427,7 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl)
void ccnl_riot_relay_start(int max_cache_entries, int fib_threshold_prefix, int fib_threshold_aggregate)
{
ccnl_get_timeval(&theRelay.startup_time);
theRelay.riot_pid = thread_pid;
theRelay.riot_pid = sched_active_pid;
DEBUGMSG(1, "This is ccn-lite-relay, starting at %lu:%lu\n", theRelay.startup_time.tv_sec, theRelay.startup_time.tv_usec);
DEBUGMSG(1, " compile time: %s %s\n", __DATE__, __TIME__);

6
sys/posix/pthread/pthread.c

@ -158,7 +158,7 @@ int pthread_create(pthread_t *newthread, const pthread_attr_t *attr, void *(*sta
return -1;
}
sched_switch(active_thread->priority, PRIORITY_MAIN);
sched_switch(sched_active_thread->priority, PRIORITY_MAIN);
return 0;
}
@ -217,7 +217,7 @@ int pthread_join(pthread_t th, void **thread_return)
switch (other->status) {
case (PTS_RUNNING):
other->joining_thread = thread_pid;
other->joining_thread = sched_active_pid;
/* go blocked, I'm waking up if other thread exits */
thread_sleep();
/* no break */
@ -265,7 +265,7 @@ pthread_t pthread_self(void)
{
pthread_t result = 0;
mutex_lock(&pthread_mutex);
int pid = thread_pid; /* thread_pid is volatile */
int pid = sched_active_pid; /* sched_active_pid is volatile */
for (int i = 0; i < MAXTHREADS; i++) {
if (pthread_sched_threads[i] && pthread_sched_threads[i]->thread_pid == pid) {
result = i+1;

8
sys/posix/pthread/pthread_barrier.c

@ -48,16 +48,16 @@ int pthread_barrier_wait(pthread_barrier_t *barrier)
mutex_lock(&barrier->mutex);
DEBUG("%s: hit a synchronization barrier. pid=%u\n",
active_thread->name, active_thread->pid);
sched_active_thread->name, sched_active_thread->pid);
if (--barrier->count > 0) {
/* need to wait for further threads */
DEBUG("%s: waiting for %u threads. pid=%u\n",
active_thread->name, barrier->count, active_thread->pid);
sched_active_thread->name, barrier->count, sched_active_thread->pid);
pthread_barrier_waiting_node_t node;
node.pid = thread_pid;
node.pid = sched_active_pid;
node.next = barrier->next;
node.cont = 0;
@ -80,7 +80,7 @@ int pthread_barrier_wait(pthread_barrier_t *barrier)
/* all threads have arrived, wake everybody up */
DEBUG("%s: waking every other thread up. pid=%u\n",
active_thread->name, active_thread->pid);
sched_active_thread->name, sched_active_thread->pid);
int count = 1; /* Count number of woken up threads.
* The first thread is the current thread. */

10
sys/posix/pthread/pthread_cond.c

@ -99,8 +99,8 @@ int pthread_cond_destroy(struct pthread_cond_t *cond)
int pthread_cond_wait(struct pthread_cond_t *cond, struct mutex_t *mutex)
{
queue_node_t n;
n.priority = active_thread->priority;
n.data = active_thread->pid;
n.priority = sched_active_thread->priority;
n.data = sched_active_thread->pid;
n.next = NULL;
/* the signaling thread may not hold the mutex, the queue is not thread safe */
@ -132,7 +132,7 @@ int pthread_cond_timedwait(struct pthread_cond_t *cond, struct mutex_t *mutex, c
reltime = timex_sub(then, now);
vtimer_t timer;
vtimer_set_wakeup(&timer, reltime, active_thread->pid);
vtimer_set_wakeup(&timer, reltime, sched_active_thread->pid);
int result = pthread_cond_wait(cond, mutex);
vtimer_remove(&timer);
@ -157,7 +157,7 @@ int pthread_cond_signal(struct pthread_cond_t *cond)
restoreIRQ(old_state);
if (other_prio >= 0) {
sched_switch(active_thread->priority, other_prio);
sched_switch(sched_active_thread->priority, other_prio);
}
return 0;
@ -191,7 +191,7 @@ int pthread_cond_broadcast(struct pthread_cond_t *cond)
restoreIRQ(old_state);
if (other_prio >= 0) {
sched_switch(active_thread->priority, other_prio);
sched_switch(sched_active_thread->priority, other_prio);
}
return 0;

10
sys/posix/pthread/pthread_rwlock.c

@ -81,7 +81,7 @@ bool __pthread_rwlock_blocked_readingly(const pthread_rwlock_t *rwlock)
}
queue_node_t *qnode = rwlock->queue.next;
if (qnode->priority > active_thread->priority) {
if (qnode->priority > sched_active_thread->priority) {
/* the waiting thread has a lower priority */
return false;
}
@ -122,11 +122,11 @@ static int pthread_rwlock_lock(pthread_rwlock_t *rwlock,
/* queue for the lock */
__pthread_rwlock_waiter_node_t waiting_node = {
.is_writer = is_writer,
.thread = (tcb_t *) active_thread,
.thread = (tcb_t *) sched_active_thread,
.qnode = {
.next = NULL,
.data = (uintptr_t) &waiting_node,
.priority = active_thread->priority,
.priority = sched_active_thread->priority,
},
.continue_ = false,
};
@ -200,7 +200,7 @@ static int pthread_rwlock_timedlock(pthread_rwlock_t *rwlock,
timex_t reltime = timex_sub(then,