source: rtems/cpukit/rtems/src/semflush.c @ 21275b58

5
Last change on this file since 21275b58 was 114e408, checked in by Sebastian Huber <sebastian.huber@…>, on 08/22/16 at 11:17:05

score: Simplify thread queue acquire/release

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS Semaphore Flush
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
23rtems_status_code rtems_semaphore_flush( rtems_id id )
24{
25  Semaphore_Control    *the_semaphore;
26  Thread_queue_Context  queue_context;
27
28  the_semaphore = _Semaphore_Get( id, &queue_context );
29
30  if ( the_semaphore == NULL ) {
31#if defined(RTEMS_MULTIPROCESSING)
32    if ( _Semaphore_MP_Is_remote( id ) ) {
33      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
34    }
35#endif
36
37    return RTEMS_INVALID_ID;
38  }
39
40  _Thread_queue_Acquire_critical(
41    &the_semaphore->Core_control.Wait_queue,
42    &queue_context
43  );
44  _Thread_queue_Context_set_MP_callout(
45    &queue_context,
46    _Semaphore_MP_Send_object_was_deleted
47  );
48
49  switch ( the_semaphore->variant ) {
50#if defined(RTEMS_SMP)
51    case SEMAPHORE_VARIANT_MRSP:
52      _Thread_queue_Release(
53        &the_semaphore->Core_control.Wait_queue,
54        &queue_context
55      );
56      return RTEMS_NOT_DEFINED;
57#endif
58    default:
59      _Assert(
60        the_semaphore->variant == SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY
61          || the_semaphore->variant == SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING
62          || the_semaphore->variant == SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL
63          || the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
64          || the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING
65      );
66      _Thread_queue_Flush_critical(
67        &the_semaphore->Core_control.Wait_queue.Queue,
68        _Semaphore_Get_operations( the_semaphore ),
69        _Thread_queue_Flush_status_unavailable,
70        &queue_context
71      );
72      break;
73  }
74
75  return RTEMS_SUCCESSFUL;
76}
Note: See TracBrowser for help on using the repository browser.