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

4.115
Last change on this file since a6500136 was a6500136, checked in by Alex Ivanov <alexivanov97@…>, on 12/05/12 at 23:16:48

rtems misc: Clean up Doxygen GCI Task #7

http://www.google-melange.com/gci/task/view/google/gci2012/7950206

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS Add Task Variable
5 *  @ingroup ClassicTasks
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2007.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/system.h>
22#include <rtems/rtems/tasks.h>
23#include <rtems/score/wkspace.h>
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  if ( !ptr )
36    return RTEMS_INVALID_ADDRESS;
37
38  the_thread = _Thread_Get (tid, &location);
39  switch (location) {
40
41    case OBJECTS_LOCAL:
42      /*
43       *  Figure out if the variable is already in this task's list.
44       */
45      tvp = the_thread->task_variables;
46      while (tvp) {
47        if (tvp->ptr == ptr) {
48          tvp->dtor = dtor;
49          _Thread_Enable_dispatch();
50          return RTEMS_SUCCESSFUL;
51        }
52        tvp = (rtems_task_variable_t *)tvp->next;
53      }
54
55      /*
56       *  Now allocate memory for this task variable.
57       */
58      new = (rtems_task_variable_t *)
59         _Workspace_Allocate(sizeof(rtems_task_variable_t));
60      if (new == NULL) {
61        _Thread_Enable_dispatch();
62        return RTEMS_NO_MEMORY;
63      }
64      new->gval = *ptr;
65      new->ptr = ptr;
66      new->dtor = dtor;
67
68      new->next = (struct rtems_task_variable_tt *)the_thread->task_variables;
69      the_thread->task_variables = new;
70      _Thread_Enable_dispatch();
71      return RTEMS_SUCCESSFUL;
72
73#if defined(RTEMS_MULTIPROCESSING)
74    case OBJECTS_REMOTE:
75      _Thread_Dispatch();
76      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
77#endif
78
79    case OBJECTS_ERROR:
80      break;
81  }
82  return RTEMS_INVALID_ID;
83}
Note: See TracBrowser for help on using the repository browser.