source: rtems/cpukit/score/src/coresemsurrender.c @ e76c517

4.115
Last change on this file since e76c517 was e76c517, checked in by Sebastian Huber <sebastian.huber@…>, on 05/01/15 at 18:52:51

score: Fine grained locking for semaphores

Update #2273.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Surrenders a Unit to a Semaphore
5 *
6 * @ingroup ScoreSemaphore
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-1999.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/score/coresemimpl.h>
23
24CORE_semaphore_Status _CORE_semaphore_Surrender(
25  CORE_semaphore_Control                *the_semaphore,
26  Objects_Id                             id,
27  CORE_semaphore_API_mp_support_callout  api_semaphore_mp_support,
28  ISR_lock_Context                      *lock_context
29)
30{
31  Thread_Control *the_thread;
32  CORE_semaphore_Status status;
33
34  status = CORE_SEMAPHORE_STATUS_SUCCESSFUL;
35
36  _Thread_queue_Acquire_critical( &the_semaphore->Wait_queue, lock_context );
37
38  the_thread = _Thread_queue_First_locked( &the_semaphore->Wait_queue );
39  if ( the_thread != NULL ) {
40#if defined(RTEMS_MULTIPROCESSING)
41    _Thread_Dispatch_disable();
42#endif
43
44    _Thread_queue_Extract_critical(
45      &the_semaphore->Wait_queue,
46      the_thread,
47      lock_context
48    );
49
50#if defined(RTEMS_MULTIPROCESSING)
51    if ( !_Objects_Is_local_id( the_thread->Object.id ) )
52      (*api_semaphore_mp_support) ( the_thread, id );
53
54    _Thread_Dispatch_enable( _Per_CPU_Get() );
55#endif
56  } else {
57    if ( the_semaphore->count < the_semaphore->Attributes.maximum_count )
58      the_semaphore->count += 1;
59    else
60      status = CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED;
61
62    _Thread_queue_Release( &the_semaphore->Wait_queue, lock_context );
63  }
64
65  return status;
66}
Note: See TracBrowser for help on using the repository browser.