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

core: introduce KERNEL_PID_FIRST and KERNEL_PID_LAST

This commit is contained in:
René Kijewski 2014-08-13 09:08:50 +02:00
parent 6999e6fb21
commit b31e5a8675
4 changed files with 32 additions and 19 deletions

View File

@ -5,19 +5,35 @@
#include <inttypes.h>
/**
* @def KERNEL_PID_UNDEF
* @brief Identifier to detect an invalid PID
* @def MAXTHREADS
* @brief The maximum number of threads to be scheduled
*/
#ifndef MAXTHREADS
#define MAXTHREADS 32
#endif
/**
* Canonical identifier for an invalid PID.
*/
#define KERNEL_PID_UNDEF -1
/**
* The first valid PID (inclusive).
*/
#define KERNEL_PID_FIRST (KERNEL_PID_UNDEF + 1)
/**
* The last valid PID (inclusive).
*/
#define KERNEL_PID_LAST (KERNEL_PID_FIRST + MAXTHREADS - 1)
/**
* Macro for printing formatter
*/
#define PRIkernel_pid PRIi16
/**
* @brief Unique process identifier
*
* Unique process identifier
*/
typedef int16_t kernel_pid_t;

View File

@ -84,8 +84,7 @@
#include "bitarithm.h"
#include "tcb.h"
#include "attributes.h"
#define MAXTHREADS 32 /**< the maximum number of threads to be scheduled */
#include "kernel_types.h"
/**
* @def SCHED_PRIO_LEVELS

View File

@ -39,7 +39,7 @@ inline kernel_pid_t thread_getpid(void)
volatile tcb_t *thread_get(kernel_pid_t pid)
{
if ((pid != KERNEL_PID_UNDEF) && (0 <= pid) && (pid < MAXTHREADS)) {
if ((pid != KERNEL_PID_UNDEF) && (KERNEL_PID_FIRST <= pid) && (pid <= KERNEL_PID_LAST)) {
return sched_threads[pid];
}
return NULL;
@ -158,19 +158,14 @@ kernel_pid_t thread_create(char *stack, int stacksize, char priority, int flags,
dINT();
}
kernel_pid_t pid = 0;
while (pid < MAXTHREADS) {
if (sched_threads[pid] == NULL) {
sched_threads[pid] = cb;
cb->pid = pid;
kernel_pid_t pid = KERNEL_PID_UNDEF;
for (kernel_pid_t i = KERNEL_PID_FIRST; i <= KERNEL_PID_LAST; ++i) {
if (sched_threads[i] == NULL) {
pid = i;
break;
}
pid++;
}
if (pid == MAXTHREADS) {
if (pid == KERNEL_PID_UNDEF) {
DEBUG("thread_create(): too many threads!\n");
if (!inISR()) {
@ -180,6 +175,9 @@ kernel_pid_t thread_create(char *stack, int stacksize, char priority, int flags,
return -EOVERFLOW;
}
sched_threads[pid] = cb;
cb->pid = pid;
cb->sp = thread_stack_init(function, arg, stack, stacksize);
cb->stack_start = stack;

View File

@ -21,6 +21,7 @@
#include "hwtimer.h"
#include "sched.h"
#include "tcb.h"
#include "kernel_types.h"
/* list of states copied from tcb.h */
const char *state_names[] = {
@ -40,7 +41,6 @@ const char *state_names[] = {
void thread_print_all(void)
{
const char queued_name[] = {'_', 'Q'};
int i;
#ifdef DEVELHELP
int overall_stacksz = 0, overall_used = 0;
#endif
@ -56,7 +56,7 @@ void thread_print_all(void)
"\n"
, "name", "state");
for (i = 0; i < MAXTHREADS; i++) {
for (kernel_pid_t i = KERNEL_PID_FIRST; i <= KERNEL_PID_LAST; i++) {
tcb_t *p = (tcb_t *)sched_threads[i];
if (p != NULL) {