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

5
Last change on this file since 3692095 was 3692095, checked in by Sebastian Huber <sebastian.huber@…>, on 05/30/16 at 08:41:22

rtems: Move MrsP semaphore operations

Move MrsP semaphore operations to a less prominent location. Fix field
name.

  • Property mode set to 100644
File size: 3.0 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/rtems/semimpl.h>
22#include <rtems/rtems/optionsimpl.h>
23#include <rtems/rtems/statusimpl.h>
24
25THREAD_QUEUE_OBJECT_ASSERT(
26  Semaphore_Control,
27  Core_control.Wait_queue
28);
29
30THREAD_QUEUE_OBJECT_ASSERT(
31  Semaphore_Control,
32  Core_control.Mutex.Recursive.Mutex.Wait_queue
33);
34
35THREAD_QUEUE_OBJECT_ASSERT(
36  Semaphore_Control,
37  Core_control.semaphore.Wait_queue
38);
39
40#if defined(RTEMS_SMP)
41THREAD_QUEUE_OBJECT_ASSERT(
42  Semaphore_Control,
43  Core_control.MRSP.Wait_queue
44);
45#endif
46
47rtems_status_code rtems_semaphore_obtain(
48  rtems_id        id,
49  rtems_option    option_set,
50  rtems_interval  timeout
51)
52{
53  Semaphore_Control    *the_semaphore;
54  Thread_queue_Context  queue_context;
55  Thread_Control       *executing;
56  bool                  wait;
57  Status_Control        status;
58
59  the_semaphore = _Semaphore_Get( id, &queue_context );
60
61  if ( the_semaphore == NULL ) {
62#if defined(RTEMS_MULTIPROCESSING)
63    return _Semaphore_MP_Obtain( id, option_set, timeout );
64#else
65    return RTEMS_INVALID_ID;
66#endif
67  }
68
69  executing = _Thread_Executing;
70  wait = !_Options_Is_no_wait( option_set );
71
72  switch ( the_semaphore->variant ) {
73    case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
74      status = _CORE_recursive_mutex_Seize(
75        &the_semaphore->Core_control.Mutex.Recursive,
76        executing,
77        wait,
78        timeout,
79        _CORE_recursive_mutex_Seize_nested,
80        &queue_context
81      );
82      break;
83    case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
84      status = _CORE_ceiling_mutex_Seize(
85        &the_semaphore->Core_control.Mutex,
86        executing,
87        wait,
88        timeout,
89        _CORE_recursive_mutex_Seize_nested,
90        &queue_context
91      );
92      break;
93    case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
94      status = _CORE_recursive_mutex_Seize_no_protocol(
95        &the_semaphore->Core_control.Mutex.Recursive,
96        _Semaphore_Get_operations( the_semaphore ),
97        executing,
98        wait,
99        timeout,
100        _CORE_recursive_mutex_Seize_nested,
101        &queue_context
102      );
103      break;
104#if defined(RTEMS_SMP)
105    case SEMAPHORE_VARIANT_MRSP:
106      status = _MRSP_Seize(
107        &the_semaphore->Core_control.MRSP,
108        executing,
109        wait,
110        timeout,
111        &queue_context
112      );
113      break;
114#endif
115    default:
116      _Assert(
117        the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
118          || the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING
119      );
120      status = _CORE_semaphore_Seize(
121        &the_semaphore->Core_control.semaphore,
122        _Semaphore_Get_operations( the_semaphore ),
123        executing,
124        wait,
125        timeout,
126        &queue_context
127      );
128      break;
129  }
130
131  return _Status_Get( status );
132}
Note: See TracBrowser for help on using the repository browser.