drivers/mtd/mtd_config: switch from semaphore to mutex for exclusive access
#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>
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 */
@@ -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);
