summaryrefslogtreecommitdiffstats
path: root/libcxx/src/memory.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [libcxx{,abi}] Emit deplibs only when detected by CMakeMichał Górny2019-12-021-1/+1
| | | | | | | | This is a followup to 35bc5276ca3. It fixes the dependent libs usage in libcxx and libcxxabi to link pthread and rt libraries only if CMake detects them, rather than based on explicit platform blacklist. Differential Revision: https://reviews.llvm.org/D70888
* [runtimes] Don't depend on libpthread on AndroidYi Kong2019-07-221-1/+1
| | | | | | | | | | r362048 added support for ELF dependent libraries, but broke Android build since Android does not have libpthread. Remove the dependency on the Android build. Differential Revision: https://reviews.llvm.org/D65098 llvm-svn: 366734
* [runtimes] Use _LIBCPP_HAS_COMMENT_LIB_PRAGMA in all relevant filesPetr Hosek2019-05-301-1/+1
| | | | | | These two sources were omitted in r362055. llvm-svn: 362061
* [runtimes] Support ELF dependent libraries featurePetr Hosek2019-05-301-0/+3
| | | | | | | | | | | | | | | | | | | As of r360984, LLD supports dependent libraries feature for ELF. libunwind, libc++abi and libc++ have library dependencies: libdl librt and libpthread, which means that when libunwind and libc++ are being statically linked (using -static-libstdc++ flag), user has to manually specify -ldl -lpthread which is onerous. This change includes the lib pragma to specify the library dependencies directly in the source that uses those libraries. This doesn't make any difference when using linkers that don't support dependent libraries. However, when using LLD that has dependent libraries feature, users no longer have to manually specifying library dependencies when using static linking, linker will pick the library automatically. Differential Revision: https://reviews.llvm.org/D62090 llvm-svn: 362048
* Update more file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | | to reflect the new license. These used slightly different spellings that defeated my regular expressions. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351648
* [libc++] Remove _LIBCPP_BUILDING_XXX macros, which are redundant since ↵Louis Dionne2018-08-011-1/+0
| | | | | | | | | | | | | | _LIBCPP_BUILDING_LIBRARY Summary: As suggested by Marshall in https://reviews.llvm.org/D49914 Reviewers: mclow.lists, EricWF Subscribers: christof, dexonsmith, cfe-commits Differential Revision: https://reviews.llvm.org/D50008 llvm-svn: 338475
* Fix incorrect usage of __libcpp_mutex_trylock. Patch from Andrey KhalyavinEric Fiselier2017-05-041-1/+1
| | | | llvm-svn: 302129
* Use nullptr instead of the literal 0Eric Fiselier2017-05-041-2/+2
| | | | llvm-svn: 302100
* Add ABI option to remove recently inlined __shared_count functions from the ↵Eric Fiselier2017-01-171-0/+3
| | | | | | | | | | | | | | library. In order to allow inlining of previously out-of-line functions without an ABI break libc++ provides legacy definitions in the dylib that old programs can continue to use. Unfortunatly Windows link.exe detects this hack and diagnoses the duplicate definitions. This patch disable the duplicate definitions on Windows by adding an ABI option which disables all "legacy out-of-line symbols" llvm-svn: 292190
* [Test patch] Inline hot functions in libcxx shared_ptrKevin Hu2017-01-171-30/+8
| | | | | | | | | | | Moves hot functions such as atomic add into the memory header file so that they can be inlined, which brings performance benefits. Patch by Kevin Hu, Aditya Kumar, Sebastian Pop Differential Revision: https://reviews.llvm.org/D24991 llvm-svn: 292184
* Fix std::pointer_safety type in ABI v2Eric Fiselier2017-01-051-2/+3
| | | | | | | | | | | | | | | | | | | | In the C++ standard `std::pointer_safety` is defined as a C++11 strongly typed enum. However libc++ currently defines it as a class type which simulates a C++11 enumeration. This can be detected in valid C++ code. This patch introduces an the _LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE ABI option. When defined `std::pointer_safety` is implemented as an enum type. Unfortunatly this also means it can no longer be provided as an extension in C++03. Additionally this patch moves the definition for `get_pointer_safety()` out of the dylib, and into the headers. New usages of `get_pointer_safety()` will now use the inline version instead of the dylib version. However in order to keep the dylib ABI compatible the old definition is explicitly compiled into it. llvm-svn: 291046
* Mark libc++ internal globals with _LIBCPP_SAFE_STATIC.Eric Fiselier2016-09-281-9/+7
| | | | | | | | | | | | | This patch applies the _LIBCPP_SAFE_STATIC attribute to internal globals, most of which are locking primitives, in order to ensure that they can safely be used during program startup. This patch also fixes an unsafe static init issue with the global locks used to implement atomic operations on shared pointers. Previously the locks were initialized using a dynamically initialized pointer, so it was possible that the pointer was uninitialized. llvm-svn: 282640
* Fixing 'Aquire' typo and libcxx build.Ben Craig2016-08-021-1/+1
| | | | llvm-svn: 277456
* Improve shared_ptr dtor performanceBen Craig2016-08-011-1/+29
| | | | | | | | | | If the last destruction is uncontended, skip the atomic store on __shared_weak_owners_. This shifts some costs from normal shared_ptr usage to weak_ptr uses. https://reviews.llvm.org/D22470 llvm-svn: 277357
* 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