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

4.104.114.84.95
Last change on this file since df49c60 was df49c60, checked in by Joel Sherrill <joel.sherrill@…>, on 06/12/00 at 15:00:15

Merged from 4.5.0-beta3a

  • 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  void **ptr,
28  void (*dtor)(void *)
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        tvp->dtor = dtor;
59        _Thread_Enable_dispatch();
60        return RTEMS_SUCCESSFUL;
61      }
62      tvp = tvp->next;
63    }
64
65    /*
66     *  Now allocate memory for this task variable.
67     */
68
69    new = (rtems_task_variable_t *)
70       _Workspace_Allocate(sizeof(rtems_task_variable_t));
71    if (new == NULL) {
72      _Thread_Enable_dispatch();
73      return RTEMS_NO_MEMORY;
74    }
75    new->gval = *ptr;
76    new->ptr = ptr;
77    new->dtor = dtor;
78
79    new->next = the_thread->task_variables;
80    the_thread->task_variables = new;
81    _Thread_Enable_dispatch();
82    return RTEMS_SUCCESSFUL;
83  }
84  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
85}
Note: See TracBrowser for help on using the repository browser.