summaryrefslogblamecommitdiffstats
path: root/cpukit/score/src/coremutexseize.c
blob: 67954b697b09f70f58538cc580f160969aa82611 (plain) (tree)
1
2
3
4
5
6
7
8
9

         
  




                                    
                            
                                                    


                                                           
                                         

   



                   

                            
                                      
                                      
                                   
                               
 


                                                     
                                  
                           
                             



                                







                         


      
                                          
                                 
                                 

                                   

 
                             
 
                                                                    

                                               






                                                                           
                                         

                               


                                  

                                          

   

                                                                         


                             

                
    
 
                            
 
 
/**
 *  @file
 *
 *  @brief Seize Mutex with Blocking
 *  @ingroup ScoreMutex
 */

/*
 *  COPYRIGHT (c) 1989-2006.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#if HAVE_CONFIG_H
#include "config.h"
#endif

#include <rtems/system.h>
#include <rtems/score/isr.h>
#include <rtems/score/coremuteximpl.h>
#include <rtems/score/schedulerimpl.h>
#include <rtems/score/statesimpl.h>
#include <rtems/score/thread.h>

#if defined(__RTEMS_DO_NOT_INLINE_CORE_MUTEX_SEIZE__)
void _CORE_mutex_Seize(
  CORE_mutex_Control  *_the_mutex,
  Thread_Control      *_executing,
  Objects_Id           _id,
  bool                 _wait,
  Watchdog_Interval    _timeout,
  ISR_Level            _level
)
{
  _CORE_mutex_Seize_body(
    _the_mutex,
    _executing,
    _id,
    _wait,
    _timeout,
    _level
  );
}
#endif

void _CORE_mutex_Seize_interrupt_blocking(
  CORE_mutex_Control  *the_mutex,
  Thread_Control      *executing,
  Watchdog_Interval    timeout,
  ISR_lock_Context    *lock_context
)
{
  _Thread_Disable_dispatch();

  if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ) {
    Thread_Control *holder = the_mutex->holder;

    /*
     * To enable interrupts here works only since we own the Giant lock and
     * only threads are allowed to seize and surrender mutexes with the
     * priority inheritance protocol.
     */
    _ISR_lock_ISR_enable( lock_context );

    _Scheduler_Change_priority_if_higher(
      _Scheduler_Get( holder ),
      holder,
      executing->current_priority,
      false
    );

    _ISR_lock_ISR_disable( lock_context );
  }

  _Thread_queue_Acquire_critical( &the_mutex->Wait_queue, lock_context );
  _Thread_queue_Enqueue_critical(
    &the_mutex->Wait_queue,
    executing,
    STATES_WAITING_FOR_MUTEX,
    timeout,
    lock_context
  );

  _Thread_Enable_dispatch();
}