[e7264f07] | 1 | /* |
---|
| 2 | * rtems_semaphore_flush |
---|
| 3 | * |
---|
| 4 | * DESCRIPTION: |
---|
| 5 | * |
---|
| 6 | * This package is the implementation of the flush directive |
---|
| 7 | * of the Semaphore Manager. |
---|
| 8 | * |
---|
[08311cc3] | 9 | * COPYRIGHT (c) 1989-1999. |
---|
[e7264f07] | 10 | * On-Line Applications Research Corporation (OAR). |
---|
| 11 | * |
---|
| 12 | * The license and distribution terms for this file may be |
---|
| 13 | * found in the file LICENSE in this distribution or at |
---|
[277cc95] | 14 | * http://www.rtems.com/license/LICENSE. |
---|
[e7264f07] | 15 | * |
---|
| 16 | * $Id$ |
---|
| 17 | */ |
---|
| 18 | |
---|
[1095ec1] | 19 | #if HAVE_CONFIG_H |
---|
| 20 | #include "config.h" |
---|
| 21 | #endif |
---|
| 22 | |
---|
[e7264f07] | 23 | #include <rtems/system.h> |
---|
| 24 | #include <rtems/rtems/status.h> |
---|
| 25 | #include <rtems/rtems/support.h> |
---|
| 26 | #include <rtems/rtems/attr.h> |
---|
| 27 | #include <rtems/score/isr.h> |
---|
| 28 | #include <rtems/score/object.h> |
---|
| 29 | #include <rtems/rtems/options.h> |
---|
| 30 | #include <rtems/rtems/sem.h> |
---|
| 31 | #include <rtems/score/coremutex.h> |
---|
| 32 | #include <rtems/score/coresem.h> |
---|
| 33 | #include <rtems/score/states.h> |
---|
| 34 | #include <rtems/score/thread.h> |
---|
| 35 | #include <rtems/score/threadq.h> |
---|
| 36 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 37 | #include <rtems/score/mpci.h> |
---|
| 38 | #endif |
---|
| 39 | #include <rtems/score/sysstate.h> |
---|
| 40 | |
---|
| 41 | #include <rtems/score/interr.h> |
---|
| 42 | |
---|
| 43 | /*PAGE |
---|
| 44 | * |
---|
| 45 | * rtems_semaphore_flush |
---|
| 46 | * |
---|
| 47 | * This directive allows a thread to flush the threads |
---|
| 48 | * pending on the semaphore. |
---|
| 49 | * |
---|
| 50 | * Input parameters: |
---|
| 51 | * id - semaphore id |
---|
| 52 | * |
---|
| 53 | * Output parameters: |
---|
| 54 | * RTEMS_SUCCESSFUL - if successful |
---|
[e980b219] | 55 | * error code - if unsuccessful |
---|
[e7264f07] | 56 | */ |
---|
| 57 | |
---|
[72719d2] | 58 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 59 | #define SEND_OBJECT_WAS_DELETED _Semaphore_MP_Send_object_was_deleted |
---|
| 60 | #else |
---|
| 61 | #define SEND_OBJECT_WAS_DELETED NULL |
---|
| 62 | #endif |
---|
| 63 | |
---|
[e7264f07] | 64 | rtems_status_code rtems_semaphore_flush( |
---|
| 65 | Objects_Id id |
---|
| 66 | ) |
---|
| 67 | { |
---|
| 68 | register Semaphore_Control *the_semaphore; |
---|
| 69 | Objects_Locations location; |
---|
| 70 | |
---|
| 71 | the_semaphore = _Semaphore_Get( id, &location ); |
---|
| 72 | switch ( location ) { |
---|
| 73 | |
---|
| 74 | case OBJECTS_REMOTE: |
---|
| 75 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 76 | _Thread_Dispatch(); |
---|
| 77 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
| 78 | #endif |
---|
| 79 | |
---|
| 80 | case OBJECTS_ERROR: |
---|
| 81 | return RTEMS_INVALID_ID; |
---|
| 82 | |
---|
| 83 | case OBJECTS_LOCAL: |
---|
[50f32b11] | 84 | if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) { |
---|
[e7264f07] | 85 | _CORE_mutex_Flush( |
---|
[50f32b11] | 86 | &the_semaphore->Core_control.mutex, |
---|
[72719d2] | 87 | SEND_OBJECT_WAS_DELETED, |
---|
[e7264f07] | 88 | CORE_MUTEX_STATUS_UNSATISFIED_NOWAIT |
---|
| 89 | ); |
---|
| 90 | } else { |
---|
| 91 | _CORE_semaphore_Flush( |
---|
[50f32b11] | 92 | &the_semaphore->Core_control.semaphore, |
---|
[72719d2] | 93 | SEND_OBJECT_WAS_DELETED, |
---|
[e7264f07] | 94 | CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT |
---|
| 95 | ); |
---|
| 96 | } |
---|
[72719d2] | 97 | _Thread_Enable_dispatch(); |
---|
[e7264f07] | 98 | return RTEMS_SUCCESSFUL; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
| 102 | } |
---|