- Rewritten posix features detection according to the first POSIX/Single Unix Specification that standardized it.

- Added macro for unnamed semaphores as OSX claims this support but returns ENOSYS, which is not very useful.
- Added macro for mapped files, as QNX does not support them.
This commit is contained in:
Ion Gaztañaga
2015-01-31 23:18:32 +01:00
parent 870d1b8e2d
commit 25bb48435f
9 changed files with 130 additions and 67 deletions

View File

@@ -7,6 +7,8 @@
// See http://www.boost.org/libs/interprocess for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#if defined(BOOST_INTERPROCESS_MAPPED_FILES)
#include <boost/interprocess/detail/config_begin.hpp>
#include <boost/interprocess/detail/workaround.hpp>
@@ -106,3 +108,10 @@ int main ()
}
#include <boost/interprocess/detail/config_end.hpp>
#else //#if defined(BOOST_INTERPROCESS_MAPPED_FILES)
int main()
{
return 0;
}
#endif//#if defined(BOOST_INTERPROCESS_MAPPED_FILES)

View File

@@ -7,6 +7,8 @@
// See http://www.boost.org/libs/interprocess for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#if defined(BOOST_INTERPROCESS_MAPPED_FILES)
#include <boost/interprocess/detail/config_begin.hpp>
//[doc_managed_multiple_allocation
#include <boost/interprocess/managed_shared_memory.hpp>
@@ -89,3 +91,10 @@ int main()
}
//]
#include <boost/interprocess/detail/config_end.hpp>
#else //#if defined(BOOST_INTERPROCESS_MAPPED_FILES)
int main()
{
return 0;
}
#endif//#if defined(BOOST_INTERPROCESS_MAPPED_FILES)

View File

@@ -26,7 +26,24 @@
#else
#include <unistd.h>
#if defined(_POSIX_THREAD_PROCESS_SHARED) && ((_POSIX_THREAD_PROCESS_SHARED - 0) > 0)
//////////////////////////////////////////////////////
//Check for XSI shared memory objects. They are available in nearly all UNIX platforms
//////////////////////////////////////////////////////
#if !defined(__QNXNTO__) && !defined(__ANDROID__) && !defined(__HAIKU__)
#define BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS
#endif
//////////////////////////////////////////////////////
// From SUSv3/UNIX 98, pthread_mutexattr_settype is mandatory
//////////////////////////////////////////////////////
#if defined(_XOPEN_UNIX) && ((_XOPEN_VERSION + 0) >= 500)
#define BOOST_INTERPROCESS_POSIX_RECURSIVE_MUTEXES
#endif
//////////////////////////////////////////////////////
// _POSIX_THREAD_PROCESS_SHARED (POSIX.1b/POSIX.4)
//////////////////////////////////////////////////////
#if defined(_POSIX_THREAD_PROCESS_SHARED) && ((_POSIX_THREAD_PROCESS_SHARED + 0) > 0)
//Cygwin defines _POSIX_THREAD_PROCESS_SHARED but does not implement it.
#if defined(__CYGWIN__)
#define BOOST_INTERPROCESS_BUGGY_POSIX_PROCESS_SHARED
@@ -51,62 +68,12 @@
#endif
#endif
#if defined(_POSIX_BARRIERS) && ((_POSIX_BARRIERS - 0) > 0)
#define BOOST_INTERPROCESS_POSIX_BARRIERS
#endif
#if defined(_POSIX_SEMAPHORES) && ((_POSIX_SEMAPHORES - 0) > 0)
#define BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
#if defined(__CYGWIN__)
#define BOOST_INTERPROCESS_POSIX_SEMAPHORES_NO_UNLINK
#endif
//Some platforms have a limited (name length) named semaphore support
#elif (defined(__FreeBSD__) && (__FreeBSD__ >= 4)) || defined(__APPLE__)
#define BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
#endif
#if (defined (_V6_ILP32_OFFBIG) &&(_V6_ILP32_OFFBIG - 0 > 0)) ||\
(defined (_V6_LP64_OFF64) &&(_V6_LP64_OFF64 - 0 > 0)) ||\
(defined (_V6_LPBIG_OFFBIG) &&(_V6_LPBIG_OFFBIG - 0 > 0)) ||\
(defined (_XBS5_ILP32_OFFBIG)&&(_XBS5_ILP32_OFFBIG - 0 > 0)) ||\
(defined (_XBS5_LP64_OFF64) &&(_XBS5_LP64_OFF64 - 0 > 0)) ||\
(defined (_XBS5_LPBIG_OFFBIG)&&(_XBS5_LPBIG_OFFBIG - 0 > 0)) ||\
(defined (_FILE_OFFSET_BITS) &&(_FILE_OFFSET_BITS - 0 >= 64))||\
(defined (_FILE_OFFSET_BITS) &&(_FILE_OFFSET_BITS - 0 >= 64))
#define BOOST_INTERPROCESS_UNIX_64_BIT_OR_BIGGER_OFF_T
#endif
//Check for XSI shared memory objects. They are available in nearly all UNIX platforms
#if !defined(__QNXNTO__) && !defined(__ANDROID__) && !defined(__HAIKU__)
#define BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS
#endif
#if defined(_POSIX_SHARED_MEMORY_OBJECTS) && ((_POSIX_SHARED_MEMORY_OBJECTS - 0) > 0)
//////////////////////////////////////////////////////
// _POSIX_SHARED_MEMORY_OBJECTS (POSIX.1b/POSIX.4)
//////////////////////////////////////////////////////
#if ( defined(_POSIX_SHARED_MEMORY_OBJECTS) && ((_POSIX_SHARED_MEMORY_OBJECTS + 0) > 0) ) ||\
(defined(__vms) && __CRTL_VER >= 70200000)
#define BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS
#else
//VMS and MACOS don't define it but they have shm_open/close interface
#if defined(__vms)
#if __CRTL_VER >= 70200000
#define BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS
#endif
//Mac OS has some non-conformant features like names limited to SHM_NAME_MAX
#elif defined (__APPLE__)
//#define BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS
//#define BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS_NO_GROW
#endif
#endif
//Now check if we have only XSI shared memory
#if defined(BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS) &&\
!defined(BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS)
//#define BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS_ONLY
#endif
#if defined(_POSIX_TIMEOUTS) && ((_POSIX_TIMEOUTS - 0) > 0)
#define BOOST_INTERPROCESS_POSIX_TIMEOUTS
#endif
#ifdef BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS
//Some systems have filesystem-based resources, so the
//portable "/shmname" format does not work due to permission issues
//For those systems we need to form a path to a temporary directory:
@@ -114,23 +81,52 @@
#if defined(__hpux) || defined(__osf__) || defined(__vms) || (defined(__FreeBSD__) && (__FreeBSD__ < 7))
#define BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SHARED_MEMORY
//Some systems have "jailed" environments where shm usage is restricted at runtime
//and temporary file file based shm is possible in those executions.
//and temporary file based shm is possible in those executions.
#elif defined(__FreeBSD__)
#define BOOST_INTERPROCESS_RUNTIME_FILESYSTEM_BASED_POSIX_SHARED_MEMORY
#endif
#endif
#ifdef BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
//////////////////////////////////////////////////////
// _POSIX_MAPPED_FILES (POSIX.1b/POSIX.4)
//////////////////////////////////////////////////////
#if defined(_POSIX_MAPPED_FILES) && ((_POSIX_MAPPED_FILES + 0) > 0)
#define BOOST_INTERPROCESS_POSIX_MAPPED_FILES
#endif
//////////////////////////////////////////////////////
// _POSIX_SEMAPHORES (POSIX.1b/POSIX.4)
//////////////////////////////////////////////////////
#if ( defined(_POSIX_SEMAPHORES) && ((_POSIX_SEMAPHORES + 0) > 0) ) ||\
( defined(__FreeBSD__) && (__FreeBSD__ >= 4)) || \
defined(__APPLE__)
#define BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
//MacOsX declares _POSIX_SEMAPHORES but sem_init returns ENOSYS
#if !defined(__APPLE__)
#define BOOST_INTERPROCESS_POSIX_UNNAMED_SEMAPHORES
#endif
#if defined(__osf__) || defined(__vms)
#define BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SEMAPHORES
#endif
#endif
#if defined(_POSIX_VERSION) && defined(_XOPEN_VERSION) && \
(((_POSIX_VERSION + 0)>= 200112L || (_XOPEN_VERSION + 0)>= 500))
#define BOOST_INTERPROCESS_POSIX_RECURSIVE_MUTEXES
//////////////////////////////////////////////////////
// _POSIX_BARRIERS (SUSv3/Unix03)
//////////////////////////////////////////////////////
#if defined(_POSIX_BARRIERS) && ((_POSIX_BARRIERS + 0) >= 200112L)
#define BOOST_INTERPROCESS_POSIX_BARRIERS
#endif
//////////////////////////////////////////////////////
// _POSIX_TIMEOUTS (SUSv3/Unix03)
//////////////////////////////////////////////////////
#if defined(_POSIX_TIMEOUTS) && ((_POSIX_TIMEOUTS + 0L) >= 200112L)
#define BOOST_INTERPROCESS_POSIX_TIMEOUTS
#endif
//////////////////////////////////////////////////////
// Detect BSD derivatives to detect sysctl
//////////////////////////////////////////////////////
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
#define BOOST_INTERPROCESS_BSD_DERIVATIVE
//Some *BSD systems (OpenBSD & NetBSD) need sys/param.h before sys/sysctl.h, whereas
@@ -142,10 +138,24 @@
//#define BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME
#endif
#endif
//////////////////////////////////////////////////////
//64 bit offset
//////////////////////////////////////////////////////
#if (defined (_V6_ILP32_OFFBIG) &&(_V6_ILP32_OFFBIG - 0 > 0)) ||\
(defined (_V6_LP64_OFF64) &&(_V6_LP64_OFF64 - 0 > 0)) ||\
(defined (_V6_LPBIG_OFFBIG) &&(_V6_LPBIG_OFFBIG - 0 > 0)) ||\
(defined (_XBS5_ILP32_OFFBIG)&&(_XBS5_ILP32_OFFBIG - 0 > 0)) ||\
(defined (_XBS5_LP64_OFF64) &&(_XBS5_LP64_OFF64 - 0 > 0)) ||\
(defined (_XBS5_LPBIG_OFFBIG)&&(_XBS5_LPBIG_OFFBIG - 0 > 0)) ||\
(defined (_FILE_OFFSET_BITS) &&(_FILE_OFFSET_BITS - 0 >= 64))||\
(defined (_FILE_OFFSET_BITS) &&(_FILE_OFFSET_BITS - 0 >= 64))
#define BOOST_INTERPROCESS_UNIX_64_BIT_OR_BIGGER_OFF_T
#endif
#endif //!defined(BOOST_INTERPROCESS_WINDOWS)
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#define BOOST_INTERPROCESS_PERFECT_FORWARDING
#if defined(BOOST_INTERPROCESS_WINDOWS) || defined(BOOST_INTERPROCESS_POSIX_MAPPED_FILES)
# define BOOST_INTERPROCESS_MAPPED_FILES
#endif
//Now declare some Boost.Interprocess features depending on the implementation
@@ -154,6 +164,10 @@
#define BOOST_INTERPROCESS_NAMED_SEMAPHORE_USES_POSIX_SEMAPHORES
#endif
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#define BOOST_INTERPROCESS_PERFECT_FORWARDING
#endif
// Timeout duration use if BOOST_INTERPROCESS_ENABLE_TIMEOUT_WHEN_LOCKING is set
#ifndef BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS
#define BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS 10000

View File

@@ -18,6 +18,10 @@
#include <boost/interprocess/detail/config_begin.hpp>
#include <boost/interprocess/detail/workaround.hpp>
#if !defined(BOOST_INTERPROCESS_MAPPED_FILES)
#error "Boost.Interprocess: This platform does not support memory mapped files!"
#endif
#include <boost/interprocess/interprocess_fwd.hpp>
#include <boost/interprocess/exceptions.hpp>
#include <boost/interprocess/detail/utilities.hpp>

View File

@@ -29,9 +29,7 @@
#include <cstddef>
#include <string>
#if defined(BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS_ONLY)
# include <sys/shm.h> //System V shared memory...
#elif defined(BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS)
#if defined(BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS)
# include <fcntl.h> //O_CREAT, O_*...
# include <sys/mman.h> //shm_xxx
# include <unistd.h> //ftruncate, close

View File

@@ -25,7 +25,7 @@
#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
#if !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION) && \
(defined(BOOST_INTERPROCESS_POSIX_PROCESS_SHARED) && defined(BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES))
(defined(BOOST_INTERPROCESS_POSIX_PROCESS_SHARED) && defined(BOOST_INTERPROCESS_POSIX_UNNAMED_SEMAPHORES))
#include <boost/interprocess/sync/posix/semaphore.hpp>
#define BOOST_INTERPROCESS_USE_POSIX
//Experimental...

View File

@@ -47,6 +47,8 @@ namespace boost {
namespace interprocess {
namespace ipcdetail {
#ifdef BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
inline bool semaphore_open
(sem_t *&handle, create_enum_t type, const char *origname,
unsigned int count = 0, const permissions &perm = permissions())
@@ -130,6 +132,10 @@ inline bool semaphore_unlink(const char *semname)
}
}
#endif //BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
#ifdef BOOST_INTERPROCESS_POSIX_UNNAMED_SEMAPHORES
inline void semaphore_init(sem_t *handle, unsigned int initialCount)
{
int ret = sem_init(handle, 1, initialCount);
@@ -150,6 +156,8 @@ inline void semaphore_destroy(sem_t *handle)
}
}
#endif //BOOST_INTERPROCESS_POSIX_UNNAMED_SEMAPHORES
inline void semaphore_post(sem_t *handle)
{
int ret = sem_post(handle);

View File

@@ -8,6 +8,8 @@
//
//////////////////////////////////////////////////////////////////////////////
#if defined(BOOST_INTERPROCESS_MAPPED_FILES)
#include <boost/interprocess/detail/config_begin.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/containers/vector.hpp>
@@ -224,3 +226,12 @@ int main ()
}
#include <boost/interprocess/detail/config_end.hpp>
#else //#if defined(BOOST_INTERPROCESS_MAPPED_FILES)
int main()
{
return 0;
}
#endif//#if defined(BOOST_INTERPROCESS_MAPPED_FILES)

View File

@@ -7,6 +7,7 @@
// See http://www.boost.org/libs/interprocess for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#if defined(BOOST_INTERPROCESS_MAPPED_FILES)
#include <boost/interprocess/detail/config_begin.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
@@ -88,3 +89,12 @@ int main ()
}
#include <boost/interprocess/detail/config_end.hpp>
#else //#if !defined(BOOST_INTERPROCESS_MAPPED_FILES)
int main()
{
return 0;
}
#endif//#if !defined(BOOST_INTERPROCESS_MAPPED_FILES)