/src/Fast-DDS/thirdparty/boost/include/boostconfig.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #ifndef _FASTDDS_THIRDPARTYBOOST_BOOSTCONFIG_H_ |
16 | | #define _FASTDDS_THIRDPARTYBOOST_BOOSTCONFIG_H_ |
17 | | |
18 | | #define BOOST_DATE_TIME_NO_LIB |
19 | | #define BOOST_INTERPROCESS_ENABLE_TIMEOUT_WHEN_LOCKING |
20 | 0 | #define BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS 1000 |
21 | | |
22 | | // We have patched part of the boost code, protecting all changes with this define |
23 | | #define BOOST_FASTDDS_PATCHES |
24 | | |
25 | | // Starting on boost 1.76.0, this will force native emulation, which is what we want as |
26 | | // it is more performant |
27 | | #define BOOST_INTERPROCESS_FORCE_NATIVE_EMULATION |
28 | | |
29 | | #ifdef _MSC_VER |
30 | | |
31 | | #include <stdlib.h> |
32 | | #include <sys/types.h> |
33 | | #include <sys/stat.h> |
34 | | #include <stdexcept> |
35 | | |
36 | | // TODO(Adolfo): This will fail if windows system without program data in C: drive |
37 | | #define BOOST_INTERPROCESS_SHARED_DIR_PATH "C:\\ProgramData\\eprosima\\fastrtps_interprocess" |
38 | | |
39 | | // Check that generic emulation has not been accidentally enabled |
40 | | #include <boost/interprocess/detail/workaround.hpp> |
41 | | #if defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION) |
42 | | # error "BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION must be disabled in boost/interprocess/detail/workarround.hpp" |
43 | | #endif // BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION |
44 | | |
45 | | #endif // _MSC_VER_ |
46 | | |
47 | | /** |
48 | | * This singleton class performs some necesary system dependent initializations |
49 | | * before start working with shared-memory |
50 | | */ |
51 | | class SharedMemEnvironment |
52 | | { |
53 | | public: |
54 | | |
55 | | SharedMemEnvironment() |
56 | | #ifdef _MSC_VER |
57 | | : is_init_done_(false) |
58 | | #endif // ifdef _MSC_VER |
59 | 0 | { |
60 | 0 | } |
61 | | |
62 | | /** |
63 | | * @return the singleton instance |
64 | | */ |
65 | | static SharedMemEnvironment& get() |
66 | 0 | { |
67 | 0 | static SharedMemEnvironment singleton_instance; |
68 | 0 | return singleton_instance; |
69 | 0 | } |
70 | | |
71 | | /** |
72 | | * Perform the initializacion, only the first time is called. |
73 | | */ |
74 | | void init() |
75 | 0 | { |
76 | | #ifdef _MSC_VER |
77 | | if (!is_init_done_) |
78 | | { |
79 | | get().create_shared_dir_if_doesnt_exist(); |
80 | | |
81 | | } |
82 | | |
83 | | is_init_done_ = true; |
84 | | #endif // ifdef _MSC_VER |
85 | 0 | } |
86 | | |
87 | | private: |
88 | | |
89 | | #ifdef _MSC_VER |
90 | | |
91 | | bool is_init_done_; |
92 | | |
93 | | |
94 | | static void create_shared_dir_if_doesnt_exist() |
95 | | { |
96 | | struct stat info; |
97 | | |
98 | | // Cannot access shared_dir_path, we assume it doesn't exist |
99 | | if (stat(BOOST_INTERPROCESS_SHARED_DIR_PATH, &info) != 0) |
100 | | { |
101 | | // Try to create it |
102 | | if (system(("mkdir " BOOST_INTERPROCESS_SHARED_DIR_PATH)) != 0) |
103 | | { |
104 | | throw std::runtime_error("couldn't access nor create " BOOST_INTERPROCESS_SHARED_DIR_PATH); |
105 | | } |
106 | | } |
107 | | } |
108 | | |
109 | | void clean() |
110 | | { |
111 | | system("del " BOOST_INTERPROCESS_SHARED_DIR_PATH "\\*.* /Q"); |
112 | | } |
113 | | |
114 | | #endif // ifdef _MSC_VER |
115 | | |
116 | | }; |
117 | | |
118 | | #endif // _FASTDDS_THIRDPARTYBOOST_BOOSTCONFIG_H_ |