Closed bremoran closed 8 years ago
cc @bogdanm @rgrover @0xc0170
Move templates into detail header
I noticed this is the first PR adding detail into our modules, is it intended as detail/internal as in boost/STL ? Looking what is there for atomic ops, looks more like it's implementation (function template definitions + some regular function declarations). If there's this detail, there should there be a namespace detail ?
I considered a detail namespace, but it didn't seem to make sense in this instance, since the detail files provide overloads for APIs that are already in the mbed::util
namespace. If they were moved to a mbed::util::detail
namespace, they would simply be imported back into mbed::util
. Because of that, I didn't think it was worth adding the namespace.
The goal of adding the detail folder is to reduce the complexity of the API definitions.
Thanks for separating those two problems.
LGTM
Offtopic as this PR was rebased, but I believe we shall do improvements around how to structure our code (namespaces like detail for instance), we can discuss this outside of this PR. We might have be better off with _impl in the case it was here here provided (template definitions). atomic_ops.hpp (declarations), atomic_ops_impl.hpp (template definitions).
I have changed from overloads to template specializations because of the interaction with atomic_incr. It seems that a template instantiation will choose another template instantiation in preference to an overload. I have checked with GCC and it appears that this version generates the correct code.
Note: build was manually retriggered successfully.
Can you please check if the correct code is also generated with armcc?
@bogdanm The code generated by both armcc and gcc appears to be correct. Functions that should invoke atomic_incr<uint32_t>
contain calls to the specialized version of atomic_cas<uint32_t>
which uses ldrex
and strex
. Due to template inlining, there is no atomic_incr
in the output.
Awesome! +1
Change specializations to overloads for atomic_cas
Fixes #55