cxx/include
Howard Hinnant 5fec82dc0d Implement [util.smartptr.shared.atomic]. This is the last unimplemented
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).

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@160940 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-30 01:40:57 +00:00
..
2012-07-07 17:04:52 +00:00
This commit establishes a new bucket_count policy in the unordered containers: The policy now allows a power-of-2 number of buckets to be requested (and that request honored) by the client. And if the number of buckets is set to a power of 2, then the constraint of the hash to the number of buckets uses & instead of %. If the client does not specify a number of buckets, then the policy remains unchanged: a prime number of buckets is selected. The growth policy is that the number of buckets is roughly doubled when needed. While growing, either the prime, or the power-of-2 strategy will be preserved. There is a small run time cost for putting in this switch. For very cheap hash functions, e.g. identity for int, the cost can be as high as 18%. However with more typical use cases, e.g. strings, the cost is in the noise level. I've measured cases with very cheap hash functions (int) that using a power-of-2 number of buckets can make look up about twice as fast. However I've also noted that a power-of-2 number of buckets is more susceptible to accidental catastrophic collisions. Though I've also noted that accidental catastrophic collisions are also possible when using a prime number of buckets (but seems far less likely). In short, this patch adds an extra tuning knob for those clients trying to get the last bit of performance squeezed out of their hash containers. Casual users of the hash containers will not notice the introduction of this tuning knob. Those clients who swear by power-of-2 hash containers can now opt-in to that strategy. Clients who prefer a prime number of buckets can continue as they have.
2012-07-06 17:31:14 +00:00
2011-12-01 20:21:04 +00:00
2011-10-17 20:05:10 +00:00
2012-07-20 19:20:49 +00:00
2012-07-07 17:04:52 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2012-07-13 19:17:27 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2012-07-20 22:18:27 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
ios
2012-07-21 01:03:40 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2012-07-20 19:36:34 +00:00
2011-10-17 20:05:10 +00:00
2012-07-20 21:44:27 +00:00
set
2011-10-17 20:05:10 +00:00
2011-11-29 16:45:27 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2011-12-01 20:21:04 +00:00
2012-07-20 19:09:12 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2012-07-21 16:50:47 +00:00
2011-10-17 20:05:10 +00:00
2011-10-17 20:05:10 +00:00
2012-07-21 00:51:28 +00:00