File: boostconfig.hpp

package info (click to toggle)
fastdds 3.3.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 60,540 kB
  • sloc: cpp: 793,735; xml: 15,283; python: 5,902; sh: 219; makefile: 95; ansic: 12
file content (126 lines) | stat: -rw-r--r-- 3,548 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef _FASTDDS_THIRDPARTYBOOST_BOOSTCONFIG_H_
#define _FASTDDS_THIRDPARTYBOOST_BOOSTCONFIG_H_

#include <utils/shared_memory/BoostAtExitRegistry.hpp>

#define BOOST_DATE_TIME_NO_LIB
#define BOOST_INTERPROCESS_ENABLE_TIMEOUT_WHEN_LOCKING
#define BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS 1000

// We have patched part of the boost code, protecting all changes with this define
#define BOOST_FASTDDS_PATCHES

// Starting on boost 1.76.0, this will force native emulation, which is what we want as
// it is more performant
#define BOOST_INTERPROCESS_FORCE_NATIVE_EMULATION

#ifdef ANDROID
#define BOOST_INTERPROCESS_SHARED_DIR_PATH "/data/local/tmp"
#endif

#define BOOST_INTERPROCESS_ATEXIT(f) eprosima::detail::BoostAtExitRegistry::get_instance()->at_exit_register((f))

#ifdef _MSC_VER

#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdexcept>

// TODO(Adolfo): This will fail if windows system without program data in C: drive
#define BOOST_INTERPROCESS_SHARED_DIR_PATH "C:\\ProgramData\\eprosima\\fastdds_interprocess"

// Check that generic emulation has not been accidentally enabled
#include <boost/interprocess/detail/workaround.hpp>
#if defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION)
#  error "BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION must be disabled in boost/interprocess/detail/workarround.hpp"
#endif  // BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION

#endif // _MSC_VER_

/**
 * This singleton class performs some necesary system dependent initializations
 * before start working with shared-memory
 */
class SharedMemEnvironment
{
public:

    SharedMemEnvironment()
#ifdef _MSC_VER
        : is_init_done_(false)
#endif // ifdef _MSC_VER
    {
    }

    /**
     * @return the singleton instance
     */
    static SharedMemEnvironment& get()
    {
        static SharedMemEnvironment singleton_instance;
        return singleton_instance;
    }

    /**
     * Perform the initializacion, only the first time is called.
     */
    void init()
    {
#ifdef _MSC_VER
        if (!is_init_done_)
        {
            get().create_shared_dir_if_doesnt_exist();

        }

        is_init_done_ = true;
#endif // ifdef _MSC_VER
    }

private:

#ifdef _MSC_VER

    bool is_init_done_;


    static void create_shared_dir_if_doesnt_exist()
    {
        struct stat info;

        // Cannot access shared_dir_path, we assume it doesn't exist
        if (stat(BOOST_INTERPROCESS_SHARED_DIR_PATH, &info) != 0)
        {
            // Try to create it
            if (system(("mkdir " BOOST_INTERPROCESS_SHARED_DIR_PATH)) != 0)
            {
                throw std::runtime_error("couldn't access nor create " BOOST_INTERPROCESS_SHARED_DIR_PATH);
            }
        }
    }

    void clean()
    {
        system("del " BOOST_INTERPROCESS_SHARED_DIR_PATH "\\*.* /Q");
    }

#endif // ifdef _MSC_VER

};

#endif // _FASTDDS_THIRDPARTYBOOST_BOOSTCONFIG_H_