mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 20:08:15 +08:00
drivers/math: use small lock to replace enter_critical_section
replace critical_section with spinlock Signed-off-by: fangpeina <fangpeina@xiaomi.com>
This commit is contained in:
+7
-3
@@ -117,13 +117,12 @@ static int math_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
|||||||
FAR struct inode *inode = filep->f_inode;
|
FAR struct inode *inode = filep->f_inode;
|
||||||
FAR math_upperhalf_s *upper = inode->i_private;
|
FAR math_upperhalf_s *upper = inode->i_private;
|
||||||
int ret = -ENOTTY;
|
int ret = -ENOTTY;
|
||||||
irqstate_t flags;
|
|
||||||
|
|
||||||
DEBUGASSERT(upper != NULL);
|
DEBUGASSERT(upper != NULL);
|
||||||
|
|
||||||
_info("cmd: %d arg: %lu\n", cmd, arg);
|
_info("cmd: %d arg: %lu\n", cmd, arg);
|
||||||
|
|
||||||
flags = enter_critical_section();
|
nxmutex_lock(&upper->lock);
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
@@ -175,7 +174,7 @@ static int math_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
leave_critical_section(flags);
|
nxmutex_unlock(&upper->lock);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -215,12 +214,17 @@ int math_register(FAR const char *path,
|
|||||||
|
|
||||||
memcpy(upper, config, sizeof(math_upperhalf_s));
|
memcpy(upper, config, sizeof(math_upperhalf_s));
|
||||||
|
|
||||||
|
/* Initialize the mutex lock */
|
||||||
|
|
||||||
|
nxmutex_init(&upper->lock);
|
||||||
|
|
||||||
/* Register the math timer device */
|
/* Register the math timer device */
|
||||||
|
|
||||||
ret = register_driver(path, &g_math_ops, 0666, upper);
|
ret = register_driver(path, &g_math_ops, 0666, upper);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
_err("register math driver failed: %d\n", ret);
|
_err("register math driver failed: %d\n", ret);
|
||||||
|
nxmutex_destroy(&upper->lock);
|
||||||
kmm_free(upper);
|
kmm_free(upper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
* Included Files
|
* Included Files
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/mutex.h>
|
||||||
#ifdef CONFIG_MATH_CORDIC
|
#ifdef CONFIG_MATH_CORDIC
|
||||||
#include <nuttx/math/cordic.h>
|
#include <nuttx/math/cordic.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -57,6 +58,7 @@ struct math_config_s
|
|||||||
#ifdef CONFIG_MATH_MPI
|
#ifdef CONFIG_MATH_MPI
|
||||||
FAR struct mpi_lowerhalf_s *mpi;
|
FAR struct mpi_lowerhalf_s *mpi;
|
||||||
#endif
|
#endif
|
||||||
|
mutex_t lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user