[3a4ae6c] | 1 | /* |
---|
| 2 | * Mutex Handler |
---|
| 3 | * |
---|
| 4 | * DESCRIPTION: |
---|
| 5 | * |
---|
| 6 | * This package is the implementation of the Mutex Handler. |
---|
| 7 | * This handler provides synchronization and mutual exclusion capabilities. |
---|
| 8 | * |
---|
[08311cc3] | 9 | * COPYRIGHT (c) 1989-1999. |
---|
[3a4ae6c] | 10 | * On-Line Applications Research Corporation (OAR). |
---|
| 11 | * |
---|
[98e4ebf5] | 12 | * The license and distribution terms for this file may be |
---|
| 13 | * found in the file LICENSE in this distribution or at |
---|
[03f2154e] | 14 | * http://www.OARcorp.com/rtems/license.html. |
---|
[3a4ae6c] | 15 | * |
---|
| 16 | * $Id$ |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #include <rtems/system.h> |
---|
[5e9b32b] | 20 | #include <rtems/score/isr.h> |
---|
| 21 | #include <rtems/score/coremutex.h> |
---|
| 22 | #include <rtems/score/states.h> |
---|
| 23 | #include <rtems/score/thread.h> |
---|
| 24 | #include <rtems/score/threadq.h> |
---|
[3a4ae6c] | 25 | |
---|
| 26 | /*PAGE |
---|
| 27 | * |
---|
| 28 | * _CORE_mutex_Initialize |
---|
| 29 | * |
---|
| 30 | * This routine initializes a mutex at create time and set the control |
---|
| 31 | * structure according to the values passed. |
---|
| 32 | * |
---|
| 33 | * Input parameters: |
---|
| 34 | * the_mutex - the mutex control block to initialize |
---|
| 35 | * the_class - the API class of the object |
---|
| 36 | * the_mutex_attributes - the mutex attributes specified at create time |
---|
| 37 | * initial_lock - mutex initial lock or unlocked status |
---|
| 38 | * proxy_extract_callout - MP specific extract callout |
---|
| 39 | * |
---|
| 40 | * Output parameters: NONE |
---|
| 41 | */ |
---|
[742b399] | 42 | |
---|
[3a4ae6c] | 43 | void _CORE_mutex_Initialize( |
---|
| 44 | CORE_mutex_Control *the_mutex, |
---|
| 45 | Objects_Classes the_class, |
---|
| 46 | CORE_mutex_Attributes *the_mutex_attributes, |
---|
| 47 | unsigned32 initial_lock, |
---|
| 48 | Thread_queue_Extract_callout proxy_extract_callout |
---|
| 49 | ) |
---|
| 50 | { |
---|
| 51 | |
---|
| 52 | /* Add this to the RTEMS environment later ????????? |
---|
| 53 | rtems_assert( initial_lock == CORE_MUTEX_LOCKED || |
---|
| 54 | initial_lock == CORE_MUTEX_UNLOCKED ); |
---|
| 55 | */ |
---|
| 56 | |
---|
| 57 | the_mutex->Attributes = *the_mutex_attributes; |
---|
[5870ac55] | 58 | the_mutex->lock = initial_lock; |
---|
| 59 | |
---|
| 60 | #if 0 |
---|
| 61 | if ( !the_mutex_attributes->only_owner_release && |
---|
| 62 | the_mutex_attributes->nesting_allowed ) { |
---|
| 63 | _Internal_error_Occurred( |
---|
| 64 | INTERNAL_ERROR_CORE, |
---|
| 65 | TRUE, |
---|
| 66 | INTERNAL_ERROR_BAD_ATTRIBUTES |
---|
| 67 | ); |
---|
| 68 | } |
---|
| 69 | #endif |
---|
[742b399] | 70 | |
---|
[3a4ae6c] | 71 | if ( initial_lock == CORE_MUTEX_LOCKED ) { |
---|
| 72 | the_mutex->nest_count = 1; |
---|
| 73 | the_mutex->holder = _Thread_Executing; |
---|
| 74 | the_mutex->holder_id = _Thread_Executing->Object.id; |
---|
[6f1118a] | 75 | if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) || |
---|
| 76 | _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) |
---|
| 77 | _Thread_Executing->resource_count++; |
---|
[3a4ae6c] | 78 | } else { |
---|
| 79 | the_mutex->nest_count = 0; |
---|
| 80 | the_mutex->holder = NULL; |
---|
| 81 | the_mutex->holder_id = 0; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | _Thread_queue_Initialize( |
---|
| 85 | &the_mutex->Wait_queue, |
---|
| 86 | the_class, |
---|
[1d9d044] | 87 | _CORE_mutex_Is_fifo( the_mutex_attributes ) ? |
---|
| 88 | THREAD_QUEUE_DISCIPLINE_FIFO : THREAD_QUEUE_DISCIPLINE_PRIORITY, |
---|
[3a4ae6c] | 89 | STATES_WAITING_FOR_MUTEX, |
---|
| 90 | proxy_extract_callout, |
---|
| 91 | CORE_MUTEX_TIMEOUT |
---|
| 92 | ); |
---|
| 93 | } |
---|
| 94 | |
---|