source: rtems-docs/c-user/task_manager.rst @ 23b1c10

5
Last change on this file since 23b1c10 was 23b1c10, checked in by Sebastian Huber <sebastian.huber@…>, on 01/17/17 at 13:17:33

c-user: Fix typo

  • Property mode set to 100644
File size: 58.0 KB
Line 
1.. comment SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. COMMENT: COPYRIGHT (c) 1988-2008.
4.. COMMENT: On-Line Applications Research Corporation (OAR).
5.. COMMENT: All rights reserved.
6
7Task Manager
8************
9
10.. index:: tasks
11
12Introduction
13============
14
15The task manager provides a comprehensive set of directives to create, delete,
16and administer tasks.  The directives provided by the task manager are:
17
18- rtems_task_create_ - Create a task
19
20- rtems_task_ident_ - Get ID of a task
21
22- rtems_task_self_ - Obtain ID of caller
23
24- rtems_task_start_ - Start a task
25
26- rtems_task_restart_ - Restart a task
27
28- rtems_task_delete_ - Delete a task
29
30- rtems_task_suspend_ - Suspend a task
31
32- rtems_task_resume_ - Resume a task
33
34- rtems_task_is_suspended_ - Determine if a task is suspended
35
36- rtems_task_set_priority_ - Set task priority
37
38- rtems_task_get_priority_ - Get task priority
39
40- rtems_task_mode_ - Change current task's mode
41
42- rtems_task_wake_after_ - Wake up after interval
43
44- rtems_task_wake_when_ - Wake up when specified
45
46- rtems_task_iterate_ - Iterate Over Tasks
47
48Background
49==========
50
51Task Definition
52---------------
53.. index:: task, definition
54
55Many definitions of a task have been proposed in computer literature.
56Unfortunately, none of these definitions encompasses all facets of the concept
57in a manner which is operating system independent.  Several of the more common
58definitions are provided to enable each user to select a definition which best
59matches their own experience and understanding of the task concept:
60
61- a "dispatchable" unit.
62
63- an entity to which the processor is allocated.
64
65- an atomic unit of a real-time, multiprocessor system.
66
67- single threads of execution which concurrently compete for resources.
68
69- a sequence of closely related computations which can execute concurrently
70  with other computational sequences.
71
72From RTEMS' perspective, a task is the smallest thread of execution which can
73compete on its own for system resources.  A task is manifested by the existence
74of a task control block (TCB).
75
76Task Control Block
77------------------
78
79The Task Control Block (TCB) is an RTEMS defined data structure which contains
80all the information that is pertinent to the execution of a task.  During
81system initialization, RTEMS reserves a TCB for each task configured.  A TCB is
82allocated upon creation of the task and is returned to the TCB free list upon
83deletion of the task.
84
85The TCB's elements are modified as a result of system calls made by the
86application in response to external and internal stimuli.  TCBs are the only
87RTEMS internal data structure that can be accessed by an application via user
88extension routines.  The TCB contains a task's name, ID, current priority,
89current and starting states, execution mode, TCB user extension pointer,
90scheduling control structures, as well as data required by a blocked task.
91
92A task's context is stored in the TCB when a task switch occurs.  When the task
93regains control of the processor, its context is restored from the TCB.  When a
94task is restarted, the initial state of the task is restored from the starting
95context area in the task's TCB.
96
97Task States
98-----------
99.. index:: task states
100
101A task may exist in one of the following five states:
102
103- *executing* - Currently scheduled to the CPU
104
105- *ready* - May be scheduled to the CPU
106
107- *blocked* - Unable to be scheduled to the CPU
108
109- *dormant* - Created task that is not started
110
111- *non-existent* - Uncreated or deleted task
112
113An active task may occupy the executing, ready, blocked or dormant state,
114otherwise the task is considered non-existent.  One or more tasks may be active
115in the system simultaneously.  Multiple tasks communicate, synchronize, and
116compete for system resources with each other via system calls.  The multiple
117tasks appear to execute in parallel, but actually each is dispatched to the CPU
118for periods of time determined by the RTEMS scheduling algorithm.  The
119scheduling of a task is based on its current state and priority.
120
121Task Priority
122-------------
123.. index:: task priority
124.. index:: priority, task
125.. index:: rtems_task_priority
126
127A task's priority determines its importance in relation to the other tasks
128executing on the same processor.  RTEMS supports 255 levels of priority ranging
129from 1 to 255.  The data type ``rtems_task_priority`` is used to store task
130priorities.
131
132Tasks of numerically smaller priority values are more important tasks than
133tasks of numerically larger priority values.  For example, a task at priority
134level 5 is of higher privilege than a task at priority level 10.  There is no
135limit to the number of tasks assigned to the same priority.
136
137Each task has a priority associated with it at all times.  The initial value of
138this priority is assigned at task creation time.  The priority of a task may be
139changed at any subsequent time.
140
141Priorities are used by the scheduler to determine which ready task will be
142allowed to execute.  In general, the higher the logical priority of a task, the
143more likely it is to receive processor execution time.
144
145Task Mode
146---------
147.. index:: task mode
148.. index:: rtems_task_mode
149
150A task's execution mode is a combination of the following four components:
151
152- preemption
153
154- ASR processing
155
156- timeslicing
157
158- interrupt level
159
160It is used to modify RTEMS' scheduling process and to alter the execution
161environment of the task.  The data type ``rtems_task_mode`` is used to manage
162the task execution mode.
163
164.. index:: preemption
165
166The preemption component allows a task to determine when control of the
167processor is relinquished.  If preemption is disabled (``RTEMS_NO_PREEMPT``),
168the task will retain control of the processor as long as it is in the executing
169state - even if a higher priority task is made ready.  If preemption is enabled
170(``RTEMS_PREEMPT``) and a higher priority task is made ready, then the
171processor will be taken away from the current task immediately and given to the
172higher priority task.
173
174.. index:: timeslicing
175
176The timeslicing component is used by the RTEMS scheduler to determine how the
177processor is allocated to tasks of equal priority.  If timeslicing is enabled
178(``RTEMS_TIMESLICE``), then RTEMS will limit the amount of time the task can
179execute before the processor is allocated to another ready task of equal
180priority. The length of the timeslice is application dependent and specified in
181the Configuration Table.  If timeslicing is disabled (``RTEMS_NO_TIMESLICE``),
182then the task will be allowed to execute until a task of higher priority is
183made ready.  If ``RTEMS_NO_PREEMPT`` is selected, then the timeslicing component
184is ignored by the scheduler.
185
186The asynchronous signal processing component is used to determine when received
187signals are to be processed by the task.  If signal processing is enabled
188(``RTEMS_ASR``), then signals sent to the task will be processed the next time
189the task executes.  If signal processing is disabled (``RTEMS_NO_ASR``), then
190all signals received by the task will remain posted until signal processing is
191enabled.  This component affects only tasks which have established a routine to
192process asynchronous signals.
193
194.. index:: interrupt level, task
195
196The interrupt level component is used to determine which interrupts will be
197enabled when the task is executing. ``RTEMS_INTERRUPT_LEVEL(n)`` specifies that
198the task will execute at interrupt level n.
199
200.. list-table::
201 :class: rtems-table
202
203 * - ``RTEMS_PREEMPT``
204   - enable preemption (default)
205 * - ``RTEMS_NO_PREEMPT``
206   - disable preemption
207 * - ``RTEMS_NO_TIMESLICE``
208   - disable timeslicing (default)
209 * - ``RTEMS_TIMESLICE``
210   - enable timeslicing
211 * - ``RTEMS_ASR``
212   - enable ASR processing (default)
213 * - ``RTEMS_NO_ASR``
214   - disable ASR processing
215 * - ``RTEMS_INTERRUPT_LEVEL(0)``
216   - enable all interrupts (default)
217 * - ``RTEMS_INTERRUPT_LEVEL(n)``
218   - execute at interrupt level n
219
220The set of default modes may be selected by specifying the
221``RTEMS_DEFAULT_MODES`` constant.
222
223Accessing Task Arguments
224------------------------
225.. index:: task arguments
226.. index:: task prototype
227
228All RTEMS tasks are invoked with a single argument which is specified when they
229are started or restarted.  The argument is commonly used to communicate startup
230information to the task.  The simplest manner in which to define a task which
231accesses it argument is:
232
233.. index:: rtems_task
234
235.. code-block:: c
236
237    rtems_task user_task(
238        rtems_task_argument argument
239    );
240
241Application tasks requiring more information may view this single argument as
242an index into an array of parameter blocks.
243
244Floating Point Considerations
245-----------------------------
246.. index:: floating point
247
248Creating a task with the ``RTEMS_FLOATING_POINT`` attribute flag results in
249additional memory being allocated for the TCB to store the state of the numeric
250coprocessor during task switches.  This additional memory is *NOT* allocated for
251``RTEMS_NO_FLOATING_POINT`` tasks. Saving and restoring the context of a
252``RTEMS_FLOATING_POINT`` task takes longer than that of a
253``RTEMS_NO_FLOATING_POINT`` task because of the relatively large amount of time
254required for the numeric coprocessor to save or restore its computational
255state.
256
257Since RTEMS was designed specifically for embedded military applications which
258are floating point intensive, the executive is optimized to avoid unnecessarily
259saving and restoring the state of the numeric coprocessor.  The state of the
260numeric coprocessor is only saved when a ``RTEMS_FLOATING_POINT`` task is
261dispatched and that task was not the last task to utilize the coprocessor.  In
262a system with only one ``RTEMS_FLOATING_POINT`` task, the state of the numeric
263coprocessor will never be saved or restored.
264
265Although the overhead imposed by ``RTEMS_FLOATING_POINT`` tasks is minimal,
266some applications may wish to completely avoid the overhead associated with
267``RTEMS_FLOATING_POINT`` tasks and still utilize a numeric coprocessor.  By
268preventing a task from being preempted while performing a sequence of floating
269point operations, a ``RTEMS_NO_FLOATING_POINT`` task can utilize the numeric
270coprocessor without incurring the overhead of a ``RTEMS_FLOATING_POINT``
271context switch.  This approach also avoids the allocation of a floating point
272context area.  However, if this approach is taken by the application designer,
273NO tasks should be created as ``RTEMS_FLOATING_POINT`` tasks.  Otherwise, the
274floating point context will not be correctly maintained because RTEMS assumes
275that the state of the numeric coprocessor will not be altered by
276``RTEMS_NO_FLOATING_POINT`` tasks.
277
278If the supported processor type does not have hardware floating capabilities or
279a standard numeric coprocessor, RTEMS will not provide built-in support for
280hardware floating point on that processor.  In this case, all tasks are
281considered ``RTEMS_NO_FLOATING_POINT`` whether created as
282``RTEMS_FLOATING_POINT`` or ``RTEMS_NO_FLOATING_POINT`` tasks.  A floating
283point emulation software library must be utilized for floating point
284operations.
285
286On some processors, it is possible to disable the floating point unit
287dynamically.  If this capability is supported by the target processor, then
288RTEMS will utilize this capability to enable the floating point unit only for
289tasks which are created with the ``RTEMS_FLOATING_POINT`` attribute.  The
290consequence of a ``RTEMS_NO_FLOATING_POINT`` task attempting to access the
291floating point unit is CPU dependent but will generally result in an exception
292condition.
293
294Building a Task Attribute Set
295-----------------------------
296.. index:: task attributes, building
297
298In general, an attribute set is built by a bitwise OR of the desired
299components.  The set of valid task attribute components is listed below:
300
301.. list-table::
302 :class: rtems-table
303
304 * - ``RTEMS_NO_FLOATING_POINT``
305   - does not use coprocessor (default)
306 * - ``RTEMS_FLOATING_POINT``
307   - uses numeric coprocessor
308 * - ``RTEMS_LOCAL``
309   - local task (default)
310 * - ``RTEMS_GLOBAL``
311   - global task
312
313Attribute values are specifically designed to be mutually exclusive, therefore
314bitwise OR and addition operations are equivalent as long as each attribute
315appears exactly once in the component list.  A component listed as a default is
316not required to appear in the component list, although it is a good programming
317practice to specify default components.  If all defaults are desired, then
318``RTEMS_DEFAULT_ATTRIBUTES`` should be used.
319
320This example demonstrates the attribute_set parameter needed to create a local
321task which utilizes the numeric coprocessor.  The attribute_set parameter could
322be ``RTEMS_FLOATING_POINT`` or ``RTEMS_LOCAL | RTEMS_FLOATING_POINT``.  The
323attribute_set parameter can be set to ``RTEMS_FLOATING_POINT`` because
324``RTEMS_LOCAL`` is the default for all created tasks.  If the task were global
325and used the numeric coprocessor, then the attribute_set parameter would be
326``RTEMS_GLOBAL | RTEMS_FLOATING_POINT``.
327
328Building a Mode and Mask
329------------------------
330.. index:: task mode, building
331
332In general, a mode and its corresponding mask is built by a bitwise OR of the
333desired components.  The set of valid mode constants and each mode's
334corresponding mask constant is listed below:
335
336.. list-table::
337 :class: rtems-table
338
339 * - ``RTEMS_PREEMPT``
340   - is masked by ``RTEMS_PREEMPT_MASK`` and enables preemption
341 * - ``RTEMS_NO_PREEMPT``
342   - is masked by ``RTEMS_PREEMPT_MASK`` and disables preemption
343 * - ``RTEMS_NO_TIMESLICE``
344   - is masked by ``RTEMS_TIMESLICE_MASK`` and disables timeslicing
345 * - ``RTEMS_TIMESLICE``
346   - is masked by ``RTEMS_TIMESLICE_MASK`` and enables timeslicing
347 * - ``RTEMS_ASR``
348   - is masked by ``RTEMS_ASR_MASK`` and enables ASR processing
349 * - ``RTEMS_NO_ASR``
350   - is masked by ``RTEMS_ASR_MASK`` and disables ASR processing
351 * - ``RTEMS_INTERRUPT_LEVEL(0)``
352   - is masked by ``RTEMS_INTERRUPT_MASK`` and enables all interrupts
353 * - ``RTEMS_INTERRUPT_LEVEL(n)``
354   - is masked by ``RTEMS_INTERRUPT_MASK`` and sets interrupts level n
355
356Mode values are specifically designed to be mutually exclusive, therefore
357bitwise OR and addition operations are equivalent as long as each mode appears
358exactly once in the component list.  A mode component listed as a default is
359not required to appear in the mode component list, although it is a good
360programming practice to specify default components.  If all defaults are
361desired, the mode ``RTEMS_DEFAULT_MODES`` and the mask ``RTEMS_ALL_MODE_MASKS``
362should be used.
363
364The following example demonstrates the mode and mask parameters used with the
365``rtems_task_mode`` directive to place a task at interrupt level 3 and make it
366non-preemptible.  The mode should be set to ``RTEMS_INTERRUPT_LEVEL(3) |
367RTEMS_NO_PREEMPT`` to indicate the desired preemption mode and interrupt level,
368while the mask parameter should be set to ``RTEMS_INTERRUPT_MASK |
369RTEMS_NO_PREEMPT_MASK`` to indicate that the calling task's interrupt level and
370preemption mode are being altered.
371
372Operations
373==========
374
375Creating Tasks
376--------------
377
378The ``rtems_task_create`` directive creates a task by allocating a task control
379block, assigning the task a user-specified name, allocating it a stack and
380floating point context area, setting a user-specified initial priority, setting
381a user-specified initial mode, and assigning it a task ID.  Newly created tasks
382are initially placed in the dormant state.  All RTEMS tasks execute in the most
383privileged mode of the processor.
384
385Obtaining Task IDs
386------------------
387
388When a task is created, RTEMS generates a unique task ID and assigns it to the
389created task until it is deleted.  The task ID may be obtained by either of two
390methods.  First, as the result of an invocation of the ``rtems_task_create``
391directive, the task ID is stored in a user provided location.  Second, the task
392ID may be obtained later using the ``rtems_task_ident`` directive.  The task ID
393is used by other directives to manipulate this task.
394
395Starting and Restarting Tasks
396-----------------------------
397
398The ``rtems_task_start`` directive is used to place a dormant task in the ready
399state.  This enables the task to compete, based on its current priority, for
400the processor and other system resources.  Any actions, such as suspension or
401change of priority, performed on a task prior to starting it are nullified when
402the task is started.
403
404With the ``rtems_task_start`` directive the user specifies the task's starting
405address and argument.  The argument is used to communicate some startup
406information to the task.  As part of this directive, RTEMS initializes the
407task's stack based upon the task's initial execution mode and start address.
408The starting argument is passed to the task in accordance with the target
409processor's calling convention.
410
411The ``rtems_task_restart`` directive restarts a task at its initial starting
412address with its original priority and execution mode, but with a possibly
413different argument.  The new argument may be used to distinguish between the
414original invocation of the task and subsequent invocations.  The task's stack
415and control block are modified to reflect their original creation values.
416Although references to resources that have been requested are cleared,
417resources allocated by the task are NOT automatically returned to RTEMS.  A
418task cannot be restarted unless it has previously been started (i.e. dormant
419tasks cannot be restarted).  All restarted tasks are placed in the ready state.
420
421Suspending and Resuming Tasks
422-----------------------------
423
424The ``rtems_task_suspend`` directive is used to place either the caller or
425another task into a suspended state.  The task remains suspended until a
426``rtems_task_resume`` directive is issued.  This implies that a task may be
427suspended as well as blocked waiting either to acquire a resource or for the
428expiration of a timer.
429
430The ``rtems_task_resume`` directive is used to remove another task from the
431suspended state. If the task is not also blocked, resuming it will place it in
432the ready state, allowing it to once again compete for the processor and
433resources.  If the task was blocked as well as suspended, this directive clears
434the suspension and leaves the task in the blocked state.
435
436Suspending a task which is already suspended or resuming a task which is not
437suspended is considered an error.  The ``rtems_task_is_suspended`` can be used
438to determine if a task is currently suspended.
439
440Delaying the Currently Executing Task
441-------------------------------------
442
443The ``rtems_task_wake_after`` directive creates a sleep timer which allows a
444task to go to sleep for a specified interval.  The task is blocked until the
445delay interval has elapsed, at which time the task is unblocked.  A task
446calling the ``rtems_task_wake_after`` directive with a delay interval of
447``RTEMS_YIELD_PROCESSOR`` ticks will yield the processor to any other ready
448task of equal or greater priority and remain ready to execute.
449
450The ``rtems_task_wake_when`` directive creates a sleep timer which allows a
451task to go to sleep until a specified date and time.  The calling task is
452blocked until the specified date and time has occurred, at which time the task
453is unblocked.
454
455Changing Task Priority
456----------------------
457
458The ``rtems_task_set_priority`` directive is used to obtain or change the
459current priority of either the calling task or another task.  If the new
460priority requested is ``RTEMS_CURRENT_PRIORITY`` or the task's actual priority,
461then the current priority will be returned and the task's priority will remain
462unchanged.  If the task's priority is altered, then the task will be scheduled
463according to its new priority.
464
465The ``rtems_task_restart`` directive resets the priority of a task to its
466original value.
467
468Changing Task Mode
469------------------
470
471The ``rtems_task_mode`` directive is used to obtain or change the current
472execution mode of the calling task.  A task's execution mode is used to enable
473preemption, timeslicing, ASR processing, and to set the task's interrupt level.
474
475The ``rtems_task_restart`` directive resets the mode of a task to its original
476value.
477
478Task Deletion
479-------------
480
481RTEMS provides the ``rtems_task_delete`` directive to allow a task to delete
482itself or any other task.  This directive removes all RTEMS references to the
483task, frees the task's control block, removes it from resource wait queues, and
484deallocates its stack as well as the optional floating point context.  The
485task's name and ID become inactive at this time, and any subsequent references
486to either of them is invalid.  In fact, RTEMS may reuse the task ID for another
487task which is created later in the application.
488
489Unexpired delay timers (i.e. those used by ``rtems_task_wake_after`` and
490``rtems_task_wake_when``) and timeout timers associated with the task are
491automatically deleted, however, other resources dynamically allocated by the
492task are NOT automatically returned to RTEMS.  Therefore, before a task is
493deleted, all of its dynamically allocated resources should be deallocated by
494the user.  This may be accomplished by instructing the task to delete itself
495rather than directly deleting the task.  Other tasks may instruct a task to
496delete itself by sending a "delete self" message, event, or signal, or by
497restarting the task with special arguments which instruct the task to delete
498itself.
499
500Transition Advice for Obsolete Notepads
501---------------------------------------
502
503.. index:: rtems_task_get_note
504.. index:: rtems_task_set_note
505
506Task notepads and the associated directives :ref:`rtems_task_get_note` and
507:ref:`rtems_task_set_note` were removed in RTEMS 4.12. These were never
508thread-safe to access and subject to conflicting use of the notepad index by
509libraries which were designed independently.
510
511It is recommended that applications be modified to use services which are
512thread safe and not subject to issues with multiple applications conflicting
513over the key (e.g. notepad index) selection. For most applications, POSIX Keys
514should be used. These are available in all RTEMS build configurations. It is
515also possible that thread-local storage (TLS) is an option for some use cases.
516
517Transition Advice for Obsolete Task Variables
518---------------------------------------------
519
520.. index:: rtems_task_variable_add
521.. index:: rtems_task_variable_get
522.. index:: rtems_task_variable_delete
523
524Task notepads and the associated directives :ref:`rtems_task_variable_add`,
525:ref:`rtems_task_variable_get` and :ref:`rtems_task_variable_delete` were
526removed in RTEMS 4.12.  Task variables must be replaced by POSIX Keys or
527thread-local storage (TLS).  POSIX Keys are available in all configurations and
528support value destructors.  For the TLS support consult the :title:`RTEMS CPU
529Architecture Supplement`.
530
531Directives
532==========
533
534This section details the task manager's directives.  A subsection is dedicated
535to each of this manager's directives and describes the calling sequence,
536related constants, usage, and status codes.
537
538.. raw:: latex
539
540   \clearpage
541
542.. _rtems_task_create:
543
544TASK_CREATE - Create a task
545---------------------------
546.. index:: create a task
547.. index:: rtems_task_create
548
549CALLING SEQUENCE:
550    .. code-block:: c
551
552        rtems_status_code rtems_task_create(
553            rtems_name           name,
554            rtems_task_priority  initial_priority,
555            size_t               stack_size,
556            rtems_mode           initial_modes,
557            rtems_attribute      attribute_set,
558            rtems_id            *id
559        );
560
561DIRECTIVE STATUS CODES:
562    .. list-table::
563      :class: rtems-table
564
565      * - ``RTEMS_SUCCESSFUL``
566        - task created successfully
567      * - ``RTEMS_INVALID_ADDRESS``
568        - ``id`` is NULL
569      * - ``RTEMS_INVALID_NAME``
570        - invalid task name
571      * - ``RTEMS_INVALID_PRIORITY``
572        - invalid task priority
573      * - ``RTEMS_MP_NOT_CONFIGURED``
574        - multiprocessing not configured
575      * - ``RTEMS_TOO_MANY``
576        - too many tasks created
577      * - ``RTEMS_UNSATISFIED``
578        - not enough memory for stack/FP context
579      * - ``RTEMS_TOO_MANY``
580        - too many global objects
581
582DESCRIPTION:
583    This directive creates a task which resides on the local node.  It
584    allocates and initializes a TCB, a stack, and an optional floating point
585    context area.  The mode parameter contains values which sets the task's
586    initial execution mode.  The ``RTEMS_FLOATING_POINT`` attribute should be
587    specified if the created task is to use a numeric coprocessor.  For
588    performance reasons, it is recommended that tasks not using the numeric
589    coprocessor should specify the ``RTEMS_NO_FLOATING_POINT`` attribute.  If
590    the ``RTEMS_GLOBAL`` attribute is specified, the task can be accessed from
591    remote nodes.  The task id, returned in id, is used in other task related
592    directives to access the task.  When created, a task is placed in the
593    dormant state and can only be made ready to execute using the directive
594    ``rtems_task_start``.
595
596NOTES:
597    This directive will not cause the calling task to be preempted.
598
599    Valid task priorities range from a high of 1 to a low of 255.
600
601    If the requested stack size is less than the configured minimum stack size,
602    then RTEMS will use the configured minimum as the stack size for this task.
603    In addition to being able to specify the task stack size as a integer,
604    there are two constants which may be specified:
605
606    ``RTEMS_MINIMUM_STACK_SIZE``
607      The minimum stack size *RECOMMENDED* for use on this processor.  This
608      value is selected by the RTEMS developers conservatively to minimize the
609      risk of blown stacks for most user applications.  Using this constant
610      when specifying the task stack size, indicates that the stack size will
611      be at least ``RTEMS_MINIMUM_STACK_SIZE`` bytes in size.  If the user
612      configured minimum stack size is larger than the recommended minimum,
613      then it will be used.
614
615    ``RTEMS_CONFIGURED_MINIMUM_STACK_SIZE``
616      Indicates this task is to be created with a stack size of the minimum
617      stack size that was configured by the application.  If not explicitly
618      configured by the application, the default configured minimum stack size
619      is the processor dependent value ``RTEMS_MINIMUM_STACK_SIZE``.  Since
620      this uses the configured minimum stack size value, you may get a stack
621      size that is smaller or larger than the recommended minimum.  This can be
622      used to provide large stacks for all tasks on complex applications or
623      small stacks on applications that are trying to conserve memory.
624
625    Application developers should consider the stack usage of the device
626    drivers when calculating the stack size required for tasks which utilize
627    the driver.
628
629    The following task attribute constants are defined by RTEMS:
630
631    .. list-table::
632      :class: rtems-table
633
634      * - ``RTEMS_NO_FLOATING_POINT``
635        - does not use coprocessor (default)
636      * - ``RTEMS_FLOATING_POINT``
637        - uses numeric coprocessor
638      * - ``RTEMS_LOCAL``
639        - local task (default)
640      * - ``RTEMS_GLOBAL``
641        - global task
642
643    The following task mode constants are defined by RTEMS:
644
645    .. list-table::
646      :class: rtems-table
647
648      * - ``RTEMS_PREEMPT``
649        - enable preemption (default)
650      * - ``RTEMS_NO_PREEMPT``
651        - disable preemption
652      * - ``RTEMS_NO_TIMESLICE``
653        - disable timeslicing (default)
654      * - ``RTEMS_TIMESLICE``
655        - enable timeslicing
656      * - ``RTEMS_ASR``
657        - enable ASR processing (default)
658      * - ``RTEMS_NO_ASR``
659        - disable ASR processing
660      * - ``RTEMS_INTERRUPT_LEVEL(0)``
661        - enable all interrupts (default)
662      * - ``RTEMS_INTERRUPT_LEVEL(n)``
663        - execute at interrupt level ``n``
664
665    The interrupt level portion of the task execution mode supports a maximum
666    of 256 interrupt levels.  These levels are mapped onto the interrupt
667    levels actually supported by the target processor in a processor dependent
668    fashion.
669
670    Tasks should not be made global unless remote tasks must interact with
671    them.  This avoids the system overhead incurred by the creation of a
672    global task.  When a global task is created, the task's name and id must
673    be transmitted to every node in the system for insertion in the local copy
674    of the global object table.
675
676    The total number of global objects, including tasks, is limited by the
677    maximum_global_objects field in the Configuration Table.
678
679.. raw:: latex
680
681   \clearpage
682
683.. _rtems_task_ident:
684
685TASK_IDENT - Get ID of a task
686-----------------------------
687.. index:: get ID of a task
688.. index:: rtems_task_ident
689
690CALLING SEQUENCE:
691    .. code-block:: c
692
693        rtems_status_code rtems_task_ident(
694            rtems_name  name,
695            uint32_t    node,
696            rtems_id   *id
697        );
698
699DIRECTIVE STATUS CODES:
700    .. list-table::
701      :class: rtems-table
702
703      * - ``RTEMS_SUCCESSFUL``
704        - task identified successfully
705      * - ``RTEMS_INVALID_ADDRESS``
706        - ``id`` is NULL
707      * - ``RTEMS_INVALID_NAME``
708        - invalid task name
709      * - ``RTEMS_INVALID_NODE``
710        - invalid node id
711
712DESCRIPTION:
713    This directive obtains the task id associated with the task name specified
714    in name.  A task may obtain its own id by specifying ``RTEMS_SELF`` or its
715    own task name in name.  If the task name is not unique, then the task id
716    returned will match one of the tasks with that name.  However, this task id
717    is not guaranteed to correspond to the desired task.  The task id, returned
718    in id, is used in other task related directives to access the task.
719
720NOTES:
721    This directive will not cause the running task to be preempted.
722
723    If node is ``RTEMS_SEARCH_ALL_NODES``, all nodes are searched with the
724    local node being searched first.  All other nodes are searched with the
725    lowest numbered node searched first.
726
727    If node is a valid node number which does not represent the local node,
728    then only the tasks exported by the designated node are searched.
729
730    This directive does not generate activity on remote nodes.  It accesses
731    only the local copy of the global object table.
732
733.. raw:: latex
734
735   \clearpage
736
737.. _rtems_task_self:
738
739TASK_SELF - Obtain ID of caller
740-------------------------------
741.. index:: obtain ID of caller
742.. index:: rtems_task_self
743
744CALLING SEQUENCE:
745    .. code-block:: c
746
747        rtems_id rtems_task_self(void);
748
749DIRECTIVE STATUS CODES:
750    Returns the object Id of the calling task.
751
752DESCRIPTION:
753    This directive returns the Id of the calling task.
754
755NOTES:
756    If called from an interrupt service routine, this directive will return the
757    Id of the interrupted task.
758
759.. raw:: latex
760
761   \clearpage
762
763.. _rtems_task_start:
764
765TASK_START - Start a task
766-------------------------
767.. index:: starting a task
768.. index:: rtems_task_start
769
770CALLING SEQUENCE:
771    .. code-block:: c
772
773        rtems_status_code rtems_task_start(
774            rtems_id            id,
775            rtems_task_entry    entry_point,
776            rtems_task_argument argument
777        );
778
779DIRECTIVE STATUS CODES:
780    .. list-table::
781      :class: rtems-table
782
783      * - ``RTEMS_SUCCESSFUL``
784        - ask started successfully
785      * - ``RTEMS_INVALID_ADDRESS``
786        - invalid task entry point
787      * - ``RTEMS_INVALID_ID``
788        - invalid task id
789      * - ``RTEMS_INCORRECT_STATE``
790        - task not in the dormant state
791      * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT``
792        - cannot start remote task
793
794DESCRIPTION:
795    This directive readies the task, specified by ``id``, for execution based
796    on the priority and execution mode specified when the task was created.
797    The starting address of the task is given in ``entry_point``.  The task's
798    starting argument is contained in argument.  This argument can be a single
799    value or used as an index into an array of parameter blocks.  The type of
800    this numeric argument is an unsigned integer type with the property that
801    any valid pointer to void can be converted to this type and then converted
802    back to a pointer to void.  The result will compare equal to the original
803    pointer.
804
805NOTES:
806    The calling task will be preempted if its preemption mode is enabled and
807    the task being started has a higher priority.
808
809    Any actions performed on a dormant task such as suspension or change of
810    priority are nullified when the task is initiated via the
811    ``rtems_task_start`` directive.
812
813.. raw:: latex
814
815   \clearpage
816
817.. _rtems_task_restart:
818
819TASK_RESTART - Restart a task
820-----------------------------
821.. index:: restarting a task
822.. index:: rtems_task_restart
823
824CALLING SEQUENCE:
825    .. code-block:: c
826
827        rtems_status_code rtems_task_restart(
828           rtems_id            id,
829           rtems_task_argument argument
830        );
831
832DIRECTIVE STATUS CODES:
833    .. list-table::
834      :class: rtems-table
835
836      * - ``RTEMS_SUCCESSFUL``
837        - task restarted successfully
838      * - ``RTEMS_INVALID_ID``
839        - task id invalid
840      * - ``RTEMS_INCORRECT_STATE``
841        - task never started
842      * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT``
843        - cannot restart remote task
844
845DESCRIPTION:
846    This directive resets the task specified by id to begin execution at its
847    original starting address.  The task's priority and execution mode are set
848    to the original creation values.  If the task is currently blocked, RTEMS
849    automatically makes the task ready.  A task can be restarted from any
850    state, except the dormant state.
851
852    The task's starting argument is contained in argument.  This argument can
853    be a single value or an index into an array of parameter blocks.  The type
854    of this numeric argument is an unsigned integer type with the property that
855    any valid pointer to void can be converted to this type and then converted
856    back to a pointer to void.  The result will compare equal to the original
857    pointer.  This new argument may be used to distinguish between the initial
858    ``rtems_task_start`` of the task and any ensuing calls to
859    ``rtems_task_restart`` of the task.  This can be beneficial in deleting a
860    task.  Instead of deleting a task using the ``rtems_task_delete``
861    directive, a task can delete another task by restarting that task, and
862    allowing that task to release resources back to RTEMS and then delete
863    itself.
864
865NOTES:
866    If id is ``RTEMS_SELF``, the calling task will be restarted and will not
867    return from this directive.
868
869    The calling task will be preempted if its preemption mode is enabled and
870    the task being restarted has a higher priority.
871
872    The task must reside on the local node, even if the task was created with
873    the ``RTEMS_GLOBAL`` option.
874
875.. raw:: latex
876
877   \clearpage
878
879.. _rtems_task_delete:
880
881TASK_DELETE - Delete a task
882---------------------------
883.. index:: deleting a task
884.. index:: rtems_task_delete
885
886CALLING SEQUENCE:
887    .. code-block:: c
888
889        rtems_status_code rtems_task_delete(
890            rtems_id id
891        );
892
893DIRECTIVE STATUS CODES:
894    .. list-table::
895      :class: rtems-table
896
897      * - ``RTEMS_SUCCESSFUL``
898        - task deleted successfully
899      * - ``RTEMS_INVALID_ID``
900        - task id invalid
901      * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT``
902        - cannot restart remote task
903
904DESCRIPTION:
905    This directive deletes a task, either the calling task or another task, as
906    specified by id.  RTEMS stops the execution of the task and reclaims the
907    stack memory, any allocated delay or timeout timers, the TCB, and, if the
908    task is ``RTEMS_FLOATING_POINT``, its floating point context area.  RTEMS
909    does not reclaim the following resources: region segments, partition
910    buffers, semaphores, timers, or rate monotonic periods.
911
912NOTES:
913    A task is responsible for releasing its resources back to RTEMS before
914    deletion.  To insure proper deallocation of resources, a task should not be
915    deleted unless it is unable to execute or does not hold any RTEMS
916    resources.  If a task holds RTEMS resources, the task should be allowed to
917    deallocate its resources before deletion.  A task can be directed to
918    release its resources and delete itself by restarting it with a special
919    argument or by sending it a message, an event, or a signal.
920
921    Deletion of the current task (``RTEMS_SELF``) will force RTEMS to select
922    another task to execute.
923
924    When a global task is deleted, the task id must be transmitted to every
925    node in the system for deletion from the local copy of the global object
926    table.
927
928    The task must reside on the local node, even if the task was created with
929    the ``RTEMS_GLOBAL`` option.
930
931.. raw:: latex
932
933   \clearpage
934
935.. _rtems_task_suspend:
936
937TASK_SUSPEND - Suspend a task
938-----------------------------
939.. index:: suspending a task
940.. index:: rtems_task_suspend
941
942CALLING SEQUENCE:
943    .. code-block:: c
944
945        rtems_status_code rtems_task_suspend(
946            rtems_id id
947        );
948
949DIRECTIVE STATUS CODES:
950    .. list-table::
951      :class: rtems-table
952
953      * - ``RTEMS_SUCCESSFUL``
954        - task suspended successfully
955      * - ``RTEMS_INVALID_ID``
956        - task id invalid
957      * - ``RTEMS_ALREADY_SUSPENDED``
958        - task already suspended
959
960DESCRIPTION:
961    This directive suspends the task specified by id from further execution by
962    placing it in the suspended state.  This state is additive to any other
963    blocked state that the task may already be in.  The task will not execute
964    again until another task issues the ``rtems_task_resume`` directive for
965    this task and any blocked state has been removed.
966
967NOTES:
968    The requesting task can suspend itself by specifying ``RTEMS_SELF`` as id.
969    In this case, the task will be suspended and a successful return code will
970    be returned when the task is resumed.
971
972    Suspending a global task which does not reside on the local node will
973    generate a request to the remote node to suspend the specified task.
974
975    If the task specified by id is already suspended, then the
976    ``RTEMS_ALREADY_SUSPENDED`` status code is returned.
977
978.. raw:: latex
979
980   \clearpage
981
982.. _rtems_task_resume:
983
984TASK_RESUME - Resume a task
985---------------------------
986.. index:: resuming a task
987.. index:: rtems_task_resume
988
989CALLING SEQUENCE:
990    .. code-block:: c
991
992        rtems_status_code rtems_task_resume(
993            rtems_id id
994        );
995
996DIRECTIVE STATUS CODES:
997    .. list-table::
998      :class: rtems-table
999
1000      * - ``RTEMS_SUCCESSFUL``
1001        - task resumed successfully
1002      * - ``RTEMS_INVALID_ID``
1003        - task id invalid
1004      * - ``RTEMS_INCORRECT_STATE``
1005        - task not suspended
1006
1007DESCRIPTION:
1008    This directive removes the task specified by id from the suspended state.
1009    If the task is in the ready state after the suspension is removed, then it
1010    will be scheduled to run.  If the task is still in a blocked state after
1011    the suspension is removed, then it will remain in that blocked state.
1012
1013NOTES:
1014    The running task may be preempted if its preemption mode is enabled and the
1015    local task being resumed has a higher priority.
1016
1017    Resuming a global task which does not reside on the local node will
1018    generate a request to the remote node to resume the specified task.
1019
1020    If the task specified by id is not suspended, then the
1021    ``RTEMS_INCORRECT_STATE`` status code is returned.
1022
1023.. raw:: latex
1024
1025   \clearpage
1026
1027.. _rtems_task_is_suspended:
1028
1029TASK_IS_SUSPENDED - Determine if a task is Suspended
1030----------------------------------------------------
1031.. index:: is task suspended
1032.. index:: rtems_task_is_suspended
1033
1034CALLING SEQUENCE:
1035    .. code-block:: c
1036
1037        rtems_status_code rtems_task_is_suspended(
1038            rtems_id id
1039        );
1040
1041DIRECTIVE STATUS CODES:
1042    .. list-table::
1043      :class: rtems-table
1044
1045      * - ``RTEMS_SUCCESSFUL``
1046        - task is NOT suspended
1047      * - ``RTEMS_ALREADY_SUSPENDED``
1048        - task is currently suspended
1049      * - ``RTEMS_INVALID_ID``
1050        - task id invalid
1051      * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT``
1052        - not supported on remote tasks
1053
1054DESCRIPTION:
1055    This directive returns a status code indicating whether or not the
1056    specified task is currently suspended.
1057
1058NOTES:
1059    This operation is not currently supported on remote tasks.
1060
1061.. raw:: latex
1062
1063   \clearpage
1064
1065.. _rtems_task_set_priority:
1066
1067TASK_SET_PRIORITY - Set task priority
1068-------------------------------------
1069.. index:: rtems_task_set_priority
1070.. index:: current task priority
1071.. index:: set task priority
1072.. index:: get task priority
1073.. index:: obtain task priority
1074
1075CALLING SEQUENCE:
1076    .. code-block:: c
1077
1078        rtems_status_code rtems_task_set_priority(
1079            rtems_id             id,
1080            rtems_task_priority  new_priority,
1081            rtems_task_priority *old_priority
1082        );
1083
1084DIRECTIVE STATUS CODES:
1085    .. list-table::
1086      :class: rtems-table
1087
1088      * - ``RTEMS_SUCCESSFUL``
1089        - task priority set successfully
1090      * - ``RTEMS_INVALID_ID``
1091        - invalid task id
1092      * - ``RTEMS_INVALID_ADDRESS``
1093        - invalid return argument pointer
1094      * - ``RTEMS_INVALID_PRIORITY``
1095        - invalid task priority
1096
1097DESCRIPTION:
1098    This directive manipulates the priority of the task specified by id.  An id
1099    of ``RTEMS_SELF`` is used to indicate the calling task.  When new_priority
1100    is not equal to ``RTEMS_CURRENT_PRIORITY``, the specified task's previous
1101    priority is returned in old_priority.  When new_priority is
1102    ``RTEMS_CURRENT_PRIORITY``, the specified task's current priority is
1103    returned in old_priority.  Valid priorities range from a high of 1 to a low
1104    of 255.
1105
1106NOTES:
1107    The calling task may be preempted if its preemption mode is enabled and it
1108    lowers its own priority or raises another task's priority.
1109
1110    In case the new priority equals the current priority of the task, then
1111    nothing happens.
1112
1113    Setting the priority of a global task which does not reside on the local
1114    node will generate a request to the remote node to change the priority of
1115    the specified task.
1116
1117    If the task specified by id is currently holding any binary semaphores
1118    which use the priority inheritance algorithm, then the task's priority
1119    cannot be lowered immediately.  If the task's priority were lowered
1120    immediately, then priority inversion results.  The requested lowering of
1121    the task's priority will occur when the task has released all priority
1122    inheritance binary semaphores.  The task's priority can be increased
1123    regardless of the task's use of priority inheritance binary semaphores.
1124
1125.. raw:: latex
1126
1127   \clearpage
1128
1129.. _rtems_task_get_priority:
1130
1131TASK_GET_PRIORITY - Get task priority
1132-------------------------------------
1133.. index:: rtems_task_get_priority
1134.. index:: current task priority
1135.. index:: get task priority
1136.. index:: obtain task priority
1137
1138CALLING SEQUENCE:
1139    .. code-block:: c
1140
1141        rtems_status_code rtems_task_get_priority(
1142            rtems_id             task_id,
1143            rtems_id             scheduler_id,
1144            rtems_task_priority *priority
1145        );
1146
1147DIRECTIVE STATUS CODES:
1148    .. list-table::
1149      :class: rtems-table
1150
1151      * - ``RTEMS_SUCCESSFUL``
1152        - Successful operation.
1153      * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT``
1154        - Directive is illegal on remote tasks.
1155      * - ``RTEMS_INVALID_ADDRESS``
1156        - The priority parameter is NULL.
1157      * - ``RTEMS_INVALID_ID``
1158        - Invalid task or scheduler identifier.
1159      * - ``RTEMS_NOT_DEFINED``
1160        - The task has no priority within the specified scheduler instance.
1161          This error is only possible in SMP configurations.
1162
1163DESCRIPTION:
1164    This directive returns the current priority of the task specified by
1165    :c:data:`task_id` with respect to the scheduler instance specified by
1166    :c:data:`scheduler_id`.  A task id of :c:macro:`RTEMS_SELF` is used to
1167    indicate the calling task.
1168
1169NOTES:
1170    The current priority reflects temporary priority adjustments due to locking
1171    protocols, the rate-monotonic period objects on some schedulers and other
1172    mechanisms.
1173
1174.. raw:: latex
1175
1176   \clearpage
1177
1178.. _rtems_task_mode:
1179
1180TASK_MODE - Change the current task mode
1181----------------------------------------
1182.. index:: current task mode
1183.. index:: set task mode
1184.. index:: get task mode
1185.. index:: set task preemption mode
1186.. index:: get task preemption mode
1187.. index:: obtain task mode
1188.. index:: rtems_task_mode
1189
1190CALLING SEQUENCE:
1191    .. code-block:: c
1192
1193        rtems_status_code rtems_task_mode(
1194            rtems_mode  mode_set,
1195            rtems_mode  mask,
1196            rtems_mode *previous_mode_set
1197        );
1198
1199DIRECTIVE STATUS CODES:
1200    .. list-table::
1201      :class: rtems-table
1202
1203      * - ``RTEMS_SUCCESSFUL``
1204        - task mode set successfully
1205      * - ``RTEMS_INVALID_ADDRESS``
1206        - ``previous_mode_set`` is NULL
1207
1208DESCRIPTION:
1209    This directive manipulates the execution mode of the calling task.  A
1210    task's execution mode enables and disables preemption, timeslicing,
1211    asynchronous signal processing, as well as specifying the current interrupt
1212    level.  To modify an execution mode, the mode class(es) to be changed must
1213    be specified in the mask parameter and the desired mode(s) must be
1214    specified in the mode parameter.
1215
1216NOTES:
1217    The calling task will be preempted if it enables preemption and a higher
1218    priority task is ready to run.
1219
1220    Enabling timeslicing has no effect if preemption is disabled.  For a task
1221    to be timesliced, that task must have both preemption and timeslicing
1222    enabled.
1223
1224    A task can obtain its current execution mode, without modifying it, by
1225    calling this directive with a mask value of ``RTEMS_CURRENT_MODE``.
1226
1227    To temporarily disable the processing of a valid ASR, a task should call
1228    this directive with the ``RTEMS_NO_ASR`` indicator specified in mode.
1229
1230    The set of task mode constants and each mode's corresponding mask constant
1231    is provided in the following table:
1232
1233    .. list-table::
1234      :class: rtems-table
1235
1236      * - ``RTEMS_PREEMPT``
1237        - is masked by ``RTEMS_PREEMPT_MASK`` and enables preemption
1238      * - ``RTEMS_NO_PREEMPT``
1239        - is masked by ``RTEMS_PREEMPT_MASK`` and disables preemption
1240      * - ``RTEMS_NO_TIMESLICE``
1241        - is masked by ``RTEMS_TIMESLICE_MASK`` and disables timeslicing
1242      * - ``RTEMS_TIMESLICE``
1243        - is masked by ``RTEMS_TIMESLICE_MASK`` and enables timeslicing
1244      * - ``RTEMS_ASR``
1245        - is masked by ``RTEMS_ASR_MASK`` and enables ASR processing
1246      * - ``RTEMS_NO_ASR``
1247        - is masked by ``RTEMS_ASR_MASK`` and disables ASR processing
1248      * - ``RTEMS_INTERRUPT_LEVEL(0)``
1249        - is masked by ``RTEMS_INTERRUPT_MASK`` and enables all interrupts
1250      * - ``RTEMS_INTERRUPT_LEVEL(n)``
1251        - is masked by ``RTEMS_INTERRUPT_MASK`` and sets interrupts level n
1252
1253.. raw:: latex
1254
1255   \clearpage
1256
1257.. _rtems_task_wake_after:
1258
1259TASK_WAKE_AFTER - Wake up after interval
1260----------------------------------------
1261.. index:: delay a task for an interval
1262.. index:: wake up after an interval
1263.. index:: rtems_task_wake_after
1264
1265CALLING SEQUENCE:
1266    .. code-block:: c
1267
1268        rtems_status_code rtems_task_wake_after(
1269            rtems_interval ticks
1270        );
1271
1272DIRECTIVE STATUS CODES:
1273    .. list-table::
1274      :class: rtems-table
1275
1276      * - ``RTEMS_SUCCESSFUL``
1277        - always successful
1278
1279DESCRIPTION:
1280    This directive blocks the calling task for the specified number of system
1281    clock ticks.  When the requested interval has elapsed, the task is made
1282    ready.  The clock tick directives automatically updates the delay period.
1283
1284NOTES:
1285    Setting the system date and time with the ``rtems_clock_set`` directive has
1286    no effect on a ``rtems_task_wake_after`` blocked task.
1287
1288    A task may give up the processor and remain in the ready state by
1289    specifying a value of ``RTEMS_YIELD_PROCESSOR`` in ticks.
1290
1291    The maximum timer interval that can be specified is the maximum value which
1292    can be represented by the uint32_t type.
1293
1294    A clock tick is required to support the functionality of this directive.
1295
1296.. raw:: latex
1297
1298   \clearpage
1299
1300.. _rtems_task_wake_when:
1301
1302TASK_WAKE_WHEN - Wake up when specified
1303---------------------------------------
1304.. index:: delay a task until a wall time
1305.. index:: wake up at a wall time
1306.. index:: rtems_task_wake_when
1307
1308CALLING SEQUENCE:
1309    .. code-block:: c
1310
1311        rtems_status_code rtems_task_wake_when(
1312            rtems_time_of_day *time_buffer
1313        );
1314
1315DIRECTIVE STATUS CODES:
1316    .. list-table::
1317      :class: rtems-table
1318
1319      * - ``RTEMS_SUCCESSFUL``
1320        - awakened at date/time successfully
1321      * - ``RTEMS_INVALID_ADDRESS``
1322        - ``time_buffer`` is NULL
1323      * - ``RTEMS_INVALID_TIME_OF_DAY``
1324        - invalid time buffer
1325      * - ``RTEMS_NOT_DEFINED``
1326        - system date and time is not set
1327
1328DESCRIPTION:
1329    This directive blocks a task until the date and time specified in
1330    time_buffer.  At the requested date and time, the calling task will be
1331    unblocked and made ready to execute.
1332
1333NOTES:
1334    The ticks portion of time_buffer structure is ignored.  The timing
1335    granularity of this directive is a second.
1336
1337    A clock tick is required to support the functionality of this directive.
1338
1339.. raw:: latex
1340
1341   \clearpage
1342
1343.. _rtems_task_iterate:
1344
1345TASK_ITERATE - Iterate Over Tasks
1346---------------------------------
1347.. index:: iterate over all threads
1348.. index:: rtems_task_iterate
1349
1350CALLING SEQUENCE:
1351    .. code-block:: c
1352
1353        typedef bool ( *rtems_task_visitor )( rtems_tcb *tcb, void *arg );
1354
1355        void rtems_task_iterate(
1356            rtems_task_visitor  visitor,
1357            void               *arg
1358        );
1359
1360DIRECTIVE STATUS CODES:
1361    NONE
1362
1363DESCRIPTION:
1364    Iterates over all tasks in the system.  This operation covers all tasks of
1365    all APIs.  The user should be careful in accessing the contents of the
1366    thread control block :c:data:`tcb`.  The visitor argument :c:data:`arg` is
1367    passed to all invocations of :c:data:`visitor` in addition to the thread
1368    control block.  The iteration stops immediately in case the visitor
1369    function returns true.
1370
1371NOTES:
1372    Must be called from task context.  This operation obtains and releases the
1373    objects allocator lock.  The task visitor is called while owning the objects
1374    allocator lock.  It is possible to perform blocking operations in the task
1375    visitor, however, take care that no deadlocks via the object allocator lock
1376    can occur.
1377
1378Deprecated and Removed Directives
1379=================================
1380
1381.. raw:: latex
1382
1383   \clearpage
1384
1385.. _rtems_iterate_over_all_threads:
1386
1387ITERATE_OVER_ALL_THREADS - Iterate Over Tasks
1388---------------------------------------------
1389.. index:: rtems_iterate_over_all_threads
1390
1391.. warning::
1392
1393    This directive is deprecated.  Its use is unsafe.  Use
1394    :ref:`rtems_task_iterate` instead.
1395
1396CALLING SEQUENCE:
1397    .. code-block:: c
1398
1399        typedef void (*rtems_per_thread_routine)(Thread_Control *the_thread);
1400        void rtems_iterate_over_all_threads(
1401            rtems_per_thread_routine routine
1402        );
1403
1404DIRECTIVE STATUS CODES:
1405    NONE
1406
1407DESCRIPTION:
1408    This directive iterates over all of the existant threads in the system and
1409    invokes ``routine`` on each of them.  The user should be careful in
1410    accessing the contents of ``the_thread``.
1411
1412    This routine is intended for use in diagnostic utilities and is not
1413    intented for routine use in an operational system.
1414
1415NOTES:
1416    There is **no protection** while this routine is called.  The thread
1417    control block may be in an inconsistent state or may change due to
1418    interrupts or activity on other processors.
1419
1420.. raw:: latex
1421
1422   \clearpage
1423
1424.. _rtems_task_get_note:
1425
1426TASK_GET_NOTE - Get task notepad entry
1427--------------------------------------
1428.. index:: get task notepad entry
1429.. index:: rtems_task_get_note
1430
1431.. warning::
1432
1433    This directive was removed in RTEMS 4.12.
1434
1435CALLING SEQUENCE:
1436    .. code-block:: c
1437
1438        rtems_status_code rtems_task_get_note(
1439          rtems_id  id,
1440          uint32_t  notepad,
1441          uint32_t *note
1442        );
1443
1444DIRECTIVE STATUS CODES:
1445    .. list-table::
1446      :class: rtems-table
1447
1448      * - ``RTEMS_SUCCESSFUL``
1449        - note value obtained successfully
1450      * - ``RTEMS_INVALID_ADDRESS``
1451        - ``note`` parameter is NULL
1452      * - ``RTEMS_INVALID_ID``
1453        - invalid task id
1454      * - ``RTEMS_INVALID_NUMBER``
1455        - invalid notepad location
1456
1457DESCRIPTION:
1458    This directive returns the note contained in the notepad location of the
1459    task specified by id.
1460
1461NOTES:
1462    This directive will not cause the running task to be preempted.
1463
1464    If id is set to ``RTEMS_SELF``, the calling task accesses its own notepad.
1465
1466    The sixteen notepad locations can be accessed using the constants
1467    ``RTEMS_NOTEPAD_0`` through ``RTEMS_NOTEPAD_15``.
1468
1469    Getting a note of a global task which does not reside on the local node
1470    will generate a request to the remote node to obtain the notepad entry of
1471    the specified task.
1472
1473.. raw:: latex
1474
1475   \clearpage
1476
1477.. _rtems_task_set_note:
1478
1479TASK_SET_NOTE - Set task notepad entry
1480--------------------------------------
1481.. index:: set task notepad entry
1482.. index:: rtems_task_set_note
1483
1484.. warning::
1485
1486    This directive was removed in RTEMS 4.12.
1487
1488CALLING SEQUENCE:
1489    .. code-block:: c
1490
1491        rtems_status_code rtems_task_set_note(
1492          rtems_id  id,
1493          uint32_t  notepad,
1494          uint32_t  note
1495        );
1496
1497DIRECTIVE STATUS CODES:
1498    .. list-table::
1499      :class: rtems-table
1500
1501      * - ``RTEMS_SUCCESSFUL``
1502        - note set successfully
1503      * - ``RTEMS_INVALID_ID``
1504        - invalid task id
1505      * - ``RTEMS_INVALID_NUMBER``
1506        - invalid notepad location
1507
1508DESCRIPTION:
1509    This directive sets the notepad entry for the task specified by id to the
1510    value note.
1511
1512NOTES:
1513    If ``id`` is set to ``RTEMS_SELF``, the calling task accesses its own
1514    notepad.
1515
1516    This directive will not cause the running task to be preempted.
1517
1518    The sixteen notepad locations can be accessed using the constants
1519    ``RTEMS_NOTEPAD_0`` through ``RTEMS_NOTEPAD_15``.
1520
1521    Setting a note of a global task which does not reside on the local node
1522    will generate a request to the remote node to set the notepad entry of the
1523    specified task.
1524
1525.. raw:: latex
1526
1527   \clearpage
1528
1529.. _rtems_task_variable_add:
1530
1531TASK_VARIABLE_ADD - Associate per task variable
1532-----------------------------------------------
1533.. index:: per-task variable
1534.. index:: task private variable
1535.. index:: task private data
1536.. index:: rtems_task_variable_add
1537
1538.. warning::
1539
1540    This directive was removed in RTEMS 4.12.
1541
1542CALLING SEQUENCE:
1543    .. code-block:: c
1544
1545        rtems_status_code rtems_task_variable_add(
1546            rtems_id  tid,
1547            void    **task_variable,
1548            void    (*dtor)(void *)
1549        );
1550
1551DIRECTIVE STATUS CODES:
1552     .. list-table::
1553      :class: rtems-table
1554
1555      * - ``RTEMS_SUCCESSFUL``
1556        - per task variable added successfully
1557      * - ``RTEMS_INVALID_ADDRESS``
1558        - ``task_variable`` is NULL
1559      * - ``RTEMS_INVALID_ID``
1560        - invalid task id
1561      * - ``RTEMS_NO_MEMORY``
1562        - invalid task id
1563      * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT``
1564        - not supported on remote tasks
1565
1566DESCRIPTION:
1567    This directive adds the memory location specified by the ptr argument to
1568    the context of the given task.  The variable will then be private to the
1569    task.  The task can access and modify the variable, but the modifications
1570    will not appear to other tasks, and other tasks' modifications to that
1571    variable will not affect the value seen by the task.  This is accomplished
1572    by saving and restoring the variable's value each time a task switch occurs
1573    to or from the calling task.  If the dtor argument is non-NULL it specifies
1574    the address of a 'destructor' function which will be called when the task
1575    is deleted.  The argument passed to the destructor function is the task's
1576    value of the variable.
1577
1578NOTES:
1579    Task variables increase the context switch time to and from the tasks that
1580    own them so it is desirable to minimize the number of task variables.  One
1581    efficient method is to have a single task variable that is a pointer to a
1582    dynamically allocated structure containing the task's private 'global'
1583    data.  In this case the destructor function could be 'free'.
1584
1585    Per-task variables are disabled in SMP configurations and this service is
1586    not available.
1587
1588.. raw:: latex
1589
1590   \clearpage
1591
1592.. _rtems_task_variable_get:
1593
1594TASK_VARIABLE_GET - Obtain value of a per task variable
1595-------------------------------------------------------
1596.. index:: get per-task variable
1597.. index:: obtain per-task variable
1598.. index:: rtems_task_variable_get
1599
1600.. warning::
1601
1602    This directive was removed in RTEMS 4.12.
1603
1604CALLING SEQUENCE:
1605    .. code-block:: c
1606
1607        rtems_status_code rtems_task_variable_get(
1608            rtems_id  tid,
1609            void    **task_variable,
1610            void    **task_variable_value
1611        );
1612
1613DIRECTIVE STATUS CODES:
1614    .. list-table::
1615      :class: rtems-table
1616
1617      * - ``RTEMS_SUCCESSFUL``
1618        - per task variable obtained successfully
1619      * - ``RTEMS_INVALID_ADDRESS``
1620        - ``task_variable`` is NULL
1621      * - ``RTEMS_INVALID_ADDRESS``
1622        - ``task_variable_value`` is NULL
1623      * - ``RTEMS_INVALID_ADDRESS``
1624        - ``task_variable`` is not found
1625      * - ``RTEMS_NO_MEMORY``
1626        - invalid task id
1627      * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT``
1628        - not supported on remote tasks
1629
1630DESCRIPTION:
1631    This directive looks up the private value of a task variable for a
1632    specified task and stores that value in the location pointed to by the
1633    result argument.  The specified task is usually not the calling task, which
1634    can get its private value by directly accessing the variable.
1635
1636NOTES:
1637    If you change memory which ``task_variable_value`` points to, remember to
1638    declare that memory as volatile, so that the compiler will optimize it
1639    correctly.  In this case both the pointer ``task_variable_value`` and data
1640    referenced by ``task_variable_value`` should be considered volatile.
1641
1642    Per-task variables are disabled in SMP configurations and this service is
1643    not available.
1644
1645.. raw:: latex
1646
1647   \clearpage
1648
1649.. _rtems_task_variable_delete:
1650
1651TASK_VARIABLE_DELETE - Remove per task variable
1652-----------------------------------------------
1653.. index:: per-task variable
1654.. index:: task private variable
1655.. index:: task private data
1656.. index:: rtems_task_variable_delete
1657
1658.. warning::
1659
1660    This directive was removed in RTEMS 4.12.
1661
1662CALLING SEQUENCE:
1663    .. code-block:: c
1664
1665        rtems_status_code rtems_task_variable_delete(
1666            rtems_id  id,
1667            void    **task_variable
1668        );
1669
1670DIRECTIVE STATUS CODES:
1671    .. list-table::
1672      :class: rtems-table
1673
1674      * - ``RTEMS_SUCCESSFUL``
1675        - per task variable deleted successfully
1676      * - ``RTEMS_INVALID_ID``
1677        - invalid task id
1678      * - ``RTEMS_NO_MEMORY``
1679        - invalid task id
1680      * - ``RTEMS_INVALID_ADDRESS``
1681        - ``task_variable`` is NULL
1682      * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT``
1683        - not supported on remote tasks
1684
1685DESCRIPTION:
1686    This directive removes the given location from a task's context.
1687
1688NOTES:
1689    Per-task variables are disabled in SMP configurations and this service is
1690    not available.
Note: See TracBrowser for help on using the repository browser.