25 #ifndef INCLUDED_SharedMemory_h_GUID_4EAFB440_5023_439B_9413_0E54BC240DBD 
   26 #define INCLUDED_SharedMemory_h_GUID_4EAFB440_5023_439B_9413_0E54BC240DBD 
   30 #define BOOST_CB_DISABLE_DEBUG 
   33 #define BOOST_DATE_TIME_NO_LIB 
   37 #include <boost/version.hpp> 
   38 #if defined(__clang__) && (BOOST_VERSION < 105000) &&                          \ 
   39     !defined(BOOST_NO_TEMPLATE_ALIASES) 
   40 #define OSVR_NEEDS_BOOST_CLANG_WORKAROUND 
   47 #ifdef OSVR_NEEDS_BOOST_CLANG_WORKAROUND 
   48 #define BOOST_NO_TEMPLATE_ALIASES 
   50 #include <boost/interprocess/mem_algo/rbtree_best_fit.hpp> 
   51 #ifdef OSVR_NEEDS_BOOST_CLANG_WORKAROUND 
   52 #undef BOOST_NO_TEMPLATE_ALIASES 
   55 #include <boost/interprocess/interprocess_fwd.hpp> 
   56 #include <boost/interprocess/offset_ptr.hpp> 
   62 #undef OSVR_USE_PLATFORM_SPECIALIZED_SHM 
   64 #if defined(BOOST_INTERPROCESS_WINDOWS) 
   67 #define OSVR_HAVE_WINDOWS_SHM 
   68 #include <boost/interprocess/managed_windows_shared_memory.hpp> 
   69 #elif defined(BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS) 
   71 #undef OSVR_HAVE_XSI_SHM 
   72 #ifdef OSVR_USE_PLATFORM_SPECIALIZED_SHM 
   73 #undef OSVR_USE_PLATFORM_SPECIALIZED_SHM 
   75 #include <boost/interprocess/managed_xsi_shared_memory.hpp> 
   77 #ifdef OSVR_USE_PLATFORM_SPECIALIZED_SHM 
   78 #undef OSVR_USE_PLATFORM_SPECIALIZED_SHM 
   82 #include <boost/interprocess/managed_shared_memory.hpp> 
   93             typedef int64_t my_ptrdiff;
 
   94             typedef uint64_t my_uintptr;
 
   96                 sizeof(my_ptrdiff) == 
sizeof(my_uintptr),
 
   97                 "These types must be the same size - the largest " 
   98                 "possible pointer size on a given platform that you want " 
  100             static_assert(
sizeof(my_ptrdiff) >= 
sizeof(::ptrdiff_t),
 
  101                           "my_ptrdiff must be at least as big as ptrdiff_t!");
 
  102             static_assert(
sizeof(my_uintptr) >= 
sizeof(::uintptr_t),
 
  103                           "my_uintptr must be at least as big as uintptr_t!");
 
  105             template <
typename T>
 
  106             using my_offset_ptr =
 
  107                 boost::interprocess::offset_ptr<T, my_ptrdiff, my_uintptr>;
 
  110         template <
typename T> 
using ipc_offset_ptr = detail::my_offset_ptr<T>;
 
  113         template <
typename T>
 
  114         using ipc_offset_ptr = boost::interprocess::offset_ptr<T>;
 
  117         template <
class MutexFamily>
 
  118         using my_mem_alloc_algo =
 
  119             boost::interprocess::rbtree_best_fit<MutexFamily,
 
  120                                                  ipc_offset_ptr<void> >;
 
  122         template <
class IndexConfig>
 
  123         using index_type = boost::interprocess::iset_index<IndexConfig>;
 
  129             static void remove(
const char *name) {
 
  130                 typedef typename ManagedMemory::device_type 
device_type;
 
  131                 device_type::remove(name);
 
  135         typedef uint8_t SharedMemoryBackendType;
 
  136         static const SharedMemoryBackendType BASIC_MANAGED_SHM_ID = 0;
 
  137         static const SharedMemoryBackendType WINDOWS_MANAGED_SHM_ID = 1;
 
  138         static const SharedMemoryBackendType SYSV_MANAGED_SHM_ID = 2;
 
  140         using basic_managed_shm =
 
  141             boost::interprocess::basic_managed_shared_memory<
 
  142                 char, my_mem_alloc_algo<boost::interprocess::mutex_family>,
 
  145 #if defined(OSVR_HAVE_WINDOWS_SHM) 
  146         using windows_managed_shm =
 
  147             boost::interprocess::basic_managed_windows_shared_memory<
 
  148                 char, my_mem_alloc_algo<boost::interprocess::mutex_family>,
 
  150         template <> 
struct device_type<windows_managed_shm> {
 
  151             static void remove(
const char *) {}
 
  155 #if defined(OSVR_HAVE_XSI_SHM) 
  157         using sysv_managed_shm =
 
  158             boost::interprocess::basic_managed_xsi_shared_memory<
 
  159                 char, my_mem_alloc_algo<boost::interprocess::mutex_family>,
 
  163 #ifdef OSVR_USE_PLATFORM_SPECIALIZED_SHM 
  164 #if defined(OSVR_HAVE_WINDOWS_SHM) 
  165         using default_managed_shm = windows_managed_shm;
 
  166         static const SharedMemoryBackendType DEFAULT_MANAGED_SHM_ID =
 
  167             WINDOWS_MANAGED_SHM_ID;
 
  168 #elif defined(OSVR_HAVE_XSI_SHM) 
  169         using default_managed_shm = sysv_managed_shm;
 
  170         static const SharedMemoryBackendType DEFAULT_MANAGED_SHM_ID =
 
  174     "Unknown kind of platform-specialized shared memory - this set of conditionals must match the one with the includes above!" 
  176 #else  // !OSVR_USE_PLATFORM_SPECIALIZED_SHM 
  177         using default_managed_shm = basic_managed_shm;
 
  178         static const SharedMemoryBackendType DEFAULT_MANAGED_SHM_ID =
 
  179             BASIC_MANAGED_SHM_ID;
 
  180 #endif // OSVR_USE_PLATFORM_SPECIALIZED_SHM 
  183         inline std::string make_name_safe(std::string 
const &input) {
 
  184             static const char UNDERSCORE = 
'_';
 
  185             std::string ret{input};
 
  188             if (ret.empty() || !std::isalpha(ret[0])) {
 
  192             for (
auto &c : ret) {
 
  193                 if (std::isalpha(c) || std::isdigit(c) || UNDERSCORE == c) {
 
  201     using ipc::ipc_offset_ptr;
 
  205 #endif // INCLUDED_SharedMemory_h_GUID_4EAFB440_5023_439B_9413_0E54BC240DBD 
Helper function to be able to remove shared memory. Specializations allow this to turn into a no-op f...
Header wrapping the C99 standard stdint header.