-
-
Notifications
You must be signed in to change notification settings - Fork 184
fix: provide non-static recursive mutex initializer #1113
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
fix: provide non-static recursive mutex initializer #1113
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1113 +/- ##
==========================================
- Coverage 82.85% 82.85% -0.01%
==========================================
Files 53 53
Lines 7991 8002 +11
Branches 1252 1252
==========================================
+ Hits 6621 6630 +9
Misses 1255 1255
- Partials 115 117 +2 🚀 New features to boost your workflow:
|
Hi @rubiefawn, can you try this branch and check whether it fixes the mutex initialization issue you see on FreeBSD? |
Sorry for the late response, I don't have FreeBSD installed on bare metal anymore and kept forgetting to create a VM for this. This looks like a step in the right direction, but it still doesn't build on FreeBSD. |
That is excellent feedback. I only quickly prepared something for the general mutex usage but did not consider that the static initializer might be used directly. That means we must introduce a |
0edcbab
to
39b3038
Compare
@rubiefawn, can you give the latest changes a try? Thx! |
Partial build on FreeBSD 15-CURRENT -- going down some compile error rabbit holes for inspection & switching to 14-STABLE in a bit to be more relevant. |
I don't understand what you mean by your comment. But just to be clear: this PR is not meant to be a FreeBSD support PR. We currently do not have the resources to achieve support, and it is also not a short to mid-term goal. However, we are happy to receive PRs that allow the Native SDK to run on FreeBSD. This would entail more changes (see below) than allowing recursive mutexes on platforms without respective static initializers. However, this is an issue on more platforms than only FreeBSD and, as such, would be a valuable addition in isolation. I only used the FreeBSD Also, if you no longer have time to work on this topic, it is OK to close it. In case you want to attempt basic FreeBSD support:
So, as you can see, there is a considerable effort beyond pthread static initializers, even if most of the other UNIX-related code works OOTB. |
Indeed, in order to test this on FreeBSD so far I have locally (and hackily) done the first few bullet points. Full FreeBSD support is out of scope and I'm not expecting the SDK to fully build on that platform even after this PR is merged. |
…nvert the #ifdef and also ensure SENTRY__MUTEX_INIT isn't defined for FreeBSD
b849925
to
48b93ad
Compare
@@ -262,14 +264,36 @@ typedef pthread_cond_t sentry_cond_t; | |||
PTHREAD_MUTEX_RECURSIVE \ | |||
} \ | |||
} | |||
# elif defined(__FreeBSD__) || defined(SENTRY_PLATFORM_NX) |
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.
Sorry, I got sick and haven't been able to look at this much.
Could we avoid gating this based on hardcoded platform checks if possible? Platform checks can set defaults, but it would be great if SENTRY__MUTEX_INIT_DYN
could also be set based on a define that the build system can control and with an opt-in mechanism. i.e., instead of "if hardcoded platform check then define it", something like this instead:
#if defined(__FreeBSD__) || defined(SENTRY_PLATFORM_NX) || SOME OTHER PLATFORM
#define NEEDS_SENTRY_MUTEX_DYN
#endif
#if defined(NEEDS_SENTRY_MUTEX_DYN) && !defined(SENTRY__MUTEX_INIT_DYN)
#define SENTRY__MUTEX_INIT_DYN(...
#endif
This way, any platform can define its own implementation if it needs to, and it can opt-in to the default implementation if it can use it, without having to go and change the header for every new platform that comes along. It is literally not possible to whitelist every platform even if you want to (some platforms have proprietary codenames that you can't make public, and those codenames usually include defines that let you detect them, so there is no way to legally publish that code), so ideally platform detection only sets defaults and generic flags, and the macro implementations are gated on those flags instead of the platforms themselves.
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.
Thanks for the feedback, @shana. We addressed these points in our recent Discord chat. Let's go ahead and continue the discussion there to reduce redundant points to a minimum.
In short, nothing is set in stone. If we need to open implementation details to anyone rather than binding them to a specific platform, we can do that, but it shouldn't be the default and we can make these decisions on a case-by-case basis.
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.
LGTM. Seems to do the job on NX: #1165
…izer
Potentially fixes #1090 by providing another mutex initializer that manually constructs a recursive mutex instead of relying on a static initialization formula (which either the
pthread
library or we provide).