[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 |
---|
| 23 | * http://www.OARcorp.com/rtems/license.html. |
---|
| 24 | * |
---|
| 25 | * $Id$ |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | #include <rtems/system.h> |
---|
| 29 | #include <rtems/rtems/status.h> |
---|
| 30 | #include <rtems/rtems/support.h> |
---|
| 31 | #include <rtems/rtems/attr.h> |
---|
| 32 | #include <rtems/score/isr.h> |
---|
| 33 | #include <rtems/score/object.h> |
---|
| 34 | #include <rtems/rtems/options.h> |
---|
| 35 | #include <rtems/rtems/sem.h> |
---|
| 36 | #include <rtems/score/coremutex.h> |
---|
| 37 | #include <rtems/score/coresem.h> |
---|
| 38 | #include <rtems/score/states.h> |
---|
| 39 | #include <rtems/score/thread.h> |
---|
| 40 | #include <rtems/score/threadq.h> |
---|
| 41 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 42 | #include <rtems/score/mpci.h> |
---|
| 43 | #endif |
---|
| 44 | #include <rtems/score/sysstate.h> |
---|
| 45 | |
---|
| 46 | #include <rtems/score/interr.h> |
---|
| 47 | |
---|
| 48 | /*PAGE |
---|
| 49 | * |
---|
| 50 | * _Semaphore_Translate_core_mutex_return_code |
---|
| 51 | * |
---|
| 52 | * Input parameters: |
---|
| 53 | * the_mutex_status - mutex status code to translate |
---|
| 54 | * |
---|
| 55 | * Output parameters: |
---|
| 56 | * rtems status code - translated RTEMS status code |
---|
| 57 | * |
---|
| 58 | */ |
---|
| 59 | |
---|
| 60 | rtems_status_code _Semaphore_Translate_core_mutex_return_code ( |
---|
| 61 | unsigned32 the_mutex_status |
---|
| 62 | ) |
---|
| 63 | { |
---|
| 64 | switch ( the_mutex_status ) { |
---|
| 65 | case CORE_MUTEX_STATUS_SUCCESSFUL: |
---|
| 66 | return RTEMS_SUCCESSFUL; |
---|
| 67 | case CORE_MUTEX_STATUS_UNSATISFIED_NOWAIT: |
---|
| 68 | return RTEMS_UNSATISFIED; |
---|
| 69 | case CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED: |
---|
[7d91d72] | 70 | return RTEMS_UNSATISFIED; |
---|
[c06d8f64] | 71 | case CORE_MUTEX_STATUS_NOT_OWNER_OF_RESOURCE: |
---|
| 72 | return RTEMS_NOT_OWNER_OF_RESOURCE; |
---|
| 73 | case CORE_MUTEX_WAS_DELETED: |
---|
| 74 | return RTEMS_OBJECT_WAS_DELETED; |
---|
| 75 | case CORE_MUTEX_TIMEOUT: |
---|
| 76 | return RTEMS_TIMEOUT; |
---|
| 77 | case THREAD_STATUS_PROXY_BLOCKING: |
---|
[bf24479] | 78 | return RTEMS_PROXY_BLOCKING; |
---|
[c06d8f64] | 79 | } |
---|
| 80 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | /*PAGE |
---|
| 84 | * |
---|
| 85 | * _Semaphore_Translate_core_semaphore_return_code |
---|
| 86 | * |
---|
| 87 | * Input parameters: |
---|
| 88 | * the_semaphore_status - semaphore status code to translate |
---|
| 89 | * |
---|
| 90 | * Output parameters: |
---|
| 91 | * rtems status code - translated RTEMS status code |
---|
| 92 | * |
---|
| 93 | */ |
---|
| 94 | |
---|
| 95 | rtems_status_code _Semaphore_Translate_core_semaphore_return_code ( |
---|
| 96 | unsigned32 the_semaphore_status |
---|
| 97 | ) |
---|
| 98 | { |
---|
| 99 | switch ( the_semaphore_status ) { |
---|
| 100 | case CORE_SEMAPHORE_STATUS_SUCCESSFUL: |
---|
| 101 | return RTEMS_SUCCESSFUL; |
---|
| 102 | case CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT: |
---|
| 103 | return RTEMS_UNSATISFIED; |
---|
| 104 | case CORE_SEMAPHORE_WAS_DELETED: |
---|
| 105 | return RTEMS_OBJECT_WAS_DELETED; |
---|
| 106 | case CORE_SEMAPHORE_TIMEOUT: |
---|
| 107 | return RTEMS_TIMEOUT; |
---|
[b970c48] | 108 | |
---|
| 109 | /* |
---|
| 110 | * An overflow should not occur in the Classic API. |
---|
| 111 | */ |
---|
| 112 | |
---|
| 113 | case CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED: |
---|
| 114 | return RTEMS_INTERNAL_ERROR; |
---|
| 115 | |
---|
[c06d8f64] | 116 | case THREAD_STATUS_PROXY_BLOCKING: |
---|
[edb2176] | 117 | return RTEMS_PROXY_BLOCKING; |
---|
[c06d8f64] | 118 | } |
---|
| 119 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
| 120 | } |
---|