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

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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