[ef9505a9] | 1 | /* apimutex.h |
---|
| 2 | * |
---|
| 3 | * This include file contains all the constants and structures associated |
---|
| 4 | * with the API Mutex Handler. This handler is used by API level |
---|
| 5 | * routines to manage mutual exclusion. |
---|
| 6 | * |
---|
| 7 | * COPYRIGHT (c) 1989-2002. |
---|
| 8 | * On-Line Applications Research Corporation (OAR). |
---|
| 9 | * |
---|
| 10 | * The license and distribution terms for this file may be |
---|
| 11 | * found in the file LICENSE in this distribution or at |
---|
| 12 | * http://www.OARcorp.com/rtems/license.html. |
---|
| 13 | * |
---|
| 14 | * $Id$ |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #ifndef __API_MUTEX_h |
---|
| 18 | #define __API_MUTEX_h |
---|
| 19 | |
---|
| 20 | #ifdef __cplusplus |
---|
| 21 | extern "C" { |
---|
| 22 | #endif |
---|
| 23 | |
---|
| 24 | #include <rtems/score/coremutex.h> |
---|
| 25 | #include <rtems/score/isr.h> |
---|
| 26 | #include <rtems/score/object.h> |
---|
| 27 | |
---|
| 28 | /* |
---|
| 29 | * The following defines the control block used to manage each mutex. |
---|
| 30 | */ |
---|
| 31 | |
---|
| 32 | typedef struct { |
---|
| 33 | Objects_Control Object; |
---|
| 34 | CORE_mutex_Control Mutex; |
---|
| 35 | } API_Mutex_Control; |
---|
| 36 | |
---|
| 37 | /* |
---|
| 38 | * The following defines the information control block used to manage |
---|
| 39 | * this class of objects. |
---|
| 40 | */ |
---|
| 41 | |
---|
| 42 | SCORE_EXTERN Objects_Information _API_Mutex_Information; |
---|
| 43 | |
---|
| 44 | /* |
---|
| 45 | * _API_Mutex_Initialization |
---|
| 46 | * |
---|
| 47 | * DESCRIPTION: |
---|
| 48 | * |
---|
| 49 | * This routine performs the initialization necessary for this handler. |
---|
| 50 | */ |
---|
| 51 | |
---|
| 52 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 53 | #define _API_Mutex_Initialization( _maximum_mutexes ) \ |
---|
| 54 | _Objects_Initialize_information( \ |
---|
| 55 | &_API_Mutex_Information, \ |
---|
| 56 | OBJECTS_INTERNAL_API, \ |
---|
| 57 | OBJECTS_INTERNAL_MUTEXES, \ |
---|
| 58 | _maximum_mutexes, \ |
---|
| 59 | sizeof( API_Mutex_Control ), \ |
---|
| 60 | FALSE, \ |
---|
| 61 | 0, \ |
---|
| 62 | FALSE, \ |
---|
| 63 | NULL \ |
---|
| 64 | ); |
---|
| 65 | #else |
---|
| 66 | #define _API_Mutex_Initialization( _maximum_mutexes ) \ |
---|
| 67 | _Objects_Initialize_information( \ |
---|
| 68 | &_API_Mutex_Information, \ |
---|
| 69 | OBJECTS_INTERNAL_API, \ |
---|
| 70 | OBJECTS_INTERNAL_MUTEXES, \ |
---|
| 71 | _maximum_mutexes, \ |
---|
| 72 | sizeof( API_Mutex_Control ), \ |
---|
| 73 | FALSE, \ |
---|
| 74 | 0 \ |
---|
| 75 | ); |
---|
| 76 | #endif |
---|
| 77 | |
---|
| 78 | /* |
---|
| 79 | * _API_Mutex_Allocate |
---|
| 80 | * |
---|
| 81 | * DESCRIPTION: |
---|
| 82 | * |
---|
| 83 | * This routine allocates an api mutex from the inactive set. |
---|
| 84 | */ |
---|
| 85 | |
---|
| 86 | #define _API_Mutex_Allocate( _the_mutex ) \ |
---|
| 87 | do { \ |
---|
| 88 | CORE_mutex_Attributes attr = \ |
---|
| 89 | { CORE_MUTEX_NESTING_IS_ERROR, FALSE, \ |
---|
| 90 | CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT, 0 }; \ |
---|
| 91 | (_the_mutex) = (API_Mutex_Control *) \ |
---|
| 92 | _Objects_Allocate( &_API_Mutex_Information ); \ |
---|
| 93 | _CORE_mutex_Initialize( \ |
---|
| 94 | &(_the_mutex)->Mutex, &attr, CORE_MUTEX_UNLOCKED ); \ |
---|
| 95 | } while (0) |
---|
| 96 | |
---|
| 97 | /* |
---|
| 98 | * _API_Mutex_Lock |
---|
| 99 | * |
---|
| 100 | * DESCRIPTION: |
---|
| 101 | * |
---|
| 102 | * This routine acquires the specified api mutex. |
---|
| 103 | */ |
---|
| 104 | |
---|
| 105 | #define _API_Mutex_Lock( _the_mutex ) \ |
---|
| 106 | do { \ |
---|
| 107 | ISR_Level _level; \ |
---|
| 108 | _CORE_mutex_Seize( \ |
---|
| 109 | &(_the_mutex)->Mutex, (_the_mutex)->Object.id, TRUE, 0, (_level) ); \ |
---|
| 110 | } while (0) |
---|
| 111 | |
---|
| 112 | /* |
---|
| 113 | * _API_Mutex_Unlock |
---|
| 114 | * |
---|
| 115 | * DESCRIPTION: |
---|
| 116 | * |
---|
| 117 | * This routine releases the specified api mutex. |
---|
| 118 | */ |
---|
| 119 | |
---|
| 120 | #define _API_Mutex_Unlock( _the_mutex ) \ |
---|
| 121 | do { \ |
---|
| 122 | _Thread_Disable_dispatch(); \ |
---|
| 123 | _CORE_mutex_Surrender( \ |
---|
| 124 | &(_the_mutex)->Mutex, (_the_mutex)->Object.id, NULL ); \ |
---|
| 125 | _Thread_Enable_dispatch(); \ |
---|
| 126 | } while (0); |
---|
| 127 | |
---|
| 128 | /*XXX when the APIs all use this for allocation and deallocation |
---|
| 129 | *XXX protection, then they should be renamed and probably moved |
---|
| 130 | */ |
---|
| 131 | |
---|
| 132 | SCORE_EXTERN API_Mutex_Control *_RTEMS_Allocator_Mutex; |
---|
| 133 | |
---|
| 134 | #define _RTEMS_Lock_allocator() \ |
---|
| 135 | _API_Mutex_Lock( _RTEMS_Allocator_Mutex ) |
---|
| 136 | |
---|
| 137 | #define _RTEMS_Unlock_allocator() \ |
---|
| 138 | _API_Mutex_Unlock( _RTEMS_Allocator_Mutex ) |
---|
| 139 | |
---|
| 140 | /* |
---|
| 141 | * There are no inlines for this handler. |
---|
| 142 | */ |
---|
| 143 | |
---|
| 144 | #ifndef __RTEMS_APPLICATION__ |
---|
| 145 | /* #include <rtems/score/apimutex.inl> */ |
---|
| 146 | #endif |
---|
| 147 | |
---|
| 148 | #ifdef __cplusplus |
---|
| 149 | } |
---|
| 150 | #endif |
---|
| 151 | |
---|
| 152 | #endif |
---|
| 153 | /* end of include file */ |
---|