Tizen RT Libs&Environment  v1.0 D5
sched.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 
19 /********************************************************************************
20  *
21  * Copyright (C) 2007-2014 Gregory Nutt. All rights reserved.
22  * Author: Gregory Nutt <gnutt@nuttx.org>
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  *
28  * 1. Redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer.
30  * 2. Redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in
32  * the documentation and/or other materials provided with the
33  * distribution.
34  * 3. Neither the name NuttX nor the names of its contributors may be
35  * used to endorse or promote products derived from this software
36  * without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
41  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
42  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
43  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
45  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
46  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
48  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49  * POSSIBILITY OF SUCH DAMAGE.
50  *
51  ********************************************************************************/
53 
54 #ifndef __INCLUDE_TINYARA_SCHED_H
55 #define __INCLUDE_TINYARA_SCHED_H
56 
57 /********************************************************************************
58  * Included Files
59  ********************************************************************************/
60 
61 #include <tinyara/config.h>
62 
63 #include <sys/types.h>
64 #include <stdint.h>
65 #include <queue.h>
66 #include <signal.h>
67 #include <semaphore.h>
68 #include <pthread.h>
69 #include <mqueue.h>
70 #include <time.h>
71 
72 #include <tinyara/irq.h>
73 #include <tinyara/mm/shm.h>
74 #include <tinyara/fs/fs.h>
75 #include <tinyara/net/net.h>
76 
77 #include <arch/arch.h>
78 
79 /********************************************************************************
80  * Pre-processor Definitions
81  ********************************************************************************/
82 /* Configuration ****************************************************************/
83 /* Task groups currently only supported for retention of child status */
84 
85 #undef HAVE_TASK_GROUP
86 #undef HAVE_GROUP_MEMBERS
87 
88 /* We need a group an group members if we are supporting the parent/child
89  * relationship.
90  */
91 
92 #if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS)
93 #define HAVE_TASK_GROUP 1
94 #define HAVE_GROUP_MEMBERS 1
95 
96 /* We need a group (but not members) if any other resources are shared within
97  * a task group. NOTE: that we essentially always need a task group and that
98  * managing this definition adds a lot of overhead just to handle a corner-
99  * case very minimal system!
100  */
101 
102 #else
103 #if !defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_SCHED_HAVE_PARENT)
104 #define HAVE_TASK_GROUP 1 /* pthreads with parent */
105 #elif !defined(CONFIG_DISABLE_ENVIRON)
106 #define HAVE_TASK_GROUP 1 /* Environment variables */
107 #elif !defined(CONFIG_DISABLE_SIGNALS)
108 #define HAVE_TASK_GROUP 1 /* Signals */
109 #elif defined(CONFIG_SCHED_ATEXIT)
110 #define HAVE_TASK_GROUP 1 /* Group atexit() function */
111 #elif defined(CONFIG_SCHED_ONEXIT)
112 #define HAVE_TASK_GROUP 1 /* Group on_exit() function */
113 #elif defined(CONFIG_SCHED_WAITPID)
114 #define HAVE_TASK_GROUP 1 /* Group waitpid() function */
115 #elif CONFIG_NFILE_DESCRIPTORS > 0
116 #define HAVE_TASK_GROUP 1 /* File descriptors */
117 #elif CONFIG_NFILE_STREAMS > 0
118 #define HAVE_TASK_GROUP 1 /* Standard C buffered I/O */
119 #elif CONFIG_NSOCKET_DESCRIPTORS > 0
120 #define HAVE_TASK_GROUP 1 /* Sockets */
121 #elif !defined(CONFIG_DISABLE_MQUEUE)
122 #define HAVE_TASK_GROUP 1 /* Message queues */
123 #elif defined(CONFIG_ARCH_ADDRENV)
124 #define HAVE_TASK_GROUP 1 /* Address environment */
125 #elif defined(CONFIG_MM_SHM)
126 #define HAVE_TASK_GROUP 1 /* Shared memory */
127 #endif
128 #endif
129 
130 /* In any event, we don't need group members if support for pthreads is disabled */
131 
132 #ifdef CONFIG_DISABLE_PTHREAD
133 #undef HAVE_GROUP_MEMBERS
134 #endif
135 
136 /* Task Management Definitions **************************************************/
137 /* Special task IDS. Any negative PID is invalid. */
138 
139 #define NULL_TASK_PROCESS_ID (pid_t)0
140 #define INVALID_PROCESS_ID (pid_t)-1
141 
142 /* This is the maximum number of times that a lock can be set */
143 
144 #define MAX_LOCK_COUNT 127
145 
146 /* Values for the struct tcb_s flags bits */
147 
148 #define TCB_FLAG_TTYPE_SHIFT (0) /* Bits 0-1: thread type */
149 #define TCB_FLAG_TTYPE_MASK (3 << TCB_FLAG_TTYPE_SHIFT)
150 #define TCB_FLAG_TTYPE_TASK (0 << TCB_FLAG_TTYPE_SHIFT) /* Normal user task */
151 #define TCB_FLAG_TTYPE_PTHREAD (1 << TCB_FLAG_TTYPE_SHIFT) /* User pthread */
152 #define TCB_FLAG_TTYPE_KERNEL (2 << TCB_FLAG_TTYPE_SHIFT) /* Kernel thread */
153 #define TCB_FLAG_NONCANCELABLE (1 << 2) /* Bit 2: Pthread is non-cancelable */
154 #define TCB_FLAG_CANCEL_PENDING (1 << 3) /* Bit 3: Pthread cancel is pending */
155 #define TCB_FLAG_ROUND_ROBIN (1 << 4) /* Bit 4: Round robin sched enabled */
156 #define TCB_FLAG_EXIT_PROCESSING (1 << 5) /* Bit 5: Exitting */
157 
158 /* Values for struct task_group tg_flags */
159 
160 #define GROUP_FLAG_NOCLDWAIT (1 << 0) /* Bit 0: Do not retain child exit status */
161 #define GROUP_FLAG_ADDRENV (1 << 1) /* Bit 1: Group has an address environment */
162 #define GROUP_FLAG_PRIVILEGED (1 << 2) /* Bit 2: Group is privileged */
163 
164 /* Values for struct child_status_s ch_flags */
165 
166 #define CHILD_FLAG_TTYPE_SHIFT (0) /* Bits 0-1: child thread type */
167 #define CHILD_FLAG_TTYPE_MASK (3 << CHILD_FLAG_TTYPE_SHIFT)
168 #define CHILD_FLAG_TTYPE_TASK (0 << CHILD_FLAG_TTYPE_SHIFT) /* Normal user task */
169 #define CHILD_FLAG_TTYPE_PTHREAD (1 << CHILD_FLAG_TTYPE_SHIFT) /* User pthread */
170 #define CHILD_FLAG_TTYPE_KERNEL (2 << CHILD_FLAG_TTYPE_SHIFT) /* Kernel thread */
171 #define CHILD_FLAG_EXITED (1 << 0) /* Bit 2: The child thread has exit'ed */
172 
173 /********************************************************************************
174  * Public Type Definitions
175  ********************************************************************************/
176 
177 #ifndef __ASSEMBLY__
178 
179 /* General Task Management Types ************************************************/
180 
187 enum tstate_e {
188  TSTATE_TASK_INVALID = 0, /* INVALID - The TCB is uninitialized */
189  TSTATE_TASK_PENDING, /* READY_TO_RUN - Pending preemption unlock */
190  TSTATE_TASK_READYTORUN, /* READY-TO-RUN - But not running */
191  TSTATE_TASK_RUNNING, /* READY_TO_RUN - And running */
192 
193  TSTATE_TASK_INACTIVE, /* BLOCKED - Initialized but not yet activated */
194  TSTATE_WAIT_SEM, /* BLOCKED - Waiting for a semaphore */
195 #ifndef CONFIG_DISABLE_SIGNALS
196  TSTATE_WAIT_SIG, /* BLOCKED - Waiting for a signal */
197 #endif
198 #ifndef CONFIG_DISABLE_MQUEUE
199  TSTATE_WAIT_MQNOTEMPTY, /* BLOCKED - Waiting for a MQ to become not empty. */
200  TSTATE_WAIT_MQNOTFULL, /* BLOCKED - Waiting for a MQ to become not full. */
201 #endif
202 #ifdef CONFIG_PAGING
203  TSTATE_WAIT_PAGEFILL, /* BLOCKED - Waiting for page fill */
204 #endif
205  NUM_TASK_STATES /* Must be last */
206 };
207 typedef enum tstate_e tstate_t;
208 
209 /* The following definitions are determined by tstate_t */
210 
211 #define FIRST_READY_TO_RUN_STATE TSTATE_TASK_READYTORUN
212 #define LAST_READY_TO_RUN_STATE TSTATE_TASK_RUNNING
213 #define FIRST_BLOCKED_STATE TSTATE_TASK_INACTIVE
214 #define LAST_BLOCKED_STATE (NUM_TASK_STATES-1)
215 
216 /* The following is the form of a thread start-up function */
217 
218 typedef CODE void (*start_t)(void);
219 
223 union entry_u {
225  main_t main;
226 };
227 typedef union entry_u entry_t;
228 
229 /* This is the type of the function called at task startup */
230 
231 #ifdef CONFIG_SCHED_STARTHOOK
232 typedef CODE void (*starthook_t)(FAR void *arg);
233 #endif
234 
235 /* These are the types of the functions that are executed with exit() is called
236  * (if registered via atexit() on on_exit()).
237  */
238 
239 #ifdef CONFIG_SCHED_ATEXIT
240 typedef CODE void (*atexitfunc_t)(void);
241 #endif
242 
243 #ifdef CONFIG_SCHED_ONEXIT
244 typedef CODE void (*onexitfunc_t)(int exitcode, FAR void *arg);
245 #endif
246 
247 /* struct child_status_s *********************************************************/
252 #ifdef CONFIG_SCHED_CHILD_STATUS
254  FAR struct child_status_s *flink;
255 
256  uint8_t ch_flags; /* Child status: See CHILD_FLAG_* definitions */
257  pid_t ch_pid; /* Child task ID */
258  int ch_status; /* Child exit status */
259 };
260 #endif
261 
262 /* struct dspace_s ***************************************************************/
263 
268 #ifdef CONFIG_PIC
269 struct dspace_s {
270  /* The life of the structure allocation is determined by this reference
271  * count. This count is number of threads that shared the same D-Space.
272  * This includes the parent task as well as any pthreads created by the
273  * parent task or any of its child threads.
274  */
275 
276  uint16_t crefs;
277 
278  /* This is the allocated D-Space memory region. This may be a physical
279  * address allocated with kmm_malloc(), or it may be virtual address associated
280  * with an address environment (if CONFIG_ARCH_ADDRENV=y).
281  */
282 
283  FAR uint8_t *region;
284 };
285 #endif
286 
287 /* struct task_group_s ***********************************************************/
288 /* All threads created by pthread_create belong in the same task group (along with
289  * the thread of the original task). struct task_group_s is a shared structure
290  * referenced by the TCB of each thread that is a member of the task group.
291  *
292  * This structure should contain *all* resources shared by tasks and threads that
293  * belong to the same task group:
294  *
295  * Child exit status
296  * Environment variables
297  * PIC data space and address environments
298  * File descriptors
299  * FILE streams
300  * Sockets
301  * Address environments.
302  *
303  * Each instance of struct task_group_s is reference counted. Each instance is
304  * created with a reference count of one. The reference incremented when each
305  * thread joins the group and decremented when each thread exits, leaving the
306  * group. When the reference count decrements to zero, the struct task_group_s
307  * is free.
308  */
309 
310 #ifdef HAVE_TASK_GROUP
311 
312 #ifndef CONFIG_DISABLE_PTHREAD
313 struct join_s; /* Forward reference */
314 /* Defined in kernel/pthread/pthread.h */
315 #endif
316 
317 struct task_group_s {
318 #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV)
319  struct task_group_s *flink; /* Supports a singly linked list */
320  gid_t tg_gid; /* The ID of this task group */
321 #endif
322 #ifdef HAVE_GROUP_MEMBERS
323  gid_t tg_pgid; /* The ID of the parent task group */
324 #endif
325 #if !defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_SCHED_HAVE_PARENT)
326  pid_t tg_task; /* The ID of the task within the group */
327 #endif
328  uint8_t tg_flags; /* See GROUP_FLAG_* definitions */
329 
330  /* Group membership ********************************************************** */
331 
332  uint8_t tg_nmembers; /* Number of members in the group */
333 #ifdef HAVE_GROUP_MEMBERS
334  uint8_t tg_mxmembers; /* Number of members in allocation */
335  FAR pid_t *tg_members; /* Members of the group */
336 #endif
337 
338 #if defined(CONFIG_SCHED_ATEXIT) && !defined(CONFIG_SCHED_ONEXIT)
339  /* atexit support *********************************************************** */
340 
341 #if defined(CONFIG_SCHED_ATEXIT_MAX) && CONFIG_SCHED_ATEXIT_MAX > 1
342  atexitfunc_t tg_atexitfunc[CONFIG_SCHED_ATEXIT_MAX];
343 #else
344  atexitfunc_t tg_atexitfunc; /* Called when exit is called. */
345 #endif
346 #endif
347 
348 #ifdef CONFIG_SCHED_ONEXIT
349  /* on_exit support ********************************************************** */
350 
351 #if defined(CONFIG_SCHED_ONEXIT_MAX) && CONFIG_SCHED_ONEXIT_MAX > 1
352  onexitfunc_t tg_onexitfunc[CONFIG_SCHED_ONEXIT_MAX];
353  FAR void *tg_onexitarg[CONFIG_SCHED_ONEXIT_MAX];
354 #else
355  onexitfunc_t tg_onexitfunc; /* Called when exit is called. */
356  FAR void *tg_onexitarg; /* The argument passed to the function */
357 #endif
358 #endif
359 
360 #if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS)
361  /* Child exit status ********************************************************* */
362 
363  FAR struct child_status_s *tg_children; /* Head of a list of child status */
364 #endif
365 
366 #if defined(CONFIG_SCHED_WAITPID) && !defined(CONFIG_SCHED_HAVE_PARENT)
367  /* waitpid support *********************************************************** */
368  /* Simple mechanism used only when there is no support for SIGCHLD */
369 
370  sem_t tg_exitsem; /* Support for waitpid */
371  int *tg_statloc; /* Location to return exit status */
372 #endif
373 
374 #ifndef CONFIG_DISABLE_PTHREAD
375  /* Pthreads ****************************************************************** */
376  /* Pthread join Info: */
377  sem_t tg_joinsem; /* Mutually exclusive access to join data */
378  FAR struct join_s *tg_joinhead; /* Head of a list of join data */
379  FAR struct join_s *tg_jointail; /* Tail of a list of join data */
380  uint8_t tg_nkeys; /* Number pthread keys allocated */
381 #endif
382 
383 #ifndef CONFIG_DISABLE_SIGNALS
384  /* POSIX Signal Control Fields *********************************************** */
385 
386  sq_queue_t sigpendingq; /* List of pending signals */
387 #endif
388 
389 #ifndef CONFIG_DISABLE_ENVIRON
390  /* Environment variables ***************************************************** */
391 
392  size_t tg_envsize; /* Size of environment string allocation */
393  FAR char *tg_envp; /* Allocated environment strings */
394 #endif
395 
396  /* PIC data space and address environments *********************************** */
397  /* Logically the PIC data space belongs here (see struct dspace_s). The
398  * current logic needs review: There are differences in the away that the
399  * life of the PIC data is managed.
400  */
401 
402 #if CONFIG_NFILE_DESCRIPTORS > 0
403  /* File descriptors ********************************************************** */
404 
405  struct filelist tg_filelist; /* Maps file descriptor to file */
406 #endif
407 
408 #if CONFIG_NFILE_STREAMS > 0
409  /* FILE streams ************************************************************** */
410  /* In a flat, single-heap build. The stream list is allocated with this
411  * structure. But kernel mode with a kernel allocator, it must be separately
412  * allocated using a user-space allocator.
413  */
414 
415 #if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \
416  defined(CONFIG_MM_KERNEL_HEAP)
417  FAR struct streamlist *tg_streamlist;
418 #else
419  struct streamlist tg_streamlist; /* Holds C buffered I/O info */
420 #endif
421 #endif
422 
423 #if CONFIG_NSOCKET_DESCRIPTORS > 0
424  /* Sockets ******************************************************************* */
425 
426  struct socketlist tg_socketlist; /* Maps socket descriptor to socket */
427 #endif
428 
429 #ifndef CONFIG_DISABLE_MQUEUE
430  /* POSIX Named Message Queue Fields ****************************************** */
431 
432  sq_queue_t tg_msgdesq; /* List of opened message queues */
433 #endif
434 
435 #ifdef CONFIG_ARCH_ADDRENV
436  /* Address Environment ******************************************************* */
437 
438  group_addrenv_t tg_addrenv; /* Task group address environment */
439 #endif
440 
441 #ifdef CONFIG_MM_SHM
442  /* Shared Memory ************************************************************* */
443 
444  struct group_shm_s tg_shm; /* Task shared memory logic */
445 #endif
446 };
447 #endif
448 
449 /* struct tcb_s ******************************************************************/
450 
451 FAR struct wdog_s; /* Forward reference */
456 struct tcb_s {
457  /* Fields used to support list management ************************************ */
458 
459  FAR struct tcb_s *flink; /* Doubly linked list */
460  FAR struct tcb_s *blink;
461 
462  /* Task Group **************************************************************** */
463 
464 #ifdef HAVE_TASK_GROUP
465  FAR struct task_group_s *group; /* Pointer to shared task group data */
466 #endif
467 
468  /* Task Management Fields **************************************************** */
469 
470  pid_t pid; /* This is the ID of the thread */
471 
472 #ifdef CONFIG_SCHED_HAVE_PARENT /* Support parent-child relationship */
473 #ifndef HAVE_GROUP_MEMBERS /* Don't know pids of group members */
474  pid_t ppid; /* This is the ID of the parent thread */
475 #ifndef CONFIG_SCHED_CHILD_STATUS /* Retain child thread status */
476  uint16_t nchildren; /* This is the number active children */
477 #endif
478 #endif
479 #endif /* CONFIG_SCHED_HAVE_PARENT */
480 
481  start_t start; /* Thread start function */
482  entry_t entry; /* Entry Point into the thread */
483  uint8_t sched_priority; /* Current priority of the thread */
484 
485 #ifdef CONFIG_PRIORITY_INHERITANCE
486 #if CONFIG_SEM_NNESTPRIO > 0
487  uint8_t npend_reprio; /* Number of nested reprioritizations */
488  uint8_t pend_reprios[CONFIG_SEM_NNESTPRIO];
489 #endif
490  uint8_t base_priority; /* "Normal" priority of the thread */
491 #endif
492 
493  uint8_t task_state; /* Current state of the thread */
494  uint16_t flags; /* Misc. general status flags */
495  int16_t lockcount; /* 0=preemptable (not-locked) */
496 
497 #if CONFIG_RR_INTERVAL > 0
498  int timeslice; /* RR timeslice interval remaining */
499 #endif
500  FAR struct wdog_s *waitdog; /* All timed waits used this wdog */
501 
502  /* Stack-Related Fields ****************************************************** */
503 
504  size_t adj_stack_size; /* Stack size after adjustment */
505  /* for hardware, processor, etc. */
506  /* (for debug purposes only) */
507  FAR void *stack_alloc_ptr; /* Pointer to allocated stack */
508  /* Need to deallocate stack */
509  FAR void *adj_stack_ptr; /* Adjusted stack_alloc_ptr for HW */
510  /* The initial stack pointer value */
511 
512  /* External Module Support *************************************************** */
513 
514 #ifdef CONFIG_PIC
515  FAR struct dspace_s *dspace; /* Allocated area for .bss and .data */
516 #endif
517 
518  /* POSIX Semaphore Control Fields ******************************************** */
519 
520  sem_t *waitsem; /* Semaphore ID waiting on */
521 
522  /* POSIX Signal Control Fields *********************************************** */
523 
524 #ifndef CONFIG_DISABLE_SIGNALS
525  sigset_t sigprocmask; /* Signals that are blocked */
526  sigset_t sigwaitmask; /* Waiting for pending signals */
527  sq_queue_t sigactionq; /* List of actions for signals */
528  sq_queue_t sigpendactionq; /* List of pending signal actions */
529  sq_queue_t sigpostedq; /* List of posted signals */
530  siginfo_t sigunbinfo; /* Signal info when task unblocked */
531 #endif
532 
533  /* POSIX Named Message Queue Fields ****************************************** */
534 
535 #ifndef CONFIG_DISABLE_MQUEUE
536  FAR struct mqueue_inode_s *msgwaitq; /* Waiting for this message queue */
537 #endif
538 
539  /* Library related fields **************************************************** */
540 
541  int pterrno; /* Current per-thread errno */
542 
543  /* State save areas ********************************************************** */
544  /* The form and content of these fields are platform-specific. */
545 
546  struct xcptcontext xcp; /* Interrupt register save area */
547 
548 #if CONFIG_TASK_NAME_SIZE > 0
549  char name[CONFIG_TASK_NAME_SIZE + 1]; /* Task name (with NUL terminator) */
550 #endif
551 
552 #ifdef CONFIG_DEBUG_MM_HEAPINFO
556 #endif
557 };
558 
559 /* struct task_tcb_s *************************************************************/
568 struct task_tcb_s {
569  /* Common TCB fields ********************************************************* */
570 
571  struct tcb_s cmn; /* Common TCB fields */
572 
573  /* Task Management Fields **************************************************** */
574 
575 #ifdef CONFIG_SCHED_STARTHOOK
576  starthook_t starthook; /* Task startup function */
577  FAR void *starthookarg; /* The argument passed to the function */
578 #endif
579 
580  /* Values needed to restart a task ******************************************* */
581 
582  uint8_t init_priority; /* Initial priority of the task */
583  FAR char **argv; /* Name+start-up parameters */
584 };
585 
586 /* struct pthread_tcb_s **********************************************************/
587 
588 #ifndef CONFIG_DISABLE_PTHREAD
589 
598  /* Common TCB fields ********************************************************* */
599 
600  struct tcb_s cmn; /* Common TCB fields */
601 
602  /* Task Management Fields **************************************************** */
603 
604  pthread_addr_t arg; /* Startup argument */
605  FAR void *joininfo; /* Detach-able info to support join */
606 
607  /* POSIX Thread Specific Data ************************************************ */
608 
609 #if CONFIG_NPTHREAD_KEYS > 0
610  FAR void *pthread_data[CONFIG_NPTHREAD_KEYS];
611 #endif
612 #if defined(CONFIG_BUILD_PROTECTED)
613  struct pthread_region_s *region;
614 #endif
615 };
616 #endif /* !CONFIG_DISABLE_PTHREAD */
617 
618 /* This is the callback type used by sched_foreach() */
619 
620 typedef void (*sched_foreach_t)(FAR struct tcb_s *tcb, FAR void *arg);
621 
622 #endif /* __ASSEMBLY__ */
623 
624 /********************************************************************************
625  * Public Data
626  ********************************************************************************/
627 
628 #ifndef __ASSEMBLY__
629 #undef EXTERN
630 #if defined(__cplusplus)
631 #define EXTERN extern "C"
632 extern "C" {
633 #else
634 #define EXTERN extern
635 #endif
636 
637 /********************************************************************************
638  * Public Function Prototypes
639  ********************************************************************************/
640 
641 /* TCB helpers ******************************************************************/
642 
653 FAR struct tcb_s *sched_self(void);
654 
655 /* sched_foreach
656  */
668 void sched_foreach(sched_foreach_t handler, FAR void *arg);
669 
680 FAR struct tcb_s *sched_gettcb(pid_t pid);
681 
682 /* File system helpers **********************************************************/
683 /* These functions all extract lists from the group structure assocated with the
684  * currently executing task.
685  */
686 
687 #if CONFIG_NFILE_DESCRIPTORS > 0
688 
692 FAR struct filelist *sched_getfiles(void);
696 #if CONFIG_NFILE_STREAMS > 0
697 
703 FAR struct streamlist *sched_getstreams(void);
704 #endif /* CONFIG_NFILE_STREAMS */
705 #endif /* CONFIG_NFILE_DESCRIPTORS */
706 
707 #if CONFIG_NSOCKET_DESCRIPTORS > 0
708 FAR struct socketlist *sched_getsockets(void);
709 #endif /* CONFIG_NSOCKET_DESCRIPTORS */
710 
711 /********************************************************************************
712  * Name: task_starthook
713  *
714  * Description:
715  * Configure a start hook... a function that will be called on the thread
716  * of the new task before the new task's main entry point is called.
717  * The start hook is useful, for example, for setting up automatic
718  * configuration of C++ constructors.
719  *
720  * Inputs:
721  * tcb - The new, unstarted task task that needs the start hook
722  * starthook - The pointer to the start hook function
723  * arg - The argument to pass to the start hook function.
724  *
725  * Return:
726  * None
727  *
728  ********************************************************************************/
729 
730 #ifdef CONFIG_SCHED_STARTHOOK
731 
735 void task_starthook(FAR struct task_tcb_s *tcb, starthook_t starthook, FAR void *arg);
739 #endif
740 
741 /********************************************************************************
742  * Internal vfork support. The overall sequence is:
743  *
744  * 1) User code calls vfork(). vfork() is provided in architecture-specific
745  * code.
746  * 2) vfork()and calls task_vforksetup().
747  * 3) task_vforksetup() allocates and configures the child task's TCB. This
748  * consists of:
749  * - Allocation of the child task's TCB.
750  * - Initialization of file descriptors and streams
751  * - Configuration of environment variables
752  * - Setup the intput parameters for the task.
753  * - Initialization of the TCB (including call to up_initial_state()
754  * 4) vfork() provides any additional operating context. vfork must:
755  * - Allocate and initialize the stack
756  * - Initialize special values in any CPU registers that were not
757  * already configured by up_initial_state()
758  * 5) vfork() then calls task_vforkstart()
759  * 6) task_vforkstart() then executes the child thread.
760  *
761  * task_vforkabort() may be called if an error occurs between steps 3 and 6.
762  *
763  ********************************************************************************/
768 FAR struct task_tcb_s *task_vforksetup(start_t retaddr);
772 pid_t task_vforkstart(FAR struct task_tcb_s *child);
776 void task_vforkabort(FAR struct task_tcb_s *child, int errcode);
780 #undef EXTERN
781 #if defined(__cplusplus)
782 }
783 #endif
784 #endif /* __ASSEMBLY__ */
785 
786 #endif /* __INCLUDE_TINYARA_SCHED_H */
sigset_t sigwaitmask
Definition: sched.h:526
int curr_alloc_size
Definition: sched.h:553
int16_t lockcount
Definition: sched.h:495
FAR struct tcb_s * sched_gettcb(pid_t pid)
Give a task ID, look up the corresponding TCB.
uint8_t tg_mxmembers
Definition: sched.h:334
This structure describes a reference counted D-Space region. This must be a separately allocated "bre...
Definition: sched.h:269
uint8_t base_priority
Definition: sched.h:490
start_t start
Definition: sched.h:481
sq_queue_t sigpendactionq
Definition: sched.h:528
CODE void(* start_t)(void)
Definition: sched.h:218
void(* sched_foreach_t)(FAR struct tcb_s *tcb, FAR void *arg)
Definition: sched.h:620
FAR struct wdog_s * waitdog
Definition: sched.h:500
int timeslice
Definition: sched.h:498
FAR struct child_status_s * tg_children
Definition: sched.h:363
FAR void * pthread_addr_t
Definition: pthread.h:202
pid_t tg_task
Definition: sched.h:326
size_t tg_envsize
Definition: sched.h:392
main_t main
Definition: sched.h:225
This structure is used to maintin information about child tasks. pthreads work differently, they have join information. This is only for child tasks.
Definition: sched.h:253
structure for header queue
Definition: queue.h:113
CODE void(* starthook_t)(FAR void *arg)
Definition: sched.h:232
FAR pid_t * tg_members
Definition: sched.h:335
starthook_t starthook
Definition: sched.h:576
FAR void * joininfo
Definition: sched.h:605
FAR void * tg_onexitarg
Definition: sched.h:356
sq_queue_t sigactionq
Definition: sched.h:527
int ch_status
Definition: sched.h:258
uint8_t task_state
Definition: sched.h:493
Pthread APIs.
enum tstate_e tstate_t
Definition: sched.h:207
uint8_t tg_nkeys
Definition: sched.h:380
uint8_t tg_flags
Definition: sched.h:328
siginfo_t sigunbinfo
Definition: sched.h:530
FAR struct join_s * tg_jointail
Definition: sched.h:379
size_t adj_stack_size
Definition: sched.h:504
Structure for using to pass parameters to/from signal handlers.
Definition: signal.h:240
sem_t * waitsem
Definition: sched.h:520
int peak_alloc_size
Definition: sched.h:554
FAR char ** argv
Definition: sched.h:583
Queue APIs.
This is the common part of the task control block (TCB). The TCB is the heart of the TinyAra task-con...
Definition: sched.h:456
pid_t pid
Definition: sched.h:470
pthread_addr_t arg
Definition: sched.h:604
Signal APIs.
Mqueue APIs.
FAR void * starthookarg
Definition: sched.h:577
sq_queue_t sigpostedq
Definition: sched.h:529
FAR struct join_s * tg_joinhead
Definition: sched.h:378
int pterrno
Definition: sched.h:541
uint16_t flags
Definition: sched.h:494
FAR struct tcb_s * blink
Definition: sched.h:460
gid_t tg_gid
Definition: sched.h:320
FAR struct tcb_s * sched_self(void)
returns the TCB of the currently running task (i.e., the caller)
Structure for Task Group Information.
Definition: sched.h:317
CODE void(* atexitfunc_t)(void)
Definition: sched.h:240
entry_t entry
Definition: sched.h:482
uint8_t ch_flags
Definition: sched.h:256
tstate_e
This is the type of the task_state field of the TCB. NOTE: the order and content of this enumeration ...
Definition: sched.h:187
onexitfunc_t tg_onexitfunc
Definition: sched.h:355
FAR void * stack_alloc_ptr
Definition: sched.h:507
FAR struct task_group_s * group
Definition: sched.h:465
FAR char * tg_envp
Definition: sched.h:393
gid_t tg_pgid
Definition: sched.h:323
Semaphore APIs.
void sched_foreach(sched_foreach_t handler, FAR void *arg)
enumerate over each task and provide the TCB of each task or thread to a callback function...
struct task_group_s * flink
Definition: sched.h:319
FAR struct mqueue_inode_s * msgwaitq
Definition: sched.h:536
This is the particular form of the task control block (TCB) structure used by pthreads. There are two TCB forms: one for pthreads and one for tasks. Both share the common TCB fields (which must appear at the top of the structure) plus additional fields unique to tasks and threads. Having separate structures for tasks and pthreads adds some complexity, but saves memory in that it prevents pthreads from being burdened with the overhead required for tasks (and vice versa).
Definition: sched.h:597
sq_queue_t sigpendingq
Definition: sched.h:386
uint8_t tg_nmembers
Definition: sched.h:332
uint8_t init_priority
Definition: sched.h:582
Structure of generic semaphore.
Definition: semaphore.h:115
pthread_addr_t(* pthread_startroutine_t)(pthread_addr_t)
Definition: pthread.h:205
sem_t tg_joinsem
Definition: sched.h:377
This is the entry point into the main thread of the task or into a created pthread within the task...
Definition: sched.h:223
uint16_t crefs
Definition: sched.h:276
FAR struct child_status_s * flink
Definition: sched.h:254
FAR struct dspace_s * dspace
Definition: sched.h:515
uint8_t sched_priority
Definition: sched.h:483
uint32_t sigset_t
Definition: signal.h:213
FAR void * adj_stack_ptr
Definition: sched.h:509
int num_alloc_free
Definition: sched.h:555
sigset_t sigprocmask
Definition: sched.h:525
FAR struct tcb_s * flink
Definition: sched.h:459
Time APIs.
This is the particular form of the task control block (TCB) structure used by tasks (and kernel threa...
Definition: sched.h:568
Structure of pthread region configuration.
Definition: pthread.h:212
CODE void(* onexitfunc_t)(int exitcode, FAR void *arg)
Definition: sched.h:244
FAR uint8_t * region
Definition: sched.h:283
pthread_startroutine_t pthread
Definition: sched.h:224
pid_t ch_pid
Definition: sched.h:257
sq_queue_t tg_msgdesq
Definition: sched.h:432