]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/dll/test/shared_library_concurrent_load_test.cpp
1 // Copyright 2015-2020 Antony Polukhin
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)
7 // For more information, see http://www.boost.org
9 #ifdef BOOST_TRAVISCI_BUILD
15 #else // #ifdef BOOST_TRAVISCI_BUILD
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>
27 typedef std::vector
<boost::dll::fs::path
> paths_t
;
28 const std::size_t thread_count
= 4;
29 boost::barrier
b(thread_count
);
32 // Disgusting workarounds for b2 on Windows platform
33 inline paths_t
generate_paths(int argc
, char* argv
[]) {
35 ret
.reserve(argc
- 1);
37 for (int i
= 1; i
< argc
; ++i
) {
38 boost::dll::fs::path p
= argv
[i
];
39 if (b2_workarounds::is_shared_library(p
)) {
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
]);
53 for (std::size_t i
= 0; i
< paths
.size(); ++i
) {
54 boost::dll::shared_library
lib(paths
[i
]);
55 BOOST_TEST(lib
.location() != "");
58 // Waiting for all threads to unload shared libraries
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());
69 std::cout
<< "Libraries:\n\t";
70 std::copy(paths
.begin(), paths
.end(), std::ostream_iterator
<boost::dll::fs::path
>(std::cout
, ", "));
71 std::cout
<< std::endl
;
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));
79 return boost::report_errors();
82 #endif // #ifdef BOOST_TRAVISCI_BUILD