ARMmbed / core-util

DEPRECATED: Mbed 3 utilities library
Other
12 stars 17 forks source link

Template specializations of atomic_cas are not instantiated #55

Closed bremoran closed 8 years ago

bremoran commented 8 years ago

Template specializations of atomic_cas are not instantiated because they live in a cpp file and are not available to the compiler for elaboration during function template name lookup. The specializations of atomic_cas should live in either atomic_ops.h or a header included by atomic_ops.h

rgrover commented 8 years ago

one way to instantiate them would be add declarations for the specializations in atomic_ops.h:

/* For ARMv7-M and above, we use the load/store-exclusive instructions to
 * implement atomic_cas, so we provide three specialization corresponding to the
 * byte, half-word, and word variants of the instructions. As long as the following
 * declarations are available, the compiler will find the proper call targets. */
#if (__CORTEX_M >= 0x03)
template <> bool atomic_cas<uint8_t> (uint8_t  *ptr, uint8_t  *expectedCurrentValue, uint8_t  desiredValue);
template <> bool atomic_cas<uint16_t>(uint16_t *ptr, uint16_t *expectedCurrentValue, uint16_t desiredValue);
template <> bool atomic_cas<uint32_t>(uint32_t *ptr, uint32_t *expectedCurrentValue, uint32_t desiredValue);
#endif /* #if (__CORTEX_M >= 0x03) */
ciarmcom commented 8 years ago

ARM Internal Ref: IOTSFW-1824

bremoran commented 8 years ago

Since overloads are adequate and templates are not required for the specialized versions of atomic_cas I would prefer the overload version.

bremoran commented 8 years ago

I was incorrect: Using overloads instead of template specializations causes atomic_incr to select the wrong version of atomic_cas.