-
Notifications
You must be signed in to change notification settings - Fork 92
mem: Make nrefs atomic #446
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 can add C99 (mutex) and WIN32 fallbacks for |
I'm going to expand |
00636d2
to
a167c3c
Compare
I think full compiler intrinsics fallback is not needed (since we want to drop C99 maybe shortly, we should keep this simple) and add only needed fallbacks. ffmpeg replaces this with pthread mutex. For fast and full atomic support a C11 ready compiler should be used. |
I don't think MSVC implements C11. And C99 is still required. Also, I do not like using a mutex to implement atomics, this is way too much overhead. |
Ok but I think we can drop the And I would prefer to keep the naming clean like: |
f364630
to
1762db8
Compare
Ok.
I have made the macros size-agnostic, although it complicated things for MSVC quite a bit. Hopefully, it should be able to optimize away all that cruft. |
1762db8
to
0a639fb
Compare
8fdf1ee
to
2e49aff
Compare
< 8000 div data-view-component="true">
This new abstraction layer defines a set of macros that resemble C11 atomics interface and are implemented in terms of C11 atomics or compiler intrinsics, depending on the compiler. Besides C11 atomics, gcc __atomic, and MSVC Interlocked intrinsics are supported. MSVC implementation has a caveat that it has to convert its arguments and returned values to the largest supported integer size, unsigned __int64. This may cause warnings in the calling code where this results in implicit conversions. These warnings can be worked around with explicit casts.
This allows to use mem API for shared memory objects from multiple threads.
This ensures that the atomic variables are actually used as atomics on compilers that don't support C11 _Atomic keyword. Also, this changes the memory ordering to relaxed on all accesses, as no memory ordering is necessary in all cases.
2e49aff
to
1df080c
Compare
Great work, thanks! |
I am afraid, but we need C99 support up to the next 3-5 Years. So we need an abstraction for C99. I would prefer in mainline. Maybe we could separate it to an extra header file if this helps. So far I have no idea how this could be implemented. Maybe with pthread mutexes? |
Have you build issues? We have already |
Yes, indeed for our old product we get:
We have |
Yes lets do that. |
This allows to use mem API for shared memory objects from multiple threads.