[GSoC] Patches for shared_ptr array and polymorphic_allocator
Jonathan Wakely
jwakely@redhat.com
Mon Jul 20 09:50:00 GMT 2015
On 18/07/15 23:29 -0700, Tim Shen wrote:
>On Sat, Jul 18, 2015 at 3:01 PM, Fan You <youfan.noey@gmail.com> wrote:
>> However [8.8.6] said, If r is non-null, sets the value of the default memory
>> resource pointer to r, otherwise sets the default memory resource pointer to
>> new_delete_resource().
>
>Ah right, so the only place we should care about is set_default_resource:
>void
>set_default_resource(memory_resource __r)
>{
> std::atomic<memory_resource> __new_ptr = __r ? __r : new_delete_resource();
> return __new_ptr.exchange(memory_resource::_S_default_resource);
>}
This won't compile, because std::atomic<T>::exchange takes T not a
std::atomic<T>.
We don't need __new_ptr to be atomic, the only thing that needs to be
atomic is the exchange operation on the global, so as I said in my
other reply a minute ago, I think it should be:
inline memory_resource*
set_default_resource(memory_resource* __r) noexcept
{
if ( __r == nullptr)
__r = new_delete_resource();
return memory_resource::_S_default_resource.exchange(__r);
}
More information about the Libstdc++
mailing list