nuttx icon indicating copy to clipboard operation
nuttx copied to clipboard

nuttx/mutex: do not use non-nx interface in kernel except libs

Open pkarashchenko opened this issue 3 years ago • 9 comments

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

pkarashchenko avatar Jun 06 '22 21:06 pkarashchenko

@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.

pkarashchenko avatar Jun 06 '22 21:06 pkarashchenko

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.

pkarashchenko avatar Jun 06 '22 21:06 pkarashchenko

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.

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__

xiaoxiang781216 avatar Jun 07 '22 05:06 xiaoxiang781216

Yes. This can work. Similar approach like _SEM_XXX

pkarashchenko avatar Jun 07 '22 05:06 pkarashchenko

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.

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

pkarashchenko avatar Jun 07 '22 09:06 pkarashchenko

@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?

pkarashchenko avatar Jun 08 '22 07:06 pkarashchenko

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;

pkarashchenko avatar Jun 08 '22 07:06 pkarashchenko

@xiaoxiang781216 ping

pkarashchenko avatar Jun 09 '22 06:06 pkarashchenko

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;

It's hard to fix:(

xiaoxiang781216 avatar Jun 09 '22 09:06 xiaoxiang781216

@pkarashchenko Hi, pkarashchenko, is this PR still being modified?

zyfeier avatar Feb 22 '23 02:02 zyfeier

I will review and most probably close this PR as it is outdated

pkarashchenko avatar Feb 22 '23 05:02 pkarashchenko

@pkarashchenko, i have a similar modify, please help to review. #8645

zyfeier avatar Feb 24 '23 10:02 zyfeier