source: rtems/cpukit/rtems/src/semflush.c @ 4025a60f

5
Last change on this file since 4025a60f was 4025a60f, checked in by Sebastian Huber <sebastian.huber@…>, on 04/19/16 at 15:02:54

score: Avoid Giant lock for CORE mtx/sem

Avoid Giant lock for CORE mutex and semaphore flush and delete
operations.

Update #2555.

  • Property mode set to 100644
File size: 2.3 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/system.h>
22#include <rtems/rtems/status.h>
23#include <rtems/rtems/support.h>
24#include <rtems/rtems/attrimpl.h>
25#include <rtems/score/isr.h>
26#include <rtems/rtems/options.h>
27#include <rtems/rtems/semimpl.h>
28#include <rtems/score/coremuteximpl.h>
29#include <rtems/score/coresemimpl.h>
30#include <rtems/score/thread.h>
31
32#include <rtems/score/interr.h>
33
34rtems_status_code rtems_semaphore_flush(
35  rtems_id        id
36)
37{
38  Semaphore_Control          *the_semaphore;
39  Objects_Locations           location;
40  ISR_lock_Context            lock_context;
41  rtems_attribute             attribute_set;
42
43  the_semaphore = _Semaphore_Get_interrupt_disable(
44    id,
45    &location,
46    &lock_context
47  );
48  switch ( location ) {
49
50    case OBJECTS_LOCAL:
51      attribute_set = the_semaphore->attribute_set;
52#if defined(RTEMS_SMP)
53      if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
54        _ISR_lock_ISR_enable( &lock_context );
55        return RTEMS_NOT_DEFINED;
56      } else
57#endif
58      if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
59        _CORE_mutex_Acquire_critical(
60          &the_semaphore->Core_control.mutex,
61          &lock_context
62        );
63        _CORE_mutex_Flush(
64          &the_semaphore->Core_control.mutex,
65          _CORE_mutex_Unsatisfied_nowait,
66          _Semaphore_MP_Send_object_was_deleted,
67          id,
68          &lock_context
69        );
70      } else {
71        _CORE_semaphore_Acquire_critical(
72          &the_semaphore->Core_control.semaphore,
73          &lock_context
74        );
75        _CORE_semaphore_Flush(
76          &the_semaphore->Core_control.semaphore,
77          _Semaphore_MP_Send_object_was_deleted,
78          id,
79          &lock_context
80        );
81      }
82      return RTEMS_SUCCESSFUL;
83
84#if defined(RTEMS_MULTIPROCESSING)
85    case OBJECTS_REMOTE:
86      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
87#endif
88
89    case OBJECTS_ERROR:
90      break;
91  }
92
93  return RTEMS_INVALID_ID;
94}
Note: See TracBrowser for help on using the repository browser.