diff --git a/drivers/math/math.c b/drivers/math/math.c index 6371f568e91..ed535b49895 100644 --- a/drivers/math/math.c +++ b/drivers/math/math.c @@ -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 math_upperhalf_s *upper = inode->i_private; int ret = -ENOTTY; - irqstate_t flags; DEBUGASSERT(upper != NULL); _info("cmd: %d arg: %lu\n", cmd, arg); - flags = enter_critical_section(); + nxmutex_lock(&upper->lock); switch (cmd) { @@ -175,7 +174,7 @@ static int math_ioctl(FAR struct file *filep, int cmd, unsigned long arg) #endif } - leave_critical_section(flags); + nxmutex_unlock(&upper->lock); return ret; } @@ -215,12 +214,17 @@ int math_register(FAR const char *path, memcpy(upper, config, sizeof(math_upperhalf_s)); + /* Initialize the mutex lock */ + + nxmutex_init(&upper->lock); + /* Register the math timer device */ ret = register_driver(path, &g_math_ops, 0666, upper); if (ret < 0) { _err("register math driver failed: %d\n", ret); + nxmutex_destroy(&upper->lock); kmm_free(upper); } diff --git a/include/nuttx/math/math.h b/include/nuttx/math/math.h index bfe0ccd7a7e..3d3beffd7fb 100644 --- a/include/nuttx/math/math.h +++ b/include/nuttx/math/math.h @@ -27,6 +27,7 @@ * Included Files ****************************************************************************/ +#include #ifdef CONFIG_MATH_CORDIC #include #endif @@ -57,6 +58,7 @@ struct math_config_s #ifdef CONFIG_MATH_MPI FAR struct mpi_lowerhalf_s *mpi; #endif + mutex_t lock; }; /****************************************************************************