source: rtems/cpukit/score/src/objectget.c @ 749d64a

4.104.115
Last change on this file since 749d64a was e06b6b0, checked in by Joel Sherrill <joel.sherrill@…>, on 05/06/08 at 20:31:33

2008-05-06 Joel Sherrill <joel.sherrill@…>

  • score/src/objectget.c: Improve comments and readability.
  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 *  Object Handler
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/score/address.h>
21#include <rtems/score/chain.h>
22#include <rtems/score/object.h>
23#if defined(RTEMS_MULTIPROCESSING)
24#include <rtems/score/objectmp.h>
25#endif
26#include <rtems/score/thread.h>
27#include <rtems/score/wkspace.h>
28#include <rtems/score/sysstate.h>
29#include <rtems/score/isr.h>
30
31/*PAGE
32 *
33 * _Objects_Get
34 *
35 * This routine sets the object pointer for the given
36 * object id based on the given object information structure.
37 *
38 * Input parameters:
39 *   information - pointer to entry in table for this class
40 *   id          - object id to search for
41 *   location    - address of where to store the location
42 *
43 * Output parameters:
44 *   returns  - address of object if local
45 *   location - one of the following:
46 *                  OBJECTS_ERROR  - invalid object ID
47 *                  OBJECTS_REMOTE - remote object
48 *                  OBJECTS_LOCAL  - local object
49 */
50
51Objects_Control *_Objects_Get(
52  Objects_Information *information,
53  Objects_Id           id,
54  Objects_Locations   *location
55)
56{
57  Objects_Control *the_object;
58  uint32_t         index;
59
60  /*
61   *  Extract the index portion of an Id in a way that produces a valid
62   *  index for objects within this class and an invalid value for objects
63   *  outside this class.
64   *
65   *  If the Id matches the api, class, and node but index portion is 0,
66   *  then the subtraction will underflow and the addition of 1 will
67   *  result in a 0 index.  The zeroth element in the local_table is
68   *  always NULL.
69   *
70   *  If the Id is valid but the object has not been created yet, then
71   *  the local_table entry will be NULL.
72   */
73  index = id - information->minimum_id + 1;
74
75  /*
76   *  If the index is less than maximum, then it is OK to use it to
77   *  index into the local_table array.
78   */
79  if ( index <= information->maximum ) {
80    _Thread_Disable_dispatch();
81    if ( (the_object = information->local_table[ index ]) != NULL ) {
82      *location = OBJECTS_LOCAL;
83      return the_object;
84    }
85
86    /*
87     *  Valid Id for this API, Class and Node but the object has not
88     *  been allocated yet.
89     */
90    _Thread_Enable_dispatch();
91    *location = OBJECTS_ERROR;
92    return NULL;
93  }
94
95  /*
96   *  Object Id is not within this API and Class on this node.  So
97   *  it may be global in a multiprocessing system.  But it is clearly
98   *  invalid on a single processor system.
99   */
100  *location = OBJECTS_ERROR;
101
102#if defined(RTEMS_MULTIPROCESSING)
103  _Objects_MP_Is_remote( information, id, location, &the_object );
104  return the_object;
105#else
106  return NULL;
107#endif
108}
Note: See TracBrowser for help on using the repository browser.