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

4.104.114.84.95
Last change on this file since a29d2e7 was 1095ec1, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/18/05 at 09:03:45

Include config.h.

  • Property mode set to 100644
File size: 1.9 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.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/rtems/tasks.h>
21#include <rtems/score/wkspace.h>
22
23/*
24 *  rtems_task_variable_add
25 *
26 *  This directive registers a task variable.
27 */
28
29rtems_status_code rtems_task_variable_add(
30  rtems_id tid,
31  void **ptr,
32  void (*dtor)(void *)
33)
34{
35  Thread_Control        *the_thread;
36  Objects_Locations      location;
37  rtems_task_variable_t *tvp, *new;
38
39  if ( !ptr )
40    return RTEMS_INVALID_ADDRESS;
41
42  the_thread = _Thread_Get (tid, &location);
43  switch (location) {
44  case OBJECTS_REMOTE:
45#if defined(RTEMS_MULTIPROCESSING)
46    _Thread_Dispatch();
47    return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
48#endif
49
50  case OBJECTS_ERROR:
51    return RTEMS_INVALID_ID;
52
53  default:
54    return RTEMS_INTERNAL_ERROR;
55
56  case OBJECTS_LOCAL:
57
58    /*
59     *  Figure out if the variable is already in this task's list.
60     */
61
62    tvp = the_thread->task_variables;
63    while (tvp) {
64      if (tvp->ptr == ptr) {
65        tvp->dtor = dtor;
66        _Thread_Enable_dispatch();
67        return RTEMS_SUCCESSFUL;
68      }
69      tvp = tvp->next;
70    }
71
72    /*
73     *  Now allocate memory for this task variable.
74     */
75
76    new = (rtems_task_variable_t *)
77       _Workspace_Allocate(sizeof(rtems_task_variable_t));
78    if (new == NULL) {
79      _Thread_Enable_dispatch();
80      return RTEMS_NO_MEMORY;
81    }
82    new->gval = *ptr;
83    new->ptr = ptr;
84    new->dtor = dtor;
85
86    new->next = the_thread->task_variables;
87    the_thread->task_variables = new;
88    _Thread_Enable_dispatch();
89    return RTEMS_SUCCESSFUL;
90  }
91  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
92}
Note: See TracBrowser for help on using the repository browser.