[c06d8f64] | 1 | /* |
---|
| 2 | * Semaphore Manager |
---|
| 3 | * |
---|
| 4 | * DESCRIPTION: |
---|
| 5 | * |
---|
| 6 | * This package is the implementation of the Semaphore Manager. |
---|
| 7 | * This manager utilizes standard Dijkstra counting semaphores to provide |
---|
| 8 | * synchronization and mutual exclusion capabilities. |
---|
| 9 | * |
---|
| 10 | * Directives provided are: |
---|
| 11 | * |
---|
| 12 | * + create a semaphore |
---|
| 13 | * + get an ID of a semaphore |
---|
| 14 | * + delete a semaphore |
---|
| 15 | * + acquire a semaphore |
---|
| 16 | * + release a semaphore |
---|
| 17 | * |
---|
[08311cc3] | 18 | * COPYRIGHT (c) 1989-1999. |
---|
[c06d8f64] | 19 | * On-Line Applications Research Corporation (OAR). |
---|
| 20 | * |
---|
| 21 | * The license and distribution terms for this file may be |
---|
| 22 | * found in the file LICENSE in this distribution or at |
---|
[277cc95] | 23 | * http://www.rtems.com/license/LICENSE. |
---|
[c06d8f64] | 24 | * |
---|
| 25 | * $Id$ |
---|
| 26 | */ |
---|
| 27 | |
---|
[1095ec1] | 28 | #if HAVE_CONFIG_H |
---|
| 29 | #include "config.h" |
---|
| 30 | #endif |
---|
| 31 | |
---|
[c06d8f64] | 32 | #include <rtems/system.h> |
---|
| 33 | #include <rtems/rtems/status.h> |
---|
| 34 | #include <rtems/rtems/support.h> |
---|
| 35 | #include <rtems/rtems/attr.h> |
---|
| 36 | #include <rtems/score/isr.h> |
---|
| 37 | #include <rtems/score/object.h> |
---|
| 38 | #include <rtems/rtems/options.h> |
---|
| 39 | #include <rtems/rtems/sem.h> |
---|
| 40 | #include <rtems/score/coremutex.h> |
---|
| 41 | #include <rtems/score/coresem.h> |
---|
| 42 | #include <rtems/score/states.h> |
---|
| 43 | #include <rtems/score/thread.h> |
---|
| 44 | #include <rtems/score/threadq.h> |
---|
| 45 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 46 | #include <rtems/score/mpci.h> |
---|
| 47 | #endif |
---|
| 48 | #include <rtems/score/sysstate.h> |
---|
| 49 | |
---|
| 50 | #include <rtems/score/interr.h> |
---|
| 51 | |
---|
| 52 | /*PAGE |
---|
| 53 | * |
---|
| 54 | * _Semaphore_Translate_core_mutex_return_code |
---|
| 55 | * |
---|
| 56 | * Input parameters: |
---|
| 57 | * the_mutex_status - mutex status code to translate |
---|
| 58 | * |
---|
| 59 | * Output parameters: |
---|
| 60 | * rtems status code - translated RTEMS status code |
---|
| 61 | * |
---|
| 62 | */ |
---|
[50f32b11] | 63 | |
---|
[8ce962c0] | 64 | rtems_status_code _Semaphore_Translate_core_mutex_return_code_[] = { |
---|
| 65 | RTEMS_SUCCESSFUL, /* CORE_MUTEX_STATUS_SUCCESSFUL */ |
---|
| 66 | RTEMS_UNSATISFIED, /* CORE_MUTEX_STATUS_UNSATISFIED_NOWAIT */ |
---|
| 67 | RTEMS_UNSATISFIED, /* CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED */ |
---|
| 68 | RTEMS_NOT_OWNER_OF_RESOURCE, /* CORE_MUTEX_STATUS_NOT_OWNER_OF_RESOURCE */ |
---|
| 69 | RTEMS_OBJECT_WAS_DELETED, /* CORE_MUTEX_WAS_DELETED */ |
---|
| 70 | RTEMS_TIMEOUT, /* CORE_MUTEX_TIMEOUT */ |
---|
| 71 | RTEMS_INTERNAL_ERROR, /* CORE_MUTEX_STATUS_CEILING_VIOLATED */ |
---|
| 72 | }; |
---|
| 73 | |
---|
| 74 | |
---|
[c06d8f64] | 75 | rtems_status_code _Semaphore_Translate_core_mutex_return_code ( |
---|
[1d496f6] | 76 | uint32_t the_mutex_status |
---|
[c06d8f64] | 77 | ) |
---|
| 78 | { |
---|
[8ce962c0] | 79 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[50f32b11] | 80 | if ( the_mutex_status == THREAD_STATUS_PROXY_BLOCKING ) |
---|
[8ce962c0] | 81 | return RTEMS_PROXY_BLOCKING; |
---|
[50f32b11] | 82 | else |
---|
[8ce962c0] | 83 | #endif |
---|
| 84 | if ( the_mutex_status > CORE_MUTEX_STATUS_CEILING_VIOLATED ) |
---|
| 85 | return RTEMS_INTERNAL_ERROR; |
---|
| 86 | else |
---|
| 87 | return _Semaphore_Translate_core_mutex_return_code_[the_mutex_status]; |
---|
[c06d8f64] | 88 | } |
---|
| 89 | |
---|
| 90 | /*PAGE |
---|
| 91 | * |
---|
| 92 | * _Semaphore_Translate_core_semaphore_return_code |
---|
| 93 | * |
---|
| 94 | * Input parameters: |
---|
| 95 | * the_semaphore_status - semaphore status code to translate |
---|
| 96 | * |
---|
| 97 | * Output parameters: |
---|
| 98 | * rtems status code - translated RTEMS status code |
---|
| 99 | * |
---|
| 100 | */ |
---|
[50f32b11] | 101 | |
---|
[8ce962c0] | 102 | rtems_status_code _Semaphore_Translate_core_semaphore_return_code_[] = { |
---|
| 103 | RTEMS_SUCCESSFUL, /* CORE_SEMAPHORE_STATUS_SUCCESSFUL */ |
---|
| 104 | RTEMS_UNSATISFIED, /* CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT */ |
---|
| 105 | RTEMS_OBJECT_WAS_DELETED, /* CORE_SEMAPHORE_WAS_DELETED */ |
---|
| 106 | RTEMS_TIMEOUT, /* CORE_SEMAPHORE_TIMEOUT */ |
---|
| 107 | RTEMS_INTERNAL_ERROR, /* CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED */ |
---|
[50f32b11] | 108 | |
---|
[8ce962c0] | 109 | }; |
---|
| 110 | |
---|
[c06d8f64] | 111 | rtems_status_code _Semaphore_Translate_core_semaphore_return_code ( |
---|
[1d496f6] | 112 | uint32_t the_semaphore_status |
---|
[c06d8f64] | 113 | ) |
---|
| 114 | { |
---|
[8ce962c0] | 115 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[50f32b11] | 116 | if ( the_semaphore_status == THREAD_STATUS_PROXY_BLOCKING ) |
---|
[8ce962c0] | 117 | return RTEMS_PROXY_BLOCKING; |
---|
[50f32b11] | 118 | else |
---|
[8ce962c0] | 119 | #endif |
---|
| 120 | if ( the_semaphore_status > CORE_MUTEX_STATUS_CEILING_VIOLATED ) |
---|
| 121 | return RTEMS_INTERNAL_ERROR; |
---|
| 122 | else |
---|
| 123 | return _Semaphore_Translate_core_semaphore_return_code_[the_semaphore_status]; |
---|
[c06d8f64] | 124 | } |
---|