source: rtems/cpukit/rtems/src/semobtain.c @ 66cb142

5
Last change on this file since 66cb142 was c3105894, checked in by Sebastian Huber <sebastian.huber@…>, on 10/19/17 at 11:47:57

score: Move thread queue timeout handling

Update #3117.
Update #3182.

  • Property mode set to 100644
File size: 3.2 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  if ( wait ) {
73    _Thread_queue_Context_set_enqueue_timeout_ticks( &queue_context, timeout );
74  } else {
75    _Thread_queue_Context_set_enqueue_do_nothing_extra( &queue_context );
76  }
77
78  switch ( the_semaphore->variant ) {
79    case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
80      status = _CORE_recursive_mutex_Seize(
81        &the_semaphore->Core_control.Mutex.Recursive,
82        CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS,
83        executing,
84        wait,
85        _CORE_recursive_mutex_Seize_nested,
86        &queue_context
87      );
88      break;
89    case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
90      status = _CORE_ceiling_mutex_Seize(
91        &the_semaphore->Core_control.Mutex,
92        executing,
93        wait,
94        _CORE_recursive_mutex_Seize_nested,
95        &queue_context
96      );
97      break;
98    case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
99      status = _CORE_recursive_mutex_Seize(
100        &the_semaphore->Core_control.Mutex.Recursive,
101        _Semaphore_Get_operations( the_semaphore ),
102        executing,
103        wait,
104        _CORE_recursive_mutex_Seize_nested,
105        &queue_context
106      );
107      break;
108#if defined(RTEMS_SMP)
109    case SEMAPHORE_VARIANT_MRSP:
110      status = _MRSP_Seize(
111        &the_semaphore->Core_control.MRSP,
112        executing,
113        wait,
114        &queue_context
115      );
116      break;
117#endif
118    default:
119      _Assert(
120        the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
121          || the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING
122      );
123      status = _CORE_semaphore_Seize(
124        &the_semaphore->Core_control.Semaphore,
125        _Semaphore_Get_operations( the_semaphore ),
126        executing,
127        wait,
128        &queue_context
129      );
130      break;
131  }
132
133  return _Status_Get( status );
134}
Note: See TracBrowser for help on using the repository browser.