1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

core: sched: thread: optimize thread status field usage

see PR #716 for discussion
This commit is contained in:
Kaspar Schleiser 2014-02-17 12:28:54 +01:00
parent 6dea183eac
commit 36981c95b9
4 changed files with 25 additions and 21 deletions

View File

@ -27,22 +27,24 @@
#include "cib.h"
#include "msg.h"
/* uneven means has to be on runqueue */
#define STATUS_NOT_FOUND (0x0000) /**< invalid status, may be used as
* return value to signal an error
*/
#define STATUS_ON_RUNQUEUE (0x0001) /**< scheduled to run */
#define STATUS_RUNNING (0x0002 + STATUS_ON_RUNQUEUE) /**< currently running */
#define STATUS_PENDING (0x0004 + STATUS_ON_RUNQUEUE) /**< waiting to be scheduled to run */
#define STATUS_STOPPED (0x0008) /**< has terminated */
#define STATUS_SLEEPING (0x0010) /**< sleeping */
#define STATUS_MUTEX_BLOCKED (0x0020) /**< waiting for a locked mutex */
#define STATUS_RECEIVE_BLOCKED (0x0040) /**< waiting for a message */
#define STATUS_SEND_BLOCKED (0x0080) /**< waiting for message to be
* delivered */
#define STATUS_REPLY_BLOCKED (0x0100) /**< waiting for a message response */
#define STATUS_TIMER_WAITING (0x0200) /**< waiting for a timer to fire
* (deprecated) */
/* thread status list */
/* blocked states: */
#define STATUS_STOPPED 0 /**< has terminated */
#define STATUS_SLEEPING 1 /**< sleeping */
#define STATUS_MUTEX_BLOCKED 2 /**< waiting for a locked mutex */
#define STATUS_RECEIVE_BLOCKED 3 /**< waiting for a message */
#define STATUS_SEND_BLOCKED 4 /**< waiting for message to be
* delivered */
#define STATUS_REPLY_BLOCKED 5 /**< waiting for a message response */
#define STATUS_TIMER_WAITING 6 /**< waiting for a timer to fire */
#define STATUS_ON_RUNQUEUE 7 /**< */
/* these have to be on a run queue: */
#define STATUS_RUNNING 7 /**< currently running */
#define STATUS_PENDING 8 /**< waiting to be scheduled to run */
typedef struct tcb_t {
char *sp;

View File

@ -26,6 +26,8 @@
#include "kernel.h"
#include "tcb.h"
#define STATUS_NOT_FOUND (-1)
/** Minimum stack size */
#ifndef MINIMUM_STACK_SIZE
#define MINIMUM_STACK_SIZE (sizeof(tcb_t))
@ -53,7 +55,7 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void (*f
* @brief returns the status of a process.
* @return STATUS_NOT_FOUND if pid is unknown
*/
unsigned int thread_getstatus(int pid);
int thread_getstatus(int pid);
/**
* @brief returns the name of a process.

View File

@ -149,15 +149,15 @@ void sched_register_cb(void (*callback)(uint32_t, uint32_t))
void sched_set_status(tcb_t *process, unsigned int status)
{
if (status & STATUS_ON_RUNQUEUE) {
if (!(process->status & STATUS_ON_RUNQUEUE)) {
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));
runqueue_bitcache |= 1 << process->priority;
}
}
else {
if (process->status & STATUS_ON_RUNQUEUE) {
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));

View File

@ -42,7 +42,7 @@ int thread_getlastpid()
return last_pid;
}
unsigned int thread_getstatus(int pid)
int thread_getstatus(int pid)
{
if (sched_threads[pid] == NULL) {
return STATUS_NOT_FOUND;