source: rtems/cpukit/rtems/src/semobtain.c @ 3a638ce

4.115
Last change on this file since 3a638ce was 3a638ce, checked in by Joel Sherrill <joel.sherrill@…>, on 01/31/14 at 16:55:17

rtems/*.c: Remove use of register keyword

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS Obtain Semaphore
5 *  @ingroup ClassicSem
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2014.
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/status.h>
23#include <rtems/rtems/support.h>
24#include <rtems/rtems/attrimpl.h>
25#include <rtems/score/isr.h>
26#include <rtems/rtems/optionsimpl.h>
27#include <rtems/rtems/semimpl.h>
28#include <rtems/score/coremuteximpl.h>
29#include <rtems/score/coresemimpl.h>
30#include <rtems/score/thread.h>
31
32#include <rtems/score/interr.h>
33
34rtems_status_code rtems_semaphore_obtain(
35  rtems_id        id,
36  rtems_option    option_set,
37  rtems_interval  timeout
38)
39{
40  Semaphore_Control              *the_semaphore;
41  Objects_Locations               location;
42  ISR_Level                       level;
43  Thread_Control                 *executing;
44
45  the_semaphore = _Semaphore_Get_interrupt_disable( id, &location, &level );
46  switch ( location ) {
47
48    case OBJECTS_LOCAL:
49      executing = _Thread_Executing;
50      if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) {
51        _CORE_mutex_Seize(
52          &the_semaphore->Core_control.mutex,
53          executing,
54          id,
55          ((_Options_Is_no_wait( option_set )) ? false : true),
56          timeout,
57          level
58        );
59        _Objects_Put_for_get_isr_disable( &the_semaphore->Object );
60        return _Semaphore_Translate_core_mutex_return_code(
61                  executing->Wait.return_code );
62      }
63
64      /* must be a counting semaphore */
65      _CORE_semaphore_Seize_isr_disable(
66        &the_semaphore->Core_control.semaphore,
67        executing,
68        id,
69        ((_Options_Is_no_wait( option_set )) ? false : true),
70        timeout,
71        level
72      );
73      _Objects_Put_for_get_isr_disable( &the_semaphore->Object );
74      return _Semaphore_Translate_core_semaphore_return_code(
75                  executing->Wait.return_code );
76
77#if defined(RTEMS_MULTIPROCESSING)
78    case OBJECTS_REMOTE:
79      return _Semaphore_MP_Send_request_packet(
80          SEMAPHORE_MP_OBTAIN_REQUEST,
81          id,
82          option_set,
83          timeout
84      );
85#endif
86
87    case OBJECTS_ERROR:
88      break;
89
90  }
91
92  return RTEMS_INVALID_ID;
93}
Note: See TracBrowser for help on using the repository browser.