source: rtems/cpukit/rtems/src/taskvariableadd.c @ 08311cc3

4.104.114.84.95
Last change on this file since 08311cc3 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

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