source: rtems-docs/c_user/task_manager.rst @ f02e872

4.115
Last change on this file since f02e872 was f02e872, checked in by Chris Johns <chrisj@…>, on 02/17/16 at 23:32:05

Fix the double quotes.

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