]>
Commit | Line | Data |
---|---|---|
20effc67 | 1 | // Copyright 2015-2020 Antony Polukhin |
7c673cae FG |
2 | // |
3 | // Distributed under the Boost Software License, Version 1.0. | |
4 | // (See accompanying file LICENSE_1_0.txt | |
5 | // or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | // For more information, see http://www.boost.org | |
8 | ||
9 | #ifdef BOOST_TRAVISCI_BUILD | |
10 | ||
11 | int main() { | |
12 | return 0; | |
13 | } | |
14 | ||
15 | #else // #ifdef BOOST_TRAVISCI_BUILD | |
16 | ||
17 | #include "../example/b2_workarounds.hpp" | |
18 | #include <boost/dll.hpp> | |
19 | #include <boost/filesystem/path.hpp> | |
20 | #include <boost/thread/thread.hpp> | |
21 | #include <boost/thread/barrier.hpp> | |
22 | #include <boost/core/lightweight_test.hpp> | |
23 | #include <boost/bind.hpp> | |
24 | #include <cctype> | |
25 | #include <vector> | |
26 | ||
92f5a8d4 | 27 | typedef std::vector<boost::dll::fs::path> paths_t; |
7c673cae FG |
28 | const std::size_t thread_count = 4; |
29 | boost::barrier b(thread_count); | |
30 | ||
31 | ||
32 | // Disgusting workarounds for b2 on Windows platform | |
33 | inline paths_t generate_paths(int argc, char* argv[]) { | |
34 | paths_t ret; | |
35 | ret.reserve(argc - 1); | |
36 | ||
37 | for (int i = 1; i < argc; ++i) { | |
92f5a8d4 | 38 | boost::dll::fs::path p = argv[i]; |
7c673cae FG |
39 | if (b2_workarounds::is_shared_library(p)) { |
40 | ret.push_back(p); | |
41 | } | |
42 | } | |
43 | ||
44 | return ret; | |
45 | } | |
46 | ||
47 | inline void load_unload(const paths_t& paths, std::size_t count) { | |
48 | for (std::size_t j = 0; j < count; j += 2) { | |
49 | for (std::size_t i = 0; i < paths.size(); ++i) { | |
50 | boost::dll::shared_library lib(paths[i]); | |
51 | BOOST_TEST(lib); | |
52 | } | |
53 | for (std::size_t i = 0; i < paths.size(); ++i) { | |
54 | boost::dll::shared_library lib(paths[i]); | |
55 | BOOST_TEST(lib.location() != ""); | |
56 | } | |
57 | ||
58 | // Waiting for all threads to unload shared libraries | |
59 | b.wait(); | |
60 | } | |
61 | } | |
62 | ||
63 | ||
64 | int main(int argc, char* argv[]) { | |
65 | BOOST_TEST(argc >= 3); | |
66 | paths_t paths = generate_paths(argc, argv); | |
67 | BOOST_TEST(!paths.empty()); | |
68 | ||
69 | std::cout << "Libraries:\n\t"; | |
92f5a8d4 | 70 | std::copy(paths.begin(), paths.end(), std::ostream_iterator<boost::dll::fs::path>(std::cout, ", ")); |
7c673cae FG |
71 | std::cout << std::endl; |
72 | ||
73 | boost::thread_group threads; | |
74 | for (std::size_t i = 0; i < thread_count; ++i) { | |
75 | threads.create_thread(boost::bind(load_unload, paths, 1000)); | |
76 | } | |
77 | threads.join_all(); | |
78 | ||
79 | return boost::report_errors(); | |
80 | } | |
81 | ||
82 | #endif // #ifdef BOOST_TRAVISCI_BUILD |