diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-03-20 16:51:12 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-03-20 16:51:12 +0000 |
commit | 360b2b7ab8fd7cf337f02e260346a0f0ecbb8064 (patch) | |
tree | 7e83b806156983fa5af8a32715d849762b8c7346 /nuttx/include/sched.h | |
parent | d913f00d3b4bcbebc12dfa7ea017bacd17464b88 (diff) | |
download | px4-nuttx-360b2b7ab8fd7cf337f02e260346a0f0ecbb8064.tar.gz px4-nuttx-360b2b7ab8fd7cf337f02e260346a0f0ecbb8064.tar.bz2 px4-nuttx-360b2b7ab8fd7cf337f02e260346a0f0ecbb8064.zip |
Restructure header files for POSIX compliance; eliminate compile warnings
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@107 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/include/sched.h')
-rw-r--r-- | nuttx/include/sched.h | 254 |
1 files changed, 26 insertions, 228 deletions
diff --git a/nuttx/include/sched.h b/nuttx/include/sched.h index bab6f517f..0efce85db 100644 --- a/nuttx/include/sched.h +++ b/nuttx/include/sched.h @@ -1,4 +1,4 @@ -/************************************************************ +/******************************************************************************** * sched.h * * Copyright (C) 2007 Gregory Nutt. All rights reserved. @@ -31,231 +31,48 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ********************************************************************************/ #ifndef __SCHED_H #define __SCHED_H -/************************************************************ +/******************************************************************************** * Included Files - ************************************************************/ + ********************************************************************************/ #include <nuttx/config.h> -#include <queue.h> -#include <signal.h> -#include <semaphore.h> -#include <pthread.h> -#include <mqueue.h> -#include <time.h> -#include <nuttx/irq.h> +#include <nuttx/sched.h> -/************************************************************ +/******************************************************************************** * Definitions - ************************************************************/ + ********************************************************************************/ -/* Task Management Definitins *******************************/ +/* Task Management Definitins ***************************************************/ -/* This is the maximum number of times that a lock can be set */ +/* POSIX-like scheduling policies */ -#define MAX_LOCK_COUNT 127 +#define SCHED_FIFO 1 /* FIFO per priority scheduling policy */ +#define SCHED_RR 2 /* Round robin scheduling policy */ +#define SCHED_OTHER 4 /* Not used */ -/* Values for the _TCB flags flag bits */ - -#define TCB_FLAG_PTHREAD 0x0001 /* Thread is a pthread */ -#define TCB_FLAG_NONCANCELABLE 0x0002 /* Pthread is non-cancelable */ -#define TCB_FLAG_CANCEL_PENDING 0x0004 /* Pthread cancel is pending */ -#define TCB_FLAG_ROUND_ROBIN 0x0008 /* Round robin sched enabled */ - -/* Pthread definitions **************************************/ +/* Pthread definitions **********************************************************/ #define PTHREAD_KEYS_MAX CONFIG_NPTHREAD_KEYS -/************************************************************ +/******************************************************************************** * Global Type Definitions - ************************************************************/ - -#ifndef __ASSEMBLY__ - -/* General Task Management Types ****************************/ - -/* This is the type of the task_state field of the TCB. - * NOTE: the order and content of this enumeration is - * critical since there are some OS tables indexed by these - * values. - */ - -typedef enum tstate_e -{ - TSTATE_TASK_INVALID = 0, /* INVALID - TCB has not yet been initialized */ - - TSTATE_TASK_PENDING = 1, /* READY_TO_RUN - Pending preemption unlock */ - TSTATE_TASK_READYTORUN = 2, /* READY-TO-RUN - But not running */ - TSTATE_TASK_RUNNING = 3, /* READY_TO_RUN - And running */ - - TSTATE_TASK_INACTIVE = 4, /* BLOCKED - Initialized but not yet activated */ - TSTATE_WAIT_SEM = 5, /* BLOCKED - Waiting for a semaphore */ -#ifndef CONFIG_DISABLE_SIGNALS - TSTATE_WAIT_SIG = 6, /* BLOCKED - Waiting for a signal */ -#endif -#ifndef CONFIG_DISABLE_MQUEUE - TSTATE_WAIT_MQNOTEMPTY, /* BLOCKED - Waiting for a MQ to become not empty. */ - TSTATE_WAIT_MQNOTFULL /* BLOCKED - Waiting for a MQ to become not full. */ -#endif -}; -typedef enum tstate_e tstate_t; - -/* The following definitions are determined by tstate_t */ - -#define FIRST_READY_TO_RUN_STATE TSTATE_TASK_READYTORUN -#define LAST_READY_TO_RUN_STATE TSTATE_TASK_RUNNING -#define FIRST_BLOCKED_STATE TSTATE_TASK_INACTIVE -#ifndef CONFIG_DISABLE_MQUEUE -# define LAST_BLOCKED_STATE TSTATE_WAIT_MQNOTFULL -# ifndef CONFIG_DISABLE_SIGNALS -# define NUM_TASK_STATES 9 -# else -# define NUM_TASK_STATES 8 -# endif -#else -# ifndef CONFIG_DISABLE_SIGNALS -# define LAST_BLOCKED_STATE TSTATE_WAIT_SIG -# define NUM_TASK_STATES 7 -# else -# define LAST_BLOCKED_STATE TSTATE_WAIT_SEM -# define NUM_TASK_STATES 6 -# endif -#endif + ********************************************************************************/ -/* The following is the form of a thread start-up function */ +/* This is the POSIX-like scheduling parameter structure */ -typedef void (*start_t)(void); - -/* This is the entry point into the main thread of the task - * or into a created pthread within the task. - */ - -union entry_u -{ - pthread_startroutine_t pthread; - main_t main; -}; -typedef union entry_u entry_t; - -/* This is the type of the function that is executed with - * exit() is called (if registered via atexit()). - */ - -typedef void (*exitfunc_t)(void); - -/* POSIX Message queue */ - -typedef struct msgq_s msgq_t; - -/* This is the task control block (TCB) */ - -struct _TCB +struct sched_param { - /* Fields used to support list management ***************************/ - - FAR struct _TCB *flink; /* link in DQ of TCBs */ - FAR struct _TCB *blink; - - /* Task Management Fields *******************************************/ - - pid_t pid; /* This is the ID of the thread */ - start_t start; /* Thread start function */ - entry_t entry; /* Entry Point into the thread */ - exitfunc_t exitfunc; /* Called if exit is called. */ - ubyte sched_priority; /* Current priority of the thread */ - tstate_t task_state; /* Current state of the thread */ - uint16 flags; /* Misc. general status flags */ - sint16 lockcount; /* 0=preemptable (not-locked) */ - FAR void *joininfo; /* Detach-able info to support join */ -#if CONFIG_RR_INTERVAL > 0 - int timeslice; /* RR timeslice interval remaining */ -#endif - - /* Values needed to restart a task **********************************/ - - ubyte init_priority; /* Initial priority of the task */ - char *argv[CONFIG_MAX_TASK_ARGS+1]; /* Name+start-up parameters */ - - /* Stack-Related Fields *********************************************/ - -#ifndef CONFIG_CUSTOM_STACK - size_t adj_stack_size; /* Stack size after adjustment */ - /* for hardware, processor, etc. */ - /* (for debug purposes only) */ - FAR void *stack_alloc_ptr; /* Pointer to allocated stack */ - /* Need to deallocate stack */ - FAR void *adj_stack_ptr; /* Adjusted stack_alloc_ptr for HW */ - /* The initial stack pointer value */ -#endif - - /* POSIX thread Specific Data ***************************************/ - -#if !defined(CONFIG_DISABLE_PTHREAD) && CONFIG_NPTHREAD_KEYS > 0 - FAR void *pthread_data[CONFIG_NPTHREAD_KEYS]; -#endif - - /* POSIX Semaphore Control Fields ***********************************/ - - sem_t *waitsem; /* Semaphore ID waiting on */ - - /* POSIX Signal Control Fields **************************************/ - -#ifndef CONFIG_DISABLE_SIGNALS - sigset_t sigprocmask; /* Signals that are blocked */ - sigset_t sigwaitmask; /* Waiting for pending signals */ - sq_queue_t sigactionq; /* List of actions for signals */ - sq_queue_t sigpendingq; /* List of Pending Signals */ - sq_queue_t sigpendactionq; /* List of pending signal actions */ - sq_queue_t sigpostedq; /* List of posted signals */ - siginfo_t sigunbinfo; /* Signal info when task unblocked */ -#endif - - /* POSIX Named Message Queue Fields *********************************/ - -#ifndef CONFIG_DISABLE_MQUEUE - sq_queue_t msgdesq; /* List of opened message queues */ - FAR msgq_t *msgwaitq; /* Waiting for this message queue */ -#endif - - /* Library related fields *******************************************/ - - int errno; /* Current per-thread errno */ - - /* File system support **********************************************/ - -#if CONFIG_NFILE_DESCRIPTORS > 0 - FAR struct filelist *filelist; /* Maps file descriptor to file */ -#endif - -#if CONFIG_NFILE_STREAMS > 0 - FAR struct streamlist *streams; /* Holds C buffered I/O info */ -#endif - - /* State save areas *************************************************/ - /* The form and content of these fields are processor-specific. */ - - struct xcptcontext xcp; /* Interrupt register save area */ - -#if CONFIG_TASK_NAME_SIZE > 0 - char name[CONFIG_TASK_NAME_SIZE]; /* Task name */ -#endif - + int sched_priority; }; -typedef struct _TCB _TCB; -/* This is the callback type used by sched_foreach() */ - -typedef void (sched_foreach_t)(FAR _TCB *tcb, FAR void *arg); - -#endif /* __ASSEMBLY__ */ - -/************************************************************ +/******************************************************************************** * Global Function Prototypes - ************************************************************/ + ********************************************************************************/ #ifndef __ASSEMBLY__ #undef EXTERN @@ -289,18 +106,15 @@ EXTERN STATUS task_restart(pid_t pid); /* Task Scheduling Interfaces (based on POSIX APIs) */ -EXTERN int sched_setparam(pid_t pid, - const struct sched_param *param); -EXTERN int sched_getparam(pid_t pid, - struct sched_param *param); +EXTERN int sched_setparam(pid_t pid, const struct sched_param *param); +EXTERN int sched_getparam(pid_t pid, struct sched_param *param); EXTERN int sched_setscheduler(pid_t pid, int policy, const struct sched_param *param); EXTERN int sched_getscheduler(pid_t pid); EXTERN int sched_yield(void); EXTERN int sched_get_priority_max(int policy); EXTERN int sched_get_priority_min(int policy); -EXTERN int sched_rr_get_interval(pid_t pid, - struct timespec *interval); +EXTERN int sched_rr_get_interval(pid_t pid, struct timespec *interval); /* Task Switching Interfaces (non-standard) */ @@ -314,9 +128,9 @@ EXTERN sint32 sched_lockcount(void); #ifdef CONFIG_SCHED_INSTRUMENTATION -EXTERN void sched_note_start(FAR _TCB *tcb ); -EXTERN void sched_note_stop(FAR _TCB *tcb ); -EXTERN void sched_note_switch(FAR _TCB *pFromTcb, FAR _TCB *pToTcb); +EXTERN void sched_note_start(FAR _TCB *tcb ); +EXTERN void sched_note_stop(FAR _TCB *tcb ); +EXTERN void sched_note_switch(FAR _TCB *pFromTcb, FAR _TCB *pToTcb); #else # define sched_note_start(t) @@ -324,22 +138,6 @@ EXTERN void sched_note_switch(FAR _TCB *pFromTcb, FAR _TCB *pToTcb); # define sched_note_switch(t1, t2) #endif /* CONFIG_SCHED_INSTRUMENTATION */ -/* File system helpers */ - -#if CONFIG_NFILE_DESCRIPTORS > 0 -EXTERN FAR struct filelist *sched_getfiles(void); -#if CONFIG_NFILE_STREAMS > 0 -EXTERN FAR struct streamlist *sched_getstreams(void); -#endif /* CONFIG_NFILE_STREAMS */ -#endif /* CONFIG_NFILE_DESCRIPTORS */ - -/* sched_foreach will enumerate over each task and provide the - * TCB of each task to a user callback functions. Interrupts - * will be disabled throughout this enumeration! - */ - -EXTERN void sched_foreach(sched_foreach_t handler, FAR void *arg); - #undef EXTERN #if defined(__cplusplus) } |