summaryrefslogtreecommitdiffstats
path: root/libcxx/src/memory.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Enable building and using atomic shared_ptr for GCC.Eric Fiselier2016-06-181-2/+2
| | | | | | | | | | | | | | | | | Summary: Currently the implementation of [util.smartptr.shared.atomic] is provided only when using Clang, and not with GCC. This is a relic of not having a GCC implementation of <atomic>, even though <atomic> isn't actually used in the implementation. This patch enables support for atomic shared_ptr functions when using GCC. Note that this is not a header only change. Previously only Clang builds of libc++.so would provide the required symbols. There is no reason for this restriction. After this change both Clang and GCC builds should be binary compatible with each other WRT these symbols. Reviewers: mclow.lists, rmaprath, EricWF Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D21407 llvm-svn: 273076
* Refactor pthread usage of libcxx.Asiri Rathnayake2016-05-061-5/+5
| | | | | | | | | | | | | This patch extracts out all the pthread dependencies of libcxx into the new header __threading_support. The motivation is to make it easy to re-target libcxx into platforms that do not support pthread. Original patch from Fulvio Esposito (fulvio.esposito@outlook.com) - D11781 Applied with tweaks - D19412 Change-Id: I301111f0075de93dd8129416e06babc195aa936b llvm-svn: 268734
* [libcxx] Allow use of <atomic> in C++03. Try 3.Eric Fiselier2015-08-191-2/+2
| | | | | | | | | | | | | | | | | | | | | | | Summary: After putting this question up on cfe-dev I have decided that it would be best to allow the use of `<atomic>` in C++03. Although static initialization is a concern the syntax required to get it is C++11 only. Meaning that C++11 constant static initialization cannot silently break in C++03, it will always cause a syntax error. Furthermore `ATOMIC_VAR_INIT` and `ATOMIC_FLAG_INIT` remain defined in C++03 even though they cannot be used because C++03 usages will cause better error messages. The main change in this patch is to replace `__has_feature(cxx_atomic)`, which only returns true when C++ >= 11, to `__has_extension(c_atomic)` which returns true whenever clang supports the required atomic builtins. This patch adds the following macros: * `_LIBCPP_HAS_C_ATOMIC_IMP` - Defined on clang versions which provide the C `_Atomic` keyword. * `_LIBCPP_HAS_GCC_ATOMIC_IMP` - Defined on GCC > 4.7. We must use the fallback atomic implementation. * `_LIBCPP_HAS_NO_ATOMIC_HEADER` - Defined when it is not safe to include `<atomic>`. `_LIBCPP_HAS_C_ATOMIC_IMP` and `_LIBCPP_HAS_GCC_ATOMIC_IMP` are mutually exclusive, only one should be defined. If neither is defined then `<atomic>` is not implemented and including `<atomic>` will issue an error. Reviewers: chandlerc, jroelofs, mclow.lists Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D11555 llvm-svn: 245463
* Move atomic_support.h and config_elast.h into src/includeEric Fiselier2015-08-181-1/+1
| | | | llvm-svn: 245354
* [libcxx] Add atomic_support.h header to src that handles needed atomic ↵Eric Fiselier2015-07-071-7/+10
| | | | | | | | | | | | | | | | | | | | | operations. Summary: In some places in libc++ we need to use the `__atomic_*` builtins. This patch adds a header that provides access to those builtins in a uniform way from within the dylib source. If the compiler building the dylib does not support these builtins then a warning is issued. Only relaxed loads are needed within the headers. A singe function to do these relaxed loads has been added to `<memory>`. This patch applies the new atomic builtins to `__shared_count` and `call_once`. Reviewers: mclow.lists Subscribers: majnemer, jroelofs, cfe-commits Differential Revision: http://reviews.llvm.org/D10406 llvm-svn: 241532
* Fix building and running tests when LIBCXX_ENABLE_EXCEPTIONS or ↵Eric Fiselier2014-12-121-1/+1
| | | | | | LIBCXX_ENABLE_RTTI are turned off. llvm-svn: 224095
* Address some post-commit review comments on r217261Jonathan Roelofs2014-09-051-1/+1
| | | | llvm-svn: 217276
* Allow libc++ to be built on systems without POSIX threadsJonathan Roelofs2014-09-051-2/+4
| | | | | | | | | | If you're crazy enough to want this sort of thing, then add -D_LIBCPP_HAS_NO_THREADS to your CXXFLAGS and --param=additiona_features=libcpp-has-no-threads to your lit commnad line. http://reviews.llvm.org/D3969 llvm-svn: 217271
* Switch to using C++ style casts.Joerg Sonnenberger2014-01-041-1/+1
| | | | llvm-svn: 198505
* This should be nothing but a load-time optimization. I'm trying to reduce ↵Howard Hinnant2013-03-161-1/+9
| | | | | | load time initializers and this is a big one. No visible functionality change intended. llvm-svn: 177212
* Rename uses of _ and __ because these are getting stepped on by macros from ↵Howard Hinnant2012-10-301-3/+3
| | | | | | other system code. llvm-svn: 167038
* Patch contributed by Dev Dude for mingw64 port.Howard Hinnant2012-08-191-0/+3
| | | | llvm-svn: 162188
* Despite my pathological distrust of spin locks, the number just don't lie. ↵Howard Hinnant2012-07-301-2/+13
| | | | | | I've put a small spin in __sp_mut::lock() on std::mutex::try_lock(), which is testing quite well. In my experience, putting in a yield for every failed iteration is also a major performance booster. This change makes one of the performance tests I was using (a highly contended one) run about 20 times faster. llvm-svn: 160967
* Implement [util.smartptr.shared.atomic]. This is the last unimplementedHoward Hinnant2012-07-301-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | section in libc++. This requires a recompiled dylib. Failure to rebuild the dylib will result in a link-time error if and only if the functions from [util.smartptr.shared.atomic] are used. The implementation is not lock free. After considerable thought, I know of no way to make the implementation lock free. Ideas welcome along that front. But changing the ABI of shared_ptr is not on the table at this point. The mutex used to lock these function is encapsulated by std::__sp_mut. The only thing the client knows about std::__sp_mut is that it has a void* data member, can't be constructed, and has lock and unlock members. Within the binary __sp_mut is currently implemented as a pointer to a std::mutex. That can change in the future without disturbing the ABI (as long as sizeof(__sp_mut) remains constant. I specifically did not make __sp_mut a spin lock as I have a pathological distrust of spin locks. Testing on OS X reveals that the use of std::mutex in this role is not a large performance penalty as long as the contention for the mutex is low (more likely to get the lock than to have to wait). In the future we can still make __sp_mut a spin lock if that is what is desired (without ABI damage). The dylib contains 16 __sp_mut's to be chosen based on the hash of the address of the shared_ptr. The constant 16 is a ball-park reasonable space/time tradeoff. std::hash<T*> was changed to call __murmur2_or_cityhash, instead of the identity function. I had thought we had already done this, but I was mistaken. All of this is under #if __has_feature(cxx_atomic) even though the implementation is not lock free, because the signatures require access to std::memory_order, which is currently available only under __has_feature(cxx_atomic). llvm-svn: 160940
* Appy constexpr to <memory>. Picked up a few missing noexcepts as well.Howard Hinnant2012-07-071-0/+1
| | | | llvm-svn: 159902
* Fix memory leak in converting weak_ptr to shared_ptrHoward Hinnant2011-12-271-3/+0
| | | | llvm-svn: 147298
* Quash a whole bunch of warningsHoward Hinnant2011-12-011-1/+1
| | | | llvm-svn: 145624
* noexcept for <memory>. I've added a few extension noexcept to: ↵Howard Hinnant2011-05-281-13/+13
| | | | | | allocator_traits<A>::deallocate, allocaate<T>::deallocate, return_temporary_buffer, and default_delete<T>::operator()(T*) const. My rationale was: If a std-dicated noexcept function needs to call another std-defined function, that called function must be noexcept. We're all a little new to noexcept, so things like this are to be expected. Also included fix for broken __is_swappable trait pointed out by Marc Glisse, thanks Marc|. And fixed a test case for is_nothrow_destructible. Destructors are now noexcept by default| llvm-svn: 132261
* license changeHoward Hinnant2010-11-161-2/+2
| | | | llvm-svn: 119395
* Dave Zarzycki showed how the efficiency of shared_ptr could be significantlyHoward Hinnant2010-11-161-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | increased. The following program is running 49% faster: #include <iostream> #include <memory> #include <chrono> #include <vector> #include "chrono_io" int main() { typedef std::chrono::high_resolution_clock Clock; Clock::time_point t0 = Clock::now(); { std::shared_ptr<int> p(new int (1)); std::vector<std::shared_ptr<int> > v(1000000, p); v.insert(v.begin(), p); v.insert(v.begin(), p); v.insert(v.begin(), p); v.insert(v.begin(), p); } Clock::time_point t1 = Clock::now(); std::cout << (t1-t0) << '\n'; } llvm-svn: 119388
* Fixing whitespace problemsHoward Hinnant2010-08-221-2/+1
| | | | llvm-svn: 111751
* now works with -fno-exceptions and -fno-rttiHoward Hinnant2010-08-111-0/+4
| | | | llvm-svn: 110828
* patch by Jeffrey Yasskin for porting to Ubuntu Hardy. Everything was ↵Howard Hinnant2010-05-241-46/+7
| | | | | | accepted except there were some bug fixes needed in <locale> for the __nolocale_* series. For the apple branch I ended up using templates instead of the var_args solution because it seemed both safer and more efficient. llvm-svn: 104516
* Wiped out some non-ascii characters that snuck into the copyright.Howard Hinnant2010-05-111-1/+1
| | | | llvm-svn: 103516
* libcxx initial importHoward Hinnant2010-05-111-0/+201
llvm-svn: 103490
OpenPOWER on IntegriCloud