source: rtems/cpukit/rtems/src/semrelease.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: 1.7 KB
Line 
1/**
2 * @file
3 *
4 * @brief RTEMS Semaphore Release
5 * @ingroup ClassicSem Semaphores
6 *
7 * This file contains the implementation of the Classic API directive
8 * rtems_semaphore_release().
9 */
10
11/*
12 *  COPYRIGHT (c) 1989-2014.
13 *  On-Line Applications Research Corporation (OAR).
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.rtems.org/license/LICENSE.
18 */
19
20#if HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include <rtems/rtems/semimpl.h>
25#include <rtems/rtems/statusimpl.h>
26
27rtems_status_code rtems_semaphore_release( rtems_id id )
28{
29  Semaphore_Control    *the_semaphore;
30  Thread_queue_Context  queue_context;
31  Status_Control        status;
32
33  the_semaphore = _Semaphore_Get( id, &queue_context );
34
35  if ( the_semaphore == NULL ) {
36#if defined(RTEMS_MULTIPROCESSING)
37    return _Semaphore_MP_Release( id );
38#else
39    return RTEMS_INVALID_ID;
40#endif
41  }
42
43  _Thread_queue_Context_set_MP_callout(
44    &queue_context,
45    _Semaphore_Core_mutex_mp_support
46  );
47
48  switch ( the_semaphore->variant ) {
49#if defined(RTEMS_SMP)
50    case SEMAPHORE_VARIANT_MRSP:
51      status = _MRSP_Surrender(
52        &the_semaphore->Core_control.mrsp,
53        _Thread_Executing,
54        &queue_context
55      );
56      break;
57#endif
58    case SEMAPHORE_VARIANT_MUTEX:
59      status = _CORE_mutex_Surrender(
60        &the_semaphore->Core_control.mutex,
61        &queue_context
62      );
63      break;
64    default:
65      _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING );
66      status = _CORE_semaphore_Surrender(
67        &the_semaphore->Core_control.semaphore,
68        _Semaphore_Get_operations( the_semaphore ),
69        UINT32_MAX,
70        &queue_context
71      );
72      break;
73  }
74
75  return _Status_Get( status );
76}
Note: See TracBrowser for help on using the repository browser.