[rtems commit] libblock: Use self-contained mutex for sparse disk

Sebastian Huber sebh at rtems.org
Thu Feb 8 08:16:55 UTC 2018


Module:    rtems
Branch:    master
Commit:    868ca746c21c9cb0743bec597687b5354230c8ba
Changeset: http://git.rtems.org/rtems/commit/?id=868ca746c21c9cb0743bec597687b5354230c8ba

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Jan  2 16:40:21 2018 +0100

libblock: Use self-contained mutex for sparse disk

Update #2843.

---

 cpukit/include/rtems/sparse-disk.h |  3 ++-
 cpukit/libblock/src/sparse-disk.c  | 32 ++++----------------------------
 2 files changed, 6 insertions(+), 29 deletions(-)

diff --git a/cpukit/include/rtems/sparse-disk.h b/cpukit/include/rtems/sparse-disk.h
index e558e08..7233c75 100644
--- a/cpukit/include/rtems/sparse-disk.h
+++ b/cpukit/include/rtems/sparse-disk.h
@@ -27,6 +27,7 @@
 #include <stdint.h>
 #include <rtems.h>
 #include <rtems/diskdevs.h>
+#include <rtems/thread.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -50,7 +51,7 @@ typedef struct rtems_sparse_disk rtems_sparse_disk;
 typedef void (*rtems_sparse_disk_delete_handler)(rtems_sparse_disk *sparse_disk);
 
 struct rtems_sparse_disk {
-  rtems_id                         mutex;
+  rtems_mutex                      mutex;
   rtems_blkdev_bnum                blocks_with_buffer;
   size_t                           used_count;
   uint32_t                         media_block_size;
diff --git a/cpukit/libblock/src/sparse-disk.c b/cpukit/libblock/src/sparse-disk.c
index 373c2bb..58ff8d3 100644
--- a/cpukit/libblock/src/sparse-disk.c
+++ b/cpukit/libblock/src/sparse-disk.c
@@ -58,7 +58,6 @@ static rtems_status_code sparse_disk_initialize( rtems_sparse_disk *sd,
   const rtems_sparse_disk_delete_handler                            sparse_disk_delete,
   const uint8_t                                                     fill_pattern )
 {
-  rtems_status_code sc;
   rtems_blkdev_bnum i;
 
   if ( NULL == sd )
@@ -78,17 +77,7 @@ static rtems_status_code sparse_disk_initialize( rtems_sparse_disk *sd,
 
   sd->delete_handler = sparse_disk_delete;
 
-  sc                 = rtems_semaphore_create(
-    rtems_build_name( 'S', 'P', 'A', 'R' ),
-    1,
-    RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY,
-    0,
-    &sd->mutex
-    );
-
-  if ( sc != RTEMS_SUCCESSFUL ) {
-    return sc;
-  }
+  rtems_mutex_init( &sd->mutex, "Sparse Disk" );
 
   data                  += sizeof( rtems_sparse_disk );
 
@@ -236,12 +225,8 @@ static int sparse_disk_read_write(
   uint8_t                *buff;
   size_t                  buff_size;
   unsigned int            bytes_handled;
-  rtems_status_code       sc;
 
-  sc = rtems_semaphore_obtain(sparse_disk->mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
-  if (sc != RTEMS_SUCCESSFUL) {
-      rtems_fatal_error_occurred( 0xdeadbeef );
-  }
+  rtems_mutex_lock( &sparse_disk->mutex );
 
   for ( req_buffer = 0;
         ( 0 <= rv ) && ( req_buffer < req->bufnum );
@@ -271,10 +256,7 @@ static int sparse_disk_read_write(
     }
   }
 
-  sc = rtems_semaphore_release( sparse_disk->mutex );
-  if (sc != RTEMS_SUCCESSFUL) {
-      rtems_fatal_error_occurred( 0xdeadbeef );
-  }
+  rtems_mutex_unlock( &sparse_disk->mutex );
 
   if ( 0 > rv )
     rtems_blkdev_request_done( req, RTEMS_IO_ERROR );
@@ -289,7 +271,6 @@ static int sparse_disk_read_write(
  */
 static int sparse_disk_ioctl( rtems_disk_device *dd, uint32_t req, void *argp )
 {
-  rtems_status_code  sc;
   rtems_sparse_disk *sd = rtems_disk_get_driver_data( dd );
 
   if ( RTEMS_BLKIO_REQUEST == req ) {
@@ -303,12 +284,7 @@ static int sparse_disk_ioctl( rtems_disk_device *dd, uint32_t req, void *argp )
         break;
     }
   } else if ( RTEMS_BLKIO_DELETED == req ) {
-    sc = rtems_semaphore_delete( sd->mutex );
-
-    if ( RTEMS_SUCCESSFUL != sc )
-      rtems_fatal_error_occurred( 0xdeadbeef );
-
-    sd->mutex = RTEMS_ID_NONE;
+    rtems_mutex_destroy( &sd->mutex );
 
     if ( NULL != sd->delete_handler )
       ( *sd->delete_handler )( sd );



More information about the vc mailing list