drivers/mtd/mtd_config: switch from semaphore to mutex for exclusive access

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
Petro Karashchenko
2023-01-25 22:58:40 +02:00
committed by Xiang Xiao
parent 6e3cb04531
commit e3a8e1e3ef
+6 -5
View File
@@ -42,6 +42,7 @@
#include <debug.h> #include <debug.h>
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
#include <nuttx/mutex.h>
#include <nuttx/kmalloc.h> #include <nuttx/kmalloc.h>
#include <nuttx/fs/ioctl.h> #include <nuttx/fs/ioctl.h>
#include <nuttx/mtd/mtd.h> #include <nuttx/mtd/mtd.h>
@@ -72,7 +73,7 @@
struct mtdconfig_struct_s struct mtdconfig_struct_s
{ {
FAR struct mtd_dev_s *mtd; /* Contained MTD interface */ 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 blocksize; /* Size of blocks in contained MTD */
uint32_t erasesize; /* Size of erase block in contained MTD */ uint32_t erasesize; /* Size of erase block in contained MTD */
size_t nblocks; /* Number of blocks available */ size_t nblocks; /* Number of blocks available */
@@ -1012,7 +1013,7 @@ static int mtdconfig_open(FAR struct file *filep)
/* Get exclusive access to the device */ /* Get exclusive access to the device */
ret = nxsem_wait(&dev->exclsem); ret = nxmutex_lock(&dev->lock);
if (ret < 0) if (ret < 0)
{ {
ferr("ERROR: nxsem_wait failed: %d\n", ret); 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 */ /* Release exclusive access to the device */
nxsem_post(&dev->exclsem); nxmutex_unlock(&dev->lock);
return OK; return OK;
} }
@@ -1774,7 +1775,7 @@ int mtdconfig_register(FAR struct mtd_dev_s *mtd)
goto errout; goto errout;
} }
nxsem_init(&dev->exclsem, 0, 1); nxmutex_init(&dev->lock);
register_driver("/dev/config", &mtdconfig_fops, 0666, dev); register_driver("/dev/config", &mtdconfig_fops, 0666, dev);
} }
@@ -1806,7 +1807,7 @@ int mtdconfig_unregister(void)
inode = file.f_inode; inode = file.f_inode;
dev = (FAR struct mtdconfig_struct_s *)inode->i_private; dev = (FAR struct mtdconfig_struct_s *)inode->i_private;
nxsem_destroy(&dev->exclsem); nxmutex_destroy(&dev->lock);
kmm_free(dev); kmm_free(dev);
file_close(&file); file_close(&file);