-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Make vm_interrupt and timed_out atomic #8327
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
Conversation
I'm trying with compiler intrinsics now. I suspect I may need to determine if I need to link with |
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.
Thank you! The Windows part looks good to me.
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.
As I've told you many times before, please only use static inline
in php-src, not inline
or extern inline
. I'm not having this discussion again.
@nikic I think given the past discussions, you may have misunderstood the point of
A quick grep (which means it may miss some cases with strange formatting, macros, or multiline definitions) show that within the engine today, this is novel: nothing is marked I tested on a modified __attribute__((visibility("default")))
static inline int four(void) {
return 4;
}
extern inline int four(void); // does nothing in this case
__attribute__((visibility("default")))
inline int five(void) {
return 5;
}
extern inline int five(void); // without this, five won't have external linkage either
int main() { return four() == 4 && five() == 5 ? 0 : 1; } I built with
So, that's why I used non-static inline + extern inline. When discussing this a bit with bwoebi, he suggested I could alternatively have |
f773fcf
to
16dd40a
Compare
This is done by adding a new zend_atomic_bool type. The type definition is only available for compiler alignment and size info; it should be treated as opaque and only the zend_atomic_bool_* family of functions should be used. Note that directly using atomic_bool is complicated. All C++ compilers stdlibs that I checked typedef atomic_bool to std::atomic<bool>, which can't be used in an extern "C" section, and there's at least one usage of this in core, and probably more outside of it. So, instead use platform specific functions, preferring compiler intrinsics.
I think the code is worse for doing this, but it was requested during code review and I don't care to die on this hill.
16dd40a
to
e752c79
Compare
I've made the change to remove |
Needs @nikic to review and unblock |
twose pointed out that zend_portability.h already defines the __has_feature no-op.
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
For whatever reason Nikita hasn't responded to messages here or in other places. I removed the extern inline that he complained about, so I'm going ahead with the merge. |
A feature I was developing just needed to use atomic, so I re-read this PR today, I found that there are still some things that can be improved, so I opened #8764. And, to be honest, I do not like such a design that both have ZEND_API and inline functions.
IMO, providing atomic APIs is not Zend's job, if you want to support set There are so many macros and inline functions in Zend that you can't require everything to be API... Please correct me if I am wrong :) |
[deleted wrong comment] |
On Windows these are already set from another thread and should be
atomic. Only one of these was previously atomic using
InterlockedExchange8. On Linux, it's unclear if to me if it should be
atomic based on existing code.
However, extensions which use vm interrupts are very likely to do the
same thing that Windows is doing: set a vm_interrupt from another
thread.
This adds a new zend_atomic_bool type. The type definition is only
available for compiler alignment and size info; it should be treated as
opaque and only the zend_atomic_bool_* family of functions should be
used. Extensions inspecting
EG(vm_interrupt)
andEG(timed_out)
needto be updated.
Note that directly using atomic_bool is complicated. All C++ stdlibs
that I checked typedef atomic_bool to std::atomic, which can't
be used in an extern "C" section, and there's at least one usage of
this in core, and probably more outside of it.
So, instead use platform specific functions, preferring compiler
intrinsics.