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:
fangpeina
2025-06-17 12:09:32 +08:00
committed by Donny(董九柱)
parent e44690e22a
commit e4d4f7e2c3
2 changed files with 9 additions and 3 deletions
+7 -3
View File
@@ -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);
} }
+2
View File
@@ -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;
}; };
/**************************************************************************** /****************************************************************************