summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/dll/test/shared_library_concurrent_load_test.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/dll/test/shared_library_concurrent_load_test.cpp
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/dll/test/shared_library_concurrent_load_test.cpp')
-rw-r--r--src/boost/libs/dll/test/shared_library_concurrent_load_test.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/boost/libs/dll/test/shared_library_concurrent_load_test.cpp b/src/boost/libs/dll/test/shared_library_concurrent_load_test.cpp
new file mode 100644
index 000000000..e97926b7e
--- /dev/null
+++ b/src/boost/libs/dll/test/shared_library_concurrent_load_test.cpp
@@ -0,0 +1,82 @@
+// Copyright 2015-2019 Antony Polukhin
+//
+// 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)
+
+// For more information, see http://www.boost.org
+
+#ifdef BOOST_TRAVISCI_BUILD
+
+int main() {
+ return 0;
+}
+
+#else // #ifdef BOOST_TRAVISCI_BUILD
+
+#include "../example/b2_workarounds.hpp"
+#include <boost/dll.hpp>
+#include <boost/filesystem/path.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/core/lightweight_test.hpp>
+#include <boost/bind.hpp>
+#include <cctype>
+#include <vector>
+
+typedef std::vector<boost::dll::fs::path> paths_t;
+const std::size_t thread_count = 4;
+boost::barrier b(thread_count);
+
+
+// Disgusting workarounds for b2 on Windows platform
+inline paths_t generate_paths(int argc, char* argv[]) {
+ paths_t ret;
+ ret.reserve(argc - 1);
+
+ for (int i = 1; i < argc; ++i) {
+ boost::dll::fs::path p = argv[i];
+ if (b2_workarounds::is_shared_library(p)) {
+ ret.push_back(p);
+ }
+ }
+
+ return ret;
+}
+
+inline void load_unload(const paths_t& paths, std::size_t count) {
+ for (std::size_t j = 0; j < count; j += 2) {
+ for (std::size_t i = 0; i < paths.size(); ++i) {
+ boost::dll::shared_library lib(paths[i]);
+ BOOST_TEST(lib);
+ }
+ for (std::size_t i = 0; i < paths.size(); ++i) {
+ boost::dll::shared_library lib(paths[i]);
+ BOOST_TEST(lib.location() != "");
+ }
+
+ // Waiting for all threads to unload shared libraries
+ b.wait();
+ }
+}
+
+
+int main(int argc, char* argv[]) {
+ BOOST_TEST(argc >= 3);
+ paths_t paths = generate_paths(argc, argv);
+ BOOST_TEST(!paths.empty());
+
+ std::cout << "Libraries:\n\t";
+ std::copy(paths.begin(), paths.end(), std::ostream_iterator<boost::dll::fs::path>(std::cout, ", "));
+ std::cout << std::endl;
+
+ boost::thread_group threads;
+ for (std::size_t i = 0; i < thread_count; ++i) {
+ threads.create_thread(boost::bind(load_unload, paths, 1000));
+ }
+ threads.join_all();
+
+ return boost::report_errors();
+}
+
+#endif // #ifdef BOOST_TRAVISCI_BUILD