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

5
Last change on this file since f23d470 was f23d470, checked in by Gedare Bloom <gedare@…>, on 06/09/16 at 15:33:15

cpukit: Add and use Watchdog_Discipline.

Clock disciplines may be WATCHDOG_RELATIVE, WATCHDOG_ABSOLUTE,
or WATCHDOG_NO_TIMEOUT. A discipline of WATCHDOG_RELATIVE with
a timeout of WATCHDOG_NO_TIMEOUT is equivalent to a discipline
of WATCHDOG_NO_TIMEOUT.

updates #2732

  • 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  _Thread_queue_Context_set_relative_timeout( &queue_context, timeout );
73
74  switch ( the_semaphore->variant ) {
75    case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
76      status = _CORE_recursive_mutex_Seize(
77        &the_semaphore->Core_control.Mutex.Recursive,
78        executing,
79        wait,
80        _CORE_recursive_mutex_Seize_nested,
81        &queue_context
82      );
83      break;
84    case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
85      status = _CORE_ceiling_mutex_Seize(
86        &the_semaphore->Core_control.Mutex,
87        executing,
88        wait,
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        _CORE_recursive_mutex_Seize_nested,
100        &queue_context
101      );
102      break;
103#if defined(RTEMS_SMP)
104    case SEMAPHORE_VARIANT_MRSP:
105      status = _MRSP_Seize(
106        &the_semaphore->Core_control.MRSP,
107        executing,
108        wait,
109        &queue_context
110      );
111      break;
112#endif
113    default:
114      _Assert(
115        the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
116          || the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING
117      );
118      status = _CORE_semaphore_Seize(
119        &the_semaphore->Core_control.Semaphore,
120        _Semaphore_Get_operations( the_semaphore ),
121        executing,
122        wait,
123        &queue_context
124      );
125      break;
126  }
127
128  return _Status_Get( status );
129}
Note: See TracBrowser for help on using the repository browser.