source: rtems/cpukit/rtems/src/taskvariableadd.c @ aad726e

4.104.114.84.95
Last change on this file since aad726e was aad726e, checked in by Joel Sherrill <joel.sherrill@…>, on 11/16/99 at 22:56:38

Moved task_variable pointer to basic shared part of TCB instead of
RTEMS API extension to avoid problems when the extension is freed.
Eventually the task variable switch extension should become part
of the core context switch and the Ada tcb self implemented in
terms of it.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/*
2 *  rtems_task_variable_add - Add a per-task variable
3 *
4 *
5 *  COPYRIGHT (c) 1989-1998.
6 *  On-Line Applications Research Corporation (OAR).
7 *  Copyright assigned to U.S. Government, 1994.
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.OARcorp.com/rtems/license.html.
12 *
13 *  $Id$
14 */
15
16#include <rtems/system.h>
17#include <rtems/rtems/tasks.h>
18#include <rtems/score/wkspace.h>
19
20/*
21 *  rtems_task_variable_add
22 *
23 *  This directive registers a task variable.
24 */
25
26rtems_status_code rtems_task_variable_add(
27  rtems_id tid,
28  int *ptr
29)
30{
31  Thread_Control        *the_thread;
32  Objects_Locations      location;
33  rtems_task_variable_t *tvp, *new;
34
35  the_thread = _Thread_Get (tid, &location);
36  switch (location) {
37  case OBJECTS_REMOTE:
38#if defined(RTEMS_MULTIPROCESSING)
39    _Thread_Dispatch();
40    return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
41#endif
42
43  case OBJECTS_ERROR:
44    return RTEMS_INVALID_ID;
45
46  default:
47    return RTEMS_INTERNAL_ERROR;
48
49  case OBJECTS_LOCAL:
50
51    /*
52     *  Figure out if the variable is already in this task's list.
53     */
54
55    tvp = the_thread->task_variables;
56    while (tvp) {
57      if (tvp->ptr == ptr) {
58        _Thread_Enable_dispatch();
59        return RTEMS_SUCCESSFUL;
60      }
61      tvp = tvp->next;
62    }
63
64    /*
65     *  Now allocate memory for this task variable.
66     */
67
68    new = (rtems_task_variable_t *)
69       _Workspace_Allocate(sizeof(rtems_task_variable_t));
70    if (new == NULL) {
71      _Thread_Enable_dispatch();
72      return RTEMS_NO_MEMORY;
73    }
74    new->var = 0;
75    new->ptr = ptr;
76
77    new->next = the_thread->task_variables;
78    the_thread->task_variables = new;
79    _Thread_Enable_dispatch();
80    return RTEMS_SUCCESSFUL;
81  }
82  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
83}
84
Note: See TracBrowser for help on using the repository browser.