nuttx/mutex: do not use non-nx interface in kernel except libs
Summary
The https://github.com/apache/incubator-nuttx/pull/6320 redirected nxmutex used in kernel to sem_ API family in case of CONFIG_BUILD_FLAT. That is not correct. This PR is created just for discussion and just highlight the issue.
Impact
Testing
@xiaoxiang781216 could you please take a look. I noticed during my work that mutexes use sem_ API inside the kernel in case of FLAT build. Seems that we missed that point during the review of https://github.com/apache/incubator-nuttx/pull/6320 by trying to overcome the libc build error and switching from nxsem_ to _SEM_. This introduced a side effect in case of FLAT build.
One of the possible ways may be to get back original code for the files that I've listed in this PR and switching nxmutex_ APIs to use nxsem_ APIs only.
One of the possible ways may be to get back original code for the files that I've listed in this PR and switching
nxmutex_APIs to usenxsem_APIs only.
How about we follow sem_t approach:
- include/mutex.h which call sem_xxx and set errno
- include/nuttx/mutex.h which call nxsem_xxx but not set errno
- add MUTEX_XXXX macro in include/nuttx/mutex.h which call first or second version by check
__KERNEL__
Yes. This can work. Similar approach like _SEM_XXX
One of the possible ways may be to get back original code for the files that I've listed in this PR and switching
nxmutex_APIs to usenxsem_APIs only.How about we follow sem_t approach:
* include/mutex.h which call sem_xxx and set errno * include/nuttx/mutex.h which call nxsem_xxx but not set errno * add MUTEX_XXXX macro in include/nuttx/mutex.h which call first or second version by check `__KERNEL__`
Done, but IMO we should merge mutex_t and rmutex_t (as well as APIs) and just add bool recursive; flag to mutex_t and just keep one set of APIs
@xiaoxiang781216 seems that mutex_ notation conflicts with 3P component naming. Since mutex_ is not a POSIX APIs I'm not sure what is the best way to solve the naming conflict. mtx_ prefix is already occupied (include/threads.h). What do you think, how we can resolve the naming conflict?
The issue of naming conflict comes from: #include <stdio.h> -> #include <nuttx/fs/fs.h> -> #include <nuttx/mutex.h> because struct file_struct has member rmutex_t fs_lock;
@xiaoxiang781216 ping
The issue of naming conflict comes from:
#include <stdio.h>->#include <nuttx/fs/fs.h>->#include <nuttx/mutex.h>becausestruct file_structhas memberrmutex_t fs_lock;
It's hard to fix:(
@pkarashchenko Hi, pkarashchenko, is this PR still being modified?
I will review and most probably close this PR as it is outdated
@pkarashchenko, i have a similar modify, please help to review. #8645