* destroy the empty-string _Rep object.
*
* All but the last paragraph is considered pretty conventional
- * for a C++ string implementation.
+ * for a Copy-On-Write C++ string implementation.
*/
// 21.3 Template class basic_string
template<typename _CharT, typename _Traits, typename _Alloc>
// so we need to use an atomic load. However, _M_is_leaked
// predicate does not change concurrently (i.e. the string is either
// leaked or not), so a relaxed load is enough.
- return __atomic_load_n(&this->_M_refcount, __ATOMIC_RELAXED) < 0;
-#else
- return this->_M_refcount < 0;
+ if (!__gnu_cxx::__is_single_threaded())
+ return __atomic_load_n(&this->_M_refcount, __ATOMIC_RELAXED) < 0;
#endif
+ return this->_M_refcount < 0;
}
bool
// but one reference concurrently with this check, so we need this
// load to be acquire to synchronize with release fetch_and_add in
// _M_dispose.
- return __atomic_load_n(&this->_M_refcount, __ATOMIC_ACQUIRE) > 0;
-#else
- return this->_M_refcount > 0;
+ if (!__gnu_cxx::__is_single_threaded())
+ return __atomic_load_n(&this->_M_refcount, __ATOMIC_ACQUIRE) > 0;
#endif
+ return this->_M_refcount > 0;
}
void
#else
// Rather than allocate an empty string for the rvalue string,
// just share ownership with it by incrementing the reference count.
- // If the rvalue string was "leaked" then it was the unique owner,
- // so need an extra increment to indicate shared ownership.
- if (_M_rep()->_M_is_leaked())
- __gnu_cxx::__atomic_add_dispatch(&_M_rep()->_M_refcount, 2);
- else
+ // If the rvalue string was the unique owner then there are exactly
+ // two owners now.
+ if (_M_rep()->_M_is_shared())
__gnu_cxx::__atomic_add_dispatch(&_M_rep()->_M_refcount, 1);
+ else
+ _M_rep()->_M_refcount = 1;
#endif
}