source: rtems/cpukit/rtems/src/semobtain.c @ 0b713f89

5
Last change on this file since 0b713f89 was 0b713f89, checked in by Sebastian Huber <sebastian.huber@…>, on 05/30/16 at 04:59:55

score: Rework CORE inherit priority mutex

Provide dedicated seize and surrender methods for inherit priority
mutexes. This eliminates CORE_mutex_Attributes.

  • 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#if defined(RTEMS_SMP)
74    case SEMAPHORE_VARIANT_MRSP:
75      status = _MRSP_Seize(
76        &the_semaphore->Core_control.mrsp,
77        executing,
78        wait,
79        timeout,
80        &queue_context
81      );
82      break;
83#endif
84    case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
85      status = _CORE_recursive_mutex_Seize(
86        &the_semaphore->Core_control.Mutex.Recursive,
87        executing,
88        wait,
89        timeout,
90        _CORE_recursive_mutex_Seize_nested,
91        &queue_context
92      );
93      break;
94    case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
95      status = _CORE_ceiling_mutex_Seize(
96        &the_semaphore->Core_control.Mutex,
97        executing,
98        wait,
99        timeout,
100        _CORE_recursive_mutex_Seize_nested,
101        &queue_context
102      );
103      break;
104    case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
105      status = _CORE_recursive_mutex_Seize_no_protocol(
106        &the_semaphore->Core_control.Mutex.Recursive,
107        _Semaphore_Get_operations( the_semaphore ),
108        executing,
109        wait,
110        timeout,
111        _CORE_recursive_mutex_Seize_nested,
112        &queue_context
113      );
114      break;
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.