-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
posix: abstract pthread_mutex_t as uint32_t #52087
posix: abstract pthread_mutex_t as uint32_t #52087
Conversation
972d09b
to
c675a04
Compare
Compliance check failure is a false positive (pthread functions return non-negative errno values) |
c675a04
to
8d872af
Compare
|
1c7c060
to
923a81d
Compare
e27b2d8
to
1f1d9df
Compare
Previously, `pthread_mutex_init()` could not actually fail, and destroying mutexes was a no-op, so it was missing in a couple of places. However, with the change of `pthread_mutex_t` to `uint32_t`, and since those are embedded inside of `struct posix_thread` for the time being, the pthread code needs to keep track that it is relinquishes used mutex resources when a thread completes. Signed-off-by: Chris Friedt <[email protected]>
|
||
/* Record the associated posix_mutex in mu and mark as initialized */ | ||
*mu = mark_pthread_mutex_initialized(bit); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also needs to do the same initialization that pthread_mutex_init()
does. Actually, it should probably just be moved here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! (mostly, custom attributes are still applied in pthread_mutex_init()
5d32773
to
dd4195f
Compare
|
Consistent with the change of `pthread_t` from `struct posix_thread` to `uint32_t`, we can now also abstract `pthread_mutex_t` as `uint32_t` and separate `struct posix_mutex` as an implementation detail, hidden from POSIX API consumers. This change deprecates `PTHREAD_MUTEX_DEFINE()` in favour of the (standardized) `PTHREAD_MUTEX_INITIALIZER`. This change introduces `CONFIG_MAX_PTHREAD_MUTEX_COUNT`. Signed-off-by: Chris Friedt <[email protected]>
dd4195f
to
eeccc88
Compare
Add a test to ensure that `pthread_mutex_t` can be used over and over again and that there is no resource leakage with proper usage. Signed-off-by: Chris Friedt <[email protected]>
eeccc88
to
2477815
Compare
|
@stephanosio - will need your superpowers to merge due to the compliance false positives. |
Will this solve this problem? #35986 |
@cfriedt Good to hear that! Looks like POSIX implementation is a kind of blocker for using POSIX and C++ STL. |
@belussi - the C++ STL works already and has very little dependency on POSIX (if any). However, Newlib's (prototypical) c++11 thread support uses pthreads and requires automatic stack allocation. That in itself is not so hard, but it really should be solved at the kernel (Zephyr) layer so that other threading implementations can simply re-use the same machinery. That will eventually will be fixed by #44379. Later, we can move to a direct c++ threading implementation without POSIX. |
If this relates to #35986 could that issue be re-opened? I'm not using any C++ in my project. For now I've just commented out declarations of the conflicting types in _pthreadtypes.h but i'm keen to find a proper workaround, until i guess the newlib headers are introduced as mentioned on the POSIX roadmap (#51211) |
@PatrickM-ZS @cfriedt |
Please open a discussion instead of commenting on old pull requests. |
3 commits
See individual commit messages for details.