You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/01/26 02:24:14 UTC

[nuttx] 03/05: drivers/mtd/mtd_config: switch from semaphore to mutex for exclusive access

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit e3a8e1e3ef3a0da5747706efc8679a47477ae87e
Author: Petro Karashchenko <pe...@gmail.com>
AuthorDate: Wed Jan 25 22:58:40 2023 +0200

    drivers/mtd/mtd_config: switch from semaphore to mutex for exclusive access
    
    Signed-off-by: Petro Karashchenko <pe...@gmail.com>
---
 drivers/mtd/mtd_config.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/mtd_config.c b/drivers/mtd/mtd_config.c
index 0da348c2fe..ac1bfde49f 100644
--- a/drivers/mtd/mtd_config.c
+++ b/drivers/mtd/mtd_config.c
@@ -42,6 +42,7 @@
 #include <debug.h>
 #include <nuttx/fs/fs.h>
 
+#include <nuttx/mutex.h>
 #include <nuttx/kmalloc.h>
 #include <nuttx/fs/ioctl.h>
 #include <nuttx/mtd/mtd.h>
@@ -72,7 +73,7 @@
 struct mtdconfig_struct_s
 {
   FAR struct mtd_dev_s *mtd;  /* Contained MTD interface */
-  sem_t        exclsem;       /* Supports mutual exclusion */
+  mutex_t      lock;          /* Supports mutual exclusion */
   uint32_t     blocksize;     /* Size of blocks in contained MTD */
   uint32_t     erasesize;     /* Size of erase block  in contained MTD */
   size_t       nblocks;       /* Number of blocks available */
@@ -1004,7 +1005,7 @@ errout:
  * Name: mtdconfig_open
  ****************************************************************************/
 
-static int  mtdconfig_open(FAR struct file *filep)
+static int mtdconfig_open(FAR struct file *filep)
 {
   FAR struct inode *inode = filep->f_inode;
   FAR struct mtdconfig_struct_s *dev = inode->i_private;
@@ -1012,7 +1013,7 @@ static int  mtdconfig_open(FAR struct file *filep)
 
   /* Get exclusive access to the device */
 
-  ret = nxsem_wait(&dev->exclsem);
+  ret = nxmutex_lock(&dev->lock);
   if (ret < 0)
     {
       ferr("ERROR: nxsem_wait failed: %d\n", ret);
@@ -1036,7 +1037,7 @@ static int  mtdconfig_close(FAR struct file *filep)
 
   /* Release exclusive access to the device */
 
-  nxsem_post(&dev->exclsem);
+  nxmutex_unlock(&dev->lock);
   return OK;
 }
 
@@ -1774,7 +1775,7 @@ int mtdconfig_register(FAR struct mtd_dev_s *mtd)
           goto errout;
         }
 
-      nxsem_init(&dev->exclsem, 0, 1);
+      nxmutex_init(&dev->lock);
       register_driver("/dev/config", &mtdconfig_fops, 0666, dev);
     }
 
@@ -1806,7 +1807,7 @@ int mtdconfig_unregister(void)
 
   inode = file.f_inode;
   dev = (FAR struct mtdconfig_struct_s *)inode->i_private;
-  nxsem_destroy(&dev->exclsem);
+  nxmutex_destroy(&dev->lock);
   kmm_free(dev);
 
   file_close(&file);