fs: mqueue: Fix file_mq_open() for SMP
Summary:
I noticed that sometimes mqueue_test in ostest failed
(i.e. mq_open failed) with rv-virt:smp.
This commit fixes this issue by replacing sched_lock with
critical section.
Impact:
file_mq_open()
Testing:
Tested with ostest on QEMU-7.1
@@ -162,6 +162,7 @@ static int file_mq_vopen(FAR struct file *mq, FAR const char *mq_name,
FAR struct mq_attr *attr = NULL;
struct inode_search_s desc;
char fullpath[MAX_MQUEUE_PATH];
+ irqstate_t flags;
mode_t mode = 0;
int ret;
@@ -210,11 +211,12 @@ static int file_mq_vopen(FAR struct file *mq, FAR const char *mq_name,
/* Make sure that the check for the existence of the message queue
* and the creation of the message queue are atomic with respect to
- * other processes executing mq_open(). A simple sched_lock() should
- * be sufficient.
+ * other processes executing mq_open(). A simple sched_lock() would
+ * be sufficient for non-SMP case but critical section is needed for
+ * SMP case.
*/
- sched_lock();
+ flags = enter_critical_section();
/* Get the inode for this mqueue. This should succeed if the message
* queue has already been created. In this case, inode_find() will
@@ -322,7 +324,7 @@ static int file_mq_vopen(FAR struct file *mq, FAR const char *mq_name,
}
RELEASE_SEARCH(&desc);
- sched_unlock();
+ leave_critical_section(flags);
return OK;
errout_with_inode:
@@ -330,7 +332,7 @@ errout_with_inode:
errout_with_lock:
RELEASE_SEARCH(&desc);
- sched_unlock();
+ leave_critical_section(flags);
errout:
return ret;
