source: rtems-docs/c_user/task_manager.rst @ 859f0b7

4.115
Last change on this file since 859f0b7 was 859f0b7, checked in by Chris Johns <chrisj@…>, on 01/27/16 at 00:27:31

Add an rtems-table class to wrap and align HTML tables.

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