source: rtems/cpukit/rtems/src/semobtain.c @ 2581a56

5
Last change on this file since 2581a56 was 2581a56, checked in by Sebastian Huber <sebastian.huber@…>, on 05/20/16 at 19:39:56

score: Add semaphore variants

  • Property mode set to 100644
File size: 2.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.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:
85      status = _CORE_mutex_Seize(
86        &the_semaphore->Core_control.mutex,
87        executing,
88        wait,
89        timeout,
90        &queue_context
91      );
92      break;
93    default:
94      _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING );
95      status = _CORE_semaphore_Seize(
96        &the_semaphore->Core_control.semaphore,
97        _Semaphore_Get_operations( the_semaphore ),
98        executing,
99        wait,
100        timeout,
101        &queue_context
102      );
103      break;
104  }
105
106  return _Status_Get( status );
107}
Note: See TracBrowser for help on using the repository browser.