diff --git a/.drone.jsonnet b/.drone.jsonnet index b7ff71a8..749d513d 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -30,6 +30,7 @@ local linux_pipeline(name, image, environment, packages = "", sources = [], arch name: "everything", image: image, environment: environment, + privileged: true, commands: [ 'set -e', diff --git a/.drone/drone.sh b/.drone/drone.sh index 60f06760..ed7837bb 100755 --- a/.drone/drone.sh +++ b/.drone/drone.sh @@ -14,6 +14,11 @@ DRONE_BUILD_DIR=$(pwd) BOOST_BRANCH=develop if [ "$DRONE_BRANCH" = "master" ]; then BOOST_BRANCH=master; fi +if [[ $(uname) == "Linux" && ( "$TSAN" == 1 || "$ASAN" == 1 ) ]]; then + echo 0 | sudo tee /proc/sys/kernel/randomize_va_space + sudo sysctl vm.mmap_rnd_bits=28 +fi + cd .. git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root cd boost-root diff --git a/doc/unordered/changes.adoc b/doc/unordered/changes.adoc index ffdaf242..8e317b07 100644 --- a/doc/unordered/changes.adoc +++ b/doc/unordered/changes.adoc @@ -6,6 +6,13 @@ :github-pr-url: https://github.com/boostorg/unordered/pull :cpp: C++ +== Release 1.87.0 + +* Made visitation exclusive-locked within certain +`boost::concurrent_flat_set` operations to allow for safe mutable modification of elements +({github-pr-url}/265[PR#265^]). +* In Visual Studio Natvis, supported any container with an allocator that uses fancy pointers. This applies to any fancy pointer type, as long as the proper Natvis customization point "Intrinsic" functions are written for the fancy pointer type. + == Release 1.86.0 * Added container `pmr` aliases when header `` is available. The alias `boost::unordered::pmr::[container]` refers to `boost::unordered::[container]` with a `std::pmr::polymorphic_allocator` allocator type. diff --git a/doc/unordered/concurrent_flat_map.adoc b/doc/unordered/concurrent_flat_map.adoc index 50c840a9..9b11ec12 100644 --- a/doc/unordered/concurrent_flat_map.adoc +++ b/doc/unordered/concurrent_flat_map.adoc @@ -389,9 +389,13 @@ prior blocking operations on `x` synchronize with *op*. So, blocking operations An operation is said to be _blocking on rehashing of_ ``__x__`` if it blocks on `x` only when an internal rehashing is issued. -Access or modification of an element of a `boost::concurrent_flat_map` passed by reference to a -user-provided visitation function do not introduce data races when the visitation function -is executed internally by the `boost::concurrent_flat_map`. +When executed internally by a `boost::concurrent_flat_map`, the following operations by a +user-provided visitation function on the element passed do not introduce data races: + +* Read access to the element. +* Non-mutable modification of the element. +* Mutable modification of the element (if the container operation executing the visitation function is not const +and its name does not contain `cvisit`.) Any `boost::concurrent_flat_map operation` that inserts or modifies an element `e` synchronizes with the internal invocation of a visitation function on `e`. diff --git a/doc/unordered/concurrent_flat_set.adoc b/doc/unordered/concurrent_flat_set.adoc index c52725cc..83327a8f 100644 --- a/doc/unordered/concurrent_flat_set.adoc +++ b/doc/unordered/concurrent_flat_set.adoc @@ -98,25 +98,35 @@ namespace boost { // visitation + template size_t xref:#concurrent_flat_set_cvisit[visit](const key_type& k, F f); template size_t xref:#concurrent_flat_set_cvisit[visit](const key_type& k, F f) const; template size_t xref:#concurrent_flat_set_cvisit[cvisit](const key_type& k, F f) const; + template size_t xref:#concurrent_flat_set_cvisit[visit](const K& k, F f); template size_t xref:#concurrent_flat_set_cvisit[visit](const K& k, F f) const; template size_t xref:#concurrent_flat_set_cvisit[cvisit](const K& k, F f) const; + template + size_t xref:concurrent_flat_set_bulk_visit[visit](FwdIterator first, FwdIterator last, F f); template size_t xref:concurrent_flat_set_bulk_visit[visit](FwdIterator first, FwdIterator last, F f) const; template size_t xref:concurrent_flat_set_bulk_visit[cvisit](FwdIterator first, FwdIterator last, F f) const; + template size_t xref:#concurrent_flat_set_cvisit_all[visit_all](F f); template size_t xref:#concurrent_flat_set_cvisit_all[visit_all](F f) const; template size_t xref:#concurrent_flat_set_cvisit_all[cvisit_all](F f) const; + template + void xref:#concurrent_flat_set_parallel_cvisit_all[visit_all](ExecutionPolicy&& policy, F f); template void xref:#concurrent_flat_set_parallel_cvisit_all[visit_all](ExecutionPolicy&& policy, F f) const; template void xref:#concurrent_flat_set_parallel_cvisit_all[cvisit_all](ExecutionPolicy&& policy, F f) const; + template bool xref:#concurrent_flat_set_cvisit_while[visit_while](F f); template bool xref:#concurrent_flat_set_cvisit_while[visit_while](F f) const; template bool xref:#concurrent_flat_set_cvisit_while[cvisit_while](F f) const; + template + bool xref:#concurrent_flat_set_parallel_cvisit_while[visit_while](ExecutionPolicy&& policy, F f); template bool xref:#concurrent_flat_set_parallel_cvisit_while[visit_while](ExecutionPolicy&& policy, F f) const; template @@ -340,9 +350,13 @@ prior blocking operations on `x` synchronize with *op*. So, blocking operations An operation is said to be _blocking on rehashing of_ ``__x__`` if it blocks on `x` only when an internal rehashing is issued. -Access or modification of an element of a `boost::concurrent_flat_set` passed by reference to a -user-provided visitation function do not introduce data races when the visitation function -is executed internally by the `boost::concurrent_flat_set`. +When executed internally by a `boost::concurrent_flat_set`, the following operations by a +user-provided visitation function on the element passed do not introduce data races: + +* Read access to the element. +* Non-mutable modification of the element. +* Mutable modification of the element (if the container operation executing the visitation function is not const +and its name does not contain `cvisit`.) Any `boost::concurrent_flat_set operation` that inserts or modifies an element `e` synchronizes with the internal invocation of a visitation function on `e`. @@ -708,8 +722,10 @@ Concurrency:;; Blocking on `*this`. ==== [c]visit ```c++ +template size_t visit(const key_type& k, F f); template size_t visit(const key_type& k, F f) const; template size_t cvisit(const key_type& k, F f) const; +template size_t visit(const K& k, F f); template size_t visit(const K& k, F f) const; template size_t cvisit(const K& k, F f) const; ``` @@ -725,6 +741,8 @@ Notes:;; The `template` overloads only participate in overload ==== Bulk visit ```c++ +template + size_t visit(FwdIterator first, FwdIterator last, F f); template size_t visit(FwdIterator first, FwdIterator last, F f) const; template @@ -758,6 +776,7 @@ Returns:;; The number of elements visited. ==== [c]visit_all ```c++ +template size_t visit_all(F f); template size_t visit_all(F f) const; template size_t cvisit_all(F f) const; ``` @@ -772,6 +791,7 @@ Returns:;; The number of elements visited. ==== Parallel [c]visit_all ```c++ +template void visit_all(ExecutionPolicy&& policy, F f); template void visit_all(ExecutionPolicy&& policy, F f) const; template void cvisit_all(ExecutionPolicy&& policy, F f) const; ``` @@ -792,6 +812,7 @@ Unsequenced execution policies are not allowed. ==== [c]visit_while ```c++ +template bool visit_while(F f); template bool visit_while(F f) const; template bool cvisit_while(F f) const; ``` @@ -807,6 +828,7 @@ Returns:;; `false` iff `f` ever returns `false`. ==== Parallel [c]visit_while ```c++ +template bool visit_while(ExecutionPolicy&& policy, F f); template bool visit_while(ExecutionPolicy&& policy, F f) const; template bool cvisit_while(ExecutionPolicy&& policy, F f) const; ``` diff --git a/doc/unordered/debuggability.adoc b/doc/unordered/debuggability.adoc index cd40e498..319ab54e 100644 --- a/doc/unordered/debuggability.adoc +++ b/doc/unordered/debuggability.adoc @@ -5,7 +5,13 @@ == Visual Studio Natvis -All containers and iterators have custom visualizations in the Natvis framework, as long as their allocator uses regular raw pointers. Any container or iterator with an allocator using fancy pointers does not have a custom visualization right now. +All containers and iterators have custom visualizations in the Natvis framework. + +=== Using in your project + +To visualize Boost.Unordered containers in the Natvis framework in your project, simply add the file link:https://github.com/boostorg/unordered/blob/develop/extra/boost_unordered.natvis[/extra/boost_unordered.natvis] to your Visual Studio project as an "Existing Item". + +=== Visualization structure The visualizations mirror those for the standard unordered containers. A container has a maximum of 100 elements displayed at once. Each set element has its item name listed as `[i]`, where `i` is the index in the display, starting at `0`. Each map element has its item name listed as `[\{key-display}]` by default. For example, if the first element is the pair `("abc", 1)`, the item name will be `["abc"]`. This behaviour can be overridden by using the view "ShowElementsByIndex", which switches the map display behaviour to name the elements by index. This same view name is used in the standard unordered containers. @@ -13,4 +19,8 @@ By default, the closed-addressing containers will show the `[hash_function]` and By default, the open-addressing containers will show the `[hash_function]`, `[key_eq]`, `[allocator]`, and the elements. Using the view "simple" shows only the elements, with no other items present. Both the SIMD and the non-SIMD implementations are viewable through the Natvis framework. -Iterators are displayed similarly to their standard counterparts. An iterator is displayed as though it were the element that it points to. An end iterator is simply displayed as `\{ end iterator }`. +Iterators are displayed similarly to their standard counterparts. An iterator is displayed as though it were the element that it points to. An end iterator is simply displayed as `{ end iterator }`. + +=== Fancy pointers + +The container visualizations also work if you are using fancy pointers in your allocator, such as `boost::interprocess::offset_ptr`. While this is rare, Boost.Unordered has natvis customization points to support any type of fancy pointer. `boost::interprocess::offset_ptr` has support already defined in the Boost.Interprocess library, and you can add support to your own type by following the instructions contained in a comment near the end of the file link:https://github.com/boostorg/unordered/blob/develop/extra/boost_unordered.natvis[/extra/boost_unordered.natvis]. diff --git a/extra/boost_unordered.natvis b/extra/boost_unordered.natvis index 58ba0427..75df78c7 100644 --- a/extra/boost_unordered.natvis +++ b/extra/boost_unordered.natvis @@ -30,18 +30,50 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + + + + + + + + + + + + + + + + + + + + + + - - + + - current_bucket = &buckets[bucket_index] - node = current_bucket->next + current_bucket = next(to_address(&buckets), bucket_index) + node = to_address(&current_bucket->next) node->buf.t_ - node = node->next + node = to_address(&node->next) ++bucket_index @@ -54,14 +86,14 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - - + + - current_bucket = &buckets[bucket_index] - node = current_bucket->next + current_bucket = next(to_address(&buckets), bucket_index) + node = to_address(&current_bucket->next) node->buf.t_ - node = node->next + node = to_address(&node->next) ++bucket_index @@ -99,29 +131,46 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - - {p->buf.t_} + + + + + + + + + + + + + + + + + + + + {to_address(&p)->buf.t_} {{ end iterator }} - p->buf.t_ + to_address(&p)->buf.t_ - {*p} + + + + + + + + + {*get()} - *p - - - - - - ({p->first}, {p->second}) - - p->first - p->second + *get() @@ -227,10 +276,39 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -254,8 +332,8 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) cstats - - + + @@ -264,18 +342,18 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - + *p_ first_time = false n0 = reinterpret_cast<uintptr_t>(pc_) % sizeof(group_type) - pc_ -= (ptrdiff_t)n0 + pc_ = next(pc_, -(ptrdiff_t)n0) mask = (reinterpret_cast<group_type*>(pc_)->match_occupied() >> (n0+1)) << (n0+1) - pc_ += sizeof(group_type) - p_ += group_type::N + pc_ = next(pc_, sizeof(group_type)) + p_ = next(p_, group_type::N) mask = reinterpret_cast<group_type*>(pc_)->match_occupied() @@ -284,9 +362,8 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) p_ = nullptr - pc_ += (ptrdiff_t)n - p_ -= (ptrdiff_t)n0 - p_ += (ptrdiff_t)n + pc_ = next(pc_, (ptrdiff_t)n) + p_ = next(p_, (ptrdiff_t)n - (ptrdiff_t)n0) @@ -299,8 +376,8 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) cstats - - + + @@ -309,18 +386,18 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - + *p_ first_time = false n0 = reinterpret_cast<uintptr_t>(pc_) % sizeof(group_type) - pc_ -= (ptrdiff_t)n0 + pc_ = next(pc_, -(ptrdiff_t)n0) mask = (reinterpret_cast<group_type*>(pc_)->match_occupied() >> (n0+1)) << (n0+1) - pc_ += sizeof(group_type) - p_ += group_type::N + pc_ = next(pc_, sizeof(group_type)) + p_ = next(p_, group_type::N) mask = reinterpret_cast<group_type*>(pc_)->match_occupied() @@ -329,9 +406,8 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) p_ = nullptr - pc_ += (ptrdiff_t)n - p_ -= (ptrdiff_t)n0 - p_ += (ptrdiff_t)n + pc_ = next(pc_, (ptrdiff_t)n) + p_ = next(p_, (ptrdiff_t)n - (ptrdiff_t)n0) @@ -369,12 +445,62 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - - {*p_} + + + + + + + + + + + + + + + {*to_address(&p_)} {{ end iterator }} - *p_ + *to_address(&p_) + + + + diff --git a/include/boost/unordered/concurrent_flat_set.hpp b/include/boost/unordered/concurrent_flat_set.hpp index d0665f71..7977f91c 100644 --- a/include/boost/unordered/concurrent_flat_set.hpp +++ b/include/boost/unordered/concurrent_flat_set.hpp @@ -227,6 +227,13 @@ namespace boost { return size() == 0; } + template + BOOST_FORCEINLINE size_type visit(key_type const& k, F f) + { + BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) + return table_.visit(k, f); + } + template BOOST_FORCEINLINE size_type visit(key_type const& k, F f) const { @@ -241,6 +248,15 @@ namespace boost { return table_.visit(k, f); } + template + BOOST_FORCEINLINE typename std::enable_if< + detail::are_transparent::value, size_type>::type + visit(K&& k, F f) + { + BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) + return table_.visit(std::forward(k), f); + } + template BOOST_FORCEINLINE typename std::enable_if< detail::are_transparent::value, size_type>::type @@ -259,6 +275,15 @@ namespace boost { return table_.visit(std::forward(k), f); } + template + BOOST_FORCEINLINE + size_t visit(FwdIterator first, FwdIterator last, F f) + { + BOOST_UNORDERED_STATIC_ASSERT_BULK_VISIT_ITERATOR(FwdIterator) + BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) + return table_.visit(first, last, f); + } + template BOOST_FORCEINLINE size_t visit(FwdIterator first, FwdIterator last, F f) const @@ -277,6 +302,12 @@ namespace boost { return table_.visit(first, last, f); } + template size_type visit_all(F f) + { + BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) + return table_.visit_all(f); + } + template size_type visit_all(F f) const { BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) @@ -290,6 +321,16 @@ namespace boost { } #if defined(BOOST_UNORDERED_PARALLEL_ALGORITHMS) + template + typename std::enable_if::value, + void>::type + visit_all(ExecPolicy&& p, F f) + { + BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) + BOOST_UNORDERED_STATIC_ASSERT_EXEC_POLICY(ExecPolicy) + table_.visit_all(p, f); + } + template typename std::enable_if::value, void>::type @@ -311,6 +352,12 @@ namespace boost { } #endif + template bool visit_while(F f) + { + BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) + return table_.visit_while(f); + } + template bool visit_while(F f) const { BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) @@ -324,6 +371,16 @@ namespace boost { } #if defined(BOOST_UNORDERED_PARALLEL_ALGORITHMS) + template + typename std::enable_if::value, + bool>::type + visit_while(ExecPolicy&& p, F f) + { + BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) + BOOST_UNORDERED_STATIC_ASSERT_EXEC_POLICY(ExecPolicy) + return table_.visit_while(p, f); + } + template typename std::enable_if::value, bool>::type @@ -384,14 +441,14 @@ namespace boost { BOOST_FORCEINLINE bool insert_or_visit(value_type const& obj, F f) { BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) - return table_.insert_or_cvisit(obj, f); + return table_.insert_or_visit(obj, f); } template BOOST_FORCEINLINE bool insert_or_visit(value_type&& obj, F f) { BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) - return table_.insert_or_cvisit(std::move(obj), f); + return table_.insert_or_visit(std::move(obj), f); } template @@ -401,7 +458,7 @@ namespace boost { insert_or_visit(K&& k, F f) { BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) - return table_.try_emplace_or_cvisit(std::forward(k), f); + return table_.try_emplace_or_visit(std::forward(k), f); } template @@ -409,7 +466,7 @@ namespace boost { { BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) for (; first != last; ++first) { - table_.emplace_or_cvisit(*first, f); + table_.emplace_or_visit(*first, f); } } @@ -417,7 +474,7 @@ namespace boost { void insert_or_visit(std::initializer_list ilist, F f) { BOOST_UNORDERED_STATIC_ASSERT_CONST_INVOCABLE(F) - this->insert_or_cvisit(ilist.begin(), ilist.end(), f); + this->insert_or_visit(ilist.begin(), ilist.end(), f); } template @@ -469,7 +526,7 @@ namespace boost { BOOST_FORCEINLINE bool emplace_or_visit(Arg&& arg, Args&&... args) { BOOST_UNORDERED_STATIC_ASSERT_LAST_ARG_CONST_INVOCABLE(Arg, Args...) - return table_.emplace_or_cvisit( + return table_.emplace_or_visit( std::forward(arg), std::forward(args)...); } diff --git a/include/boost/unordered/detail/foa/core.hpp b/include/boost/unordered/detail/foa/core.hpp index e89a21cf..3da26fef 100644 --- a/include/boost/unordered/detail/foa/core.hpp +++ b/include/boost/unordered/detail/foa/core.hpp @@ -1017,6 +1017,11 @@ struct table_arrays rebind; using group_type_pointer_traits=boost::pointer_traits; + // For natvis purposes + using char_pointer= + typename boost::pointer_traits::template + rebind; + table_arrays( std::size_t gsi,std::size_t gsm, group_type_pointer pg,value_type_pointer pe): diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 256b8489..0efd19d0 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -45,6 +45,8 @@ path-constant BOOST_UNORDERED_TEST_DIR : . ; run quick.cpp ; +compile natvis_tests.cpp ; + compile unordered/self_include_tests_obj.cpp : BOOST_UNORDERED_HEADER="boost/unordered_map.hpp" : tl_unordered_map_hpp ; diff --git a/test/cfoa/visit_tests.cpp b/test/cfoa/visit_tests.cpp index 61452ef7..02bcea32 100644 --- a/test/cfoa/visit_tests.cpp +++ b/test/cfoa/visit_tests.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2023 Christian Mazakas -// Copyright (C) 2023 Joaquin M Lopez Munoz +// Copyright (C) 2023-2024 Joaquin M Lopez Munoz // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -27,7 +28,10 @@ #include #include +#include #include +#include +#include #include namespace { @@ -971,6 +975,147 @@ namespace { boost::unordered::concurrent_flat_set* transp_set; + struct mutable_pair + { + mutable_pair(int first_ = 0, int second_ = 0): + first{first_}, second{second_} {} + + int first = 0; + mutable int second = 0; + }; + + struct null_mutable_pair + { + operator mutable_pair() const { return {0,0}; } + }; + + struct mutable_pair_hash + { + using is_transparent = void; + + std::size_t operator()(const mutable_pair& x) const + { + return boost::hash{}(x.first); + } + + std::size_t operator()(const null_mutable_pair&) const + { + return boost::hash{}(0); + } + }; + + struct mutable_pair_equal_to + { + using is_transparent = void; + + bool operator()(const mutable_pair& x, const mutable_pair& y) const + { + return x.first == y.first; + } + + bool operator()(const null_mutable_pair&, const mutable_pair& y) const + { + return 0 == y.first; + } + + bool operator()(const mutable_pair& x, const null_mutable_pair&) const + { + return x.first == 0; + } + }; + + template + void exclusive_access_for(F f) + { + std::atomic_int num_started{0}; + std::atomic_int in_visit{0}; + boost::compat::latch finish{1}; + + auto bound_f = [&] { + ++num_started; + f([&] (const mutable_pair& x) { + ++in_visit; + ++x.second; + finish.wait(); + --in_visit; + return true; + }); + }; + + std::thread t1{bound_f}, t2{bound_f}; + while(num_started != 2) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + BOOST_TEST(in_visit <= 1); + finish.count_down(); + t1.join(); + t2.join(); + } + + template + void exclusive_access_set_visit(X*) + { + using visit_function = std::function; + using returning_visit_function = std::function; + X x; + x.insert({0, 0}); + + exclusive_access_for([&](visit_function f) { + x.visit({0, 0}, f); + }); + exclusive_access_for([&](visit_function f) { + x.visit(null_mutable_pair{}, f); + }); + + exclusive_access_for([&](visit_function f) { + mutable_pair a[] = {{0, 0}}; + x.visit(std::begin(a), std::end(a), f); + }); + + exclusive_access_for([&](visit_function f) { + x.visit_all(f); + }); + exclusive_access_for([&](returning_visit_function f) { + x.visit_while(f); + }); + + #if defined(BOOST_UNORDERED_PARALLEL_ALGORITHMS) + exclusive_access_for([&](visit_function f) { + x.visit_all(std::execution::par, f); + }); + exclusive_access_for([&](returning_visit_function f) { + x.visit_while(std::execution::par, f); + }); + #endif + + exclusive_access_for([&](visit_function f) { + const mutable_pair p; + x.insert_or_visit(p, f); + }); + exclusive_access_for([&](visit_function f) { + x.insert_or_visit({0,0}, f); + }); + exclusive_access_for([&](visit_function f) { + x.insert_or_visit(null_mutable_pair{}, f); + }); + + exclusive_access_for([&](visit_function f) { + mutable_pair a[] = {{0, 0}}; + x.insert_or_visit(std::begin(a), std::end(a), f); + }); + exclusive_access_for([&](visit_function f) { + std::initializer_list il = {{0, 0}}; + x.insert_or_visit(il, f); + }); + + exclusive_access_for([&](visit_function f) { + x.emplace_or_visit(0, 0, f); + }); + } + + boost::concurrent_flat_set< + mutable_pair, mutable_pair_hash, mutable_pair_equal_to>* mutable_set; + } // namespace using test::default_generator; @@ -1024,6 +1169,13 @@ UNORDERED_TEST( ((sequential)) ) +// https://github.com/boostorg/unordered/issues/260 + +UNORDERED_TEST( + exclusive_access_set_visit, + ((mutable_set)) +) + // clang-format on RUN_TESTS() diff --git a/test/natvis_tests.cpp b/test/natvis_tests.cpp new file mode 100644 index 00000000..4a420b80 --- /dev/null +++ b/test/natvis_tests.cpp @@ -0,0 +1,187 @@ +// Copyright 2024 Braden Ganetsky +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +// This test applies to MSVC only. This is a file for manual testing. +// Run this test and break manually at the variable called `break_here`. +// Inspect the variables using the Visual Studio debugger to test correctness. + +#if !defined(BOOST_MSVC) + +#include +BOOST_PRAGMA_MESSAGE("These tests are for Visual Studio only.") +int main() {} + +#else + +#if 0 // Change to `#if 1` to test turning off SIMD optimizations +#define BOOST_UNORDERED_DISABLE_SSE2 +#define BOOST_UNORDERED_DISABLE_NEON +#endif + +#define BOOST_UNORDERED_ENABLE_STATS + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Prevent any "unused" errors +template void use(Args&&...) {} + +using map_value_type = std::pair; +using set_value_type = std::string; + +template void natvis_test(Tester& tester) +{ + // clang-format off + auto fca_map = tester.template construct_map(); + auto fca_multimap = tester.template construct_map(); + auto fca_set = tester.template construct_set(); + auto fca_multiset = tester.template construct_set(); + + auto foa_flat_map = tester.template construct_map(); + auto foa_flat_set = tester.template construct_set(); + auto foa_node_map = tester.template construct_map(); + auto foa_node_set = tester.template construct_set(); + + auto cfoa_flat_map = tester.template construct_map(); + auto cfoa_flat_set = tester.template construct_set(); + // clang-format on + + for (int i = 0; i < 5; ++i) { + const auto str = std::to_string(i * 2); + const auto num = i * 11; + + fca_map->emplace(str, num); + fca_multimap->emplace(str, num); + fca_multimap->emplace(str, num + 1); + foa_flat_map->emplace(str, num); + foa_node_map->emplace(str, num); + cfoa_flat_map->emplace(str, num); + + fca_set->emplace(str); + fca_multiset->emplace(str); + fca_multiset->emplace(str); + foa_flat_set->emplace(str); + foa_node_set->emplace(str); + cfoa_flat_set->emplace(str); + } + + auto fca_map_begin = fca_map->begin(); + auto fca_map_end = fca_map->end(); + auto fca_multimap_begin = fca_multimap->begin(); + auto fca_multimap_end = fca_multimap->end(); + auto fca_set_begin = fca_set->begin(); + auto fca_set_end = fca_set->end(); + auto fca_multiset_begin = fca_multiset->begin(); + auto fca_multiset_end = fca_multiset->end(); + + auto foa_flat_map_begin = foa_flat_map->begin(); + auto foa_flat_map_end = foa_flat_map->end(); + auto foa_flat_set_begin = foa_flat_set->begin(); + auto foa_flat_set_end = foa_flat_set->end(); + auto foa_node_map_begin = foa_node_map->begin(); + auto foa_node_map_end = foa_node_map->end(); + auto foa_node_set_begin = foa_node_set->begin(); + auto foa_node_set_end = foa_node_set->end(); + + use(cfoa_flat_map, cfoa_flat_set); + use(fca_map_begin, fca_map_end, fca_multimap_begin, fca_multimap_end, + fca_set_begin, fca_set_end, fca_multiset_begin, fca_multiset_end); + use(foa_flat_map_begin, foa_flat_map_end, foa_flat_set_begin, + foa_flat_set_end, foa_node_map_begin, foa_node_map_end, foa_node_set_begin, + foa_node_set_end); + + int break_here = 0; + use(break_here); +} + +class offset_ptr_tester_ +{ + static constexpr std::size_t SEGMENT_SIZE = 64 * 1024; + std::string segment_name = to_string(boost::uuids::random_generator()()); + boost::interprocess::managed_shared_memory segment{ + boost::interprocess::create_only, segment_name.c_str(), SEGMENT_SIZE}; + + using map_allocator = boost::interprocess::allocator; + using set_allocator = boost::interprocess::allocator; + + template