source: rtems/cpukit/rtems/src/semobtain.c @ a816f084

4.115
Last change on this file since a816f084 was a816f084, checked in by Sebastian Huber <sebastian.huber@…>, on 05/07/15 at 12:02:46

score: Fine grained locking for MrsP

Update #2273.

  • Property mode set to 100644
File size: 2.7 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.org/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_lock_Context                lock_context;
43  Thread_Control                 *executing;
44  rtems_attribute                 attribute_set;
45  bool                            wait;
46
47  the_semaphore = _Semaphore_Get_interrupt_disable(
48    id,
49    &location,
50    &lock_context
51  );
52  switch ( location ) {
53
54    case OBJECTS_LOCAL:
55      executing = _Thread_Executing;
56      attribute_set = the_semaphore->attribute_set;
57      wait = !_Options_Is_no_wait( option_set );
58#if defined(RTEMS_SMP)
59      if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
60        MRSP_Status mrsp_status;
61
62        mrsp_status = _MRSP_Obtain(
63          &the_semaphore->Core_control.mrsp,
64          executing,
65          wait,
66          timeout,
67          &lock_context
68        );
69        return _Semaphore_Translate_MRSP_status_code( mrsp_status );
70      } else
71#endif
72      if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
73        _CORE_mutex_Seize(
74          &the_semaphore->Core_control.mutex,
75          executing,
76          id,
77          wait,
78          timeout,
79          &lock_context
80        );
81        return _Semaphore_Translate_core_mutex_return_code(
82                  executing->Wait.return_code );
83      }
84
85      /* must be a counting semaphore */
86      _CORE_semaphore_Seize(
87        &the_semaphore->Core_control.semaphore,
88        executing,
89        id,
90        wait,
91        timeout,
92        &lock_context
93      );
94      return _Semaphore_Translate_core_semaphore_return_code(
95                  executing->Wait.return_code );
96
97#if defined(RTEMS_MULTIPROCESSING)
98    case OBJECTS_REMOTE:
99      return _Semaphore_MP_Send_request_packet(
100          SEMAPHORE_MP_OBTAIN_REQUEST,
101          id,
102          option_set,
103          timeout
104      );
105#endif
106
107    case OBJECTS_ERROR:
108      break;
109
110  }
111
112  return RTEMS_INVALID_ID;
113}
Note: See TracBrowser for help on using the repository browser.