[a9fa9b7] | 1 | /* |
---|
| 2 | * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org> |
---|
| 3 | * |
---|
| 4 | * The license and distribution terms for this file may be |
---|
| 5 | * found in the file LICENSE in this distribution or at |
---|
| 6 | * http://www.rtems.com/license/LICENSE. |
---|
| 7 | * |
---|
| 8 | * $Id$ |
---|
| 9 | */ |
---|
| 10 | /** |
---|
| 11 | * @file |
---|
| 12 | * |
---|
| 13 | * @ingroup rtems-rfs |
---|
| 14 | * |
---|
| 15 | * RTEMS File System Mutex. |
---|
| 16 | */ |
---|
| 17 | |
---|
[355b0544] | 18 | #if HAVE_CONFIG_H |
---|
| 19 | #include "config.h" |
---|
| 20 | #endif |
---|
| 21 | |
---|
[a9fa9b7] | 22 | #include <rtems/rfs/rtems-rfs-mutex.h> |
---|
| 23 | |
---|
| 24 | #if __rtems__ |
---|
| 25 | /** |
---|
| 26 | * RTEMS_RFS Mutex Attributes |
---|
| 27 | * |
---|
| 28 | * @warning Do not configure as inherit priority. If a driver is in the driver |
---|
| 29 | * initialisation table this locked semaphore will have the IDLE task |
---|
| 30 | * as the holder and a blocking task will raise the priority of the |
---|
| 31 | * IDLE task which can cause unsual side effects like not work. |
---|
| 32 | */ |
---|
| 33 | #define RTEMS_RFS_MUTEX_ATTRIBS \ |
---|
| 34 | (RTEMS_PRIORITY | RTEMS_SIMPLE_BINARY_SEMAPHORE | \ |
---|
| 35 | RTEMS_NO_INHERIT_PRIORITY | RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL) |
---|
| 36 | #endif |
---|
| 37 | |
---|
| 38 | int |
---|
| 39 | rtems_rfs_mutex_create (rtems_rfs_mutex* mutex) |
---|
| 40 | { |
---|
| 41 | #if __rtems__ |
---|
| 42 | rtems_status_code sc; |
---|
| 43 | sc = rtems_semaphore_create (rtems_build_name ('R', 'F', 'S', 'm'), |
---|
| 44 | 1, RTEMS_RFS_MUTEX_ATTRIBS, 0, |
---|
| 45 | mutex); |
---|
| 46 | if (sc != RTEMS_SUCCESSFUL) |
---|
| 47 | { |
---|
| 48 | if (rtems_rfs_trace (RTEMS_RFS_TRACE_MUTEX)) |
---|
[66b8047] | 49 | printf ("rtems-rfs: mutex: open failed: %s\n", |
---|
[a9fa9b7] | 50 | rtems_status_text (sc)); |
---|
| 51 | return EIO; |
---|
| 52 | } |
---|
| 53 | #endif |
---|
| 54 | return 0; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | int |
---|
| 58 | rtems_rfs_mutex_destroy (rtems_rfs_mutex* mutex) |
---|
| 59 | { |
---|
| 60 | #if __rtems__ |
---|
| 61 | rtems_status_code sc; |
---|
| 62 | sc = rtems_semaphore_delete (*mutex); |
---|
| 63 | if (sc != RTEMS_SUCCESSFUL) |
---|
| 64 | { |
---|
| 65 | if (rtems_rfs_trace (RTEMS_RFS_TRACE_MUTEX)) |
---|
[66b8047] | 66 | printf ("rtems-rfs: mutex: close failed: %s\n", |
---|
[a9fa9b7] | 67 | rtems_status_text (sc)); |
---|
| 68 | return EIO; |
---|
| 69 | } |
---|
| 70 | #endif |
---|
| 71 | return 0; |
---|
| 72 | } |
---|