update boost

This commit is contained in:
2023-11-24 12:56:13 -06:00
parent cfc99971af
commit 19d727037a
9260 changed files with 849256 additions and 299957 deletions

View File

@@ -22,11 +22,12 @@
#include <boost/interprocess/detail/config_begin.hpp>
#include <boost/interprocess/detail/workaround.hpp>
#include <boost/interprocess/sync/cv_status.hpp>
#include <pthread.h>
#include <errno.h>
#include <boost/interprocess/sync/posix/pthread_helpers.hpp>
#include <boost/interprocess/sync/posix/ptime_to_timespec.hpp>
#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
#include <boost/interprocess/sync/posix/timepoint_to_timespec.hpp>
#include <boost/interprocess/detail/timed_utils.hpp>
#include <boost/interprocess/sync/posix/mutex.hpp>
#include <boost/assert.hpp>
@@ -84,13 +85,13 @@ class posix_condition
//!this->notify_one() or this->notify_all(), or until time abs_time is reached,
//!and then reacquires the lock.
//!Returns: false if time abs_time is reached, otherwise true.
template <typename L>
bool timed_wait(L& lock, const boost::posix_time::ptime &abs_time)
template <typename L, typename TimePoint>
bool timed_wait(L& lock, const TimePoint &abs_time)
{
if (!lock)
throw lock_exception();
//Posix does not support infinity absolute time so handle it here
if(abs_time == boost::posix_time::pos_infin){
if(ipcdetail::is_pos_infinity(abs_time)){
this->wait(lock);
return true;
}
@@ -100,13 +101,13 @@ class posix_condition
//!The same as: while (!pred()) {
//! if (!timed_wait(lock, abs_time)) return pred();
//! } return true;
template <typename L, typename Pr>
bool timed_wait(L& lock, const boost::posix_time::ptime &abs_time, Pr pred)
template <typename L, typename TimePoint, typename Pr>
bool timed_wait(L& lock, const TimePoint &abs_time, Pr pred)
{
if (!lock)
throw lock_exception();
//Posix does not support infinity absolute time so handle it here
if(abs_time == boost::posix_time::pos_infin){
if(ipcdetail::is_pos_infinity(abs_time)){
this->wait(lock, pred);
return true;
}
@@ -117,10 +118,30 @@ class posix_condition
return true;
}
//!Same as `timed_wait`, but this function is modeled after the
//!standard library interface.
template <typename L, class TimePoint>
cv_status wait_until(L& lock, const TimePoint &abs_time)
{ return this->timed_wait(lock, abs_time) ? cv_status::no_timeout : cv_status::timeout; }
//!Same as `timed_wait`, but this function is modeled after the
//!standard library interface.
template <typename L, class TimePoint, typename Pr>
bool wait_until(L& lock, const TimePoint &abs_time, Pr pred)
{ return this->timed_wait(lock, abs_time, pred); }
template <typename L, class Duration>
cv_status wait_for(L& lock, const Duration &dur)
{ return this->wait_until(lock, duration_to_ustime(dur)) ? cv_status::no_timeout : cv_status::timeout; }
template <typename L, class Duration, typename Pr>
bool wait_for(L& lock, const Duration &dur, Pr pred)
{ return this->wait_until(lock, duration_to_ustime(dur), pred); }
void do_wait(posix_mutex &mut);
bool do_timed_wait(const boost::posix_time::ptime &abs_time, posix_mutex &mut);
template<class TimePoint>
bool do_timed_wait(const TimePoint &abs_time, posix_mutex &mut);
private:
pthread_cond_t m_condition;
@@ -175,10 +196,11 @@ inline void posix_condition::do_wait(posix_mutex &mut)
BOOST_ASSERT(res == 0); (void)res;
}
template<class TimePoint>
inline bool posix_condition::do_timed_wait
(const boost::posix_time::ptime &abs_time, posix_mutex &mut)
(const TimePoint &abs_time, posix_mutex &mut)
{
timespec ts = ptime_to_timespec(abs_time);
timespec ts = timepoint_to_timespec(abs_time);
pthread_mutex_t* pmutex = &mut.m_mut;
int res = 0;
res = pthread_cond_timedwait(&m_condition, pmutex, &ts);

View File

@@ -41,10 +41,11 @@
#include <pthread.h>
#include <errno.h>
#include <boost/interprocess/exceptions.hpp>
#include <boost/interprocess/sync/posix/ptime_to_timespec.hpp>
#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
#include <boost/interprocess/sync/posix/timepoint_to_timespec.hpp>
#include <boost/interprocess/exceptions.hpp>
#include <boost/interprocess/sync/posix/pthread_helpers.hpp>
#include <boost/interprocess/detail/timed_utils.hpp>
#ifndef BOOST_INTERPROCESS_POSIX_TIMEOUTS
# include <boost/interprocess/detail/os_thread_functions.hpp>
@@ -69,7 +70,14 @@ class posix_mutex
void lock();
bool try_lock();
bool timed_lock(const boost::posix_time::ptime &abs_time);
template<class TimePoint> bool timed_lock(const TimePoint &abs_time);
template<class TimePoint> bool try_lock_until(const TimePoint &abs_time)
{ return this->timed_lock(abs_time); }
template<class Duration> bool try_lock_for(const Duration &dur)
{ return this->timed_lock(duration_to_ustime(dur)); }
void unlock();
friend class posix_condition;
@@ -93,28 +101,66 @@ inline posix_mutex::~posix_mutex()
inline void posix_mutex::lock()
{
if (pthread_mutex_lock(&m_mut) != 0)
int res = pthread_mutex_lock(&m_mut);
#ifdef BOOST_INTERPROCESS_POSIX_ROBUST_MUTEXES
if (res == EOWNERDEAD)
{
//We can't inform the application and data might
//corrupted, so be safe and mark the mutex as not recoverable
//so applications can act accordingly.
pthread_mutex_unlock(&m_mut);
throw lock_exception(not_recoverable);
}
else if (res == ENOTRECOVERABLE)
throw lock_exception(not_recoverable);
#endif
if (res != 0)
throw lock_exception();
}
inline bool posix_mutex::try_lock()
{
int res = pthread_mutex_trylock(&m_mut);
#ifdef BOOST_INTERPROCESS_POSIX_ROBUST_MUTEXES
if (res == EOWNERDEAD)
{
//We can't inform the application and data might
//corrupted, so be safe and mark the mutex as not recoverable
//so applications can act accordingly.
pthread_mutex_unlock(&m_mut);
throw lock_exception(not_recoverable);
}
else if (res == ENOTRECOVERABLE)
throw lock_exception(not_recoverable);
#endif
if (!(res == 0 || res == EBUSY))
throw lock_exception();
return res == 0;
}
inline bool posix_mutex::timed_lock(const boost::posix_time::ptime &abs_time)
template<class TimePoint>
inline bool posix_mutex::timed_lock(const TimePoint &abs_time)
{
#ifdef BOOST_INTERPROCESS_POSIX_TIMEOUTS
//Posix does not support infinity absolute time so handle it here
if(abs_time == boost::posix_time::pos_infin){
if(ipcdetail::is_pos_infinity(abs_time)){
this->lock();
return true;
}
timespec ts = ptime_to_timespec(abs_time);
timespec ts = timepoint_to_timespec(abs_time);
int res = pthread_mutex_timedlock(&m_mut, &ts);
#ifdef BOOST_INTERPROCESS_POSIX_ROBUST_MUTEXES
if (res == EOWNERDEAD)
{
//We can't inform the application and data might
//corrupted, so be safe and mark the mutex as not recoverable
//so applications can act accordingly.
pthread_mutex_unlock(&m_mut);
throw lock_exception(not_recoverable);
}
else if (res == ENOTRECOVERABLE)
throw lock_exception(not_recoverable);
#endif
if (res != 0 && res != ETIMEDOUT)
throw lock_exception();
return res == 0;
@@ -128,8 +174,7 @@ inline bool posix_mutex::timed_lock(const boost::posix_time::ptime &abs_time)
inline void posix_mutex::unlock()
{
int res = 0;
res = pthread_mutex_unlock(&m_mut);
int res = pthread_mutex_unlock(&m_mut);
(void)res;
BOOST_ASSERT(res == 0);
}

View File

@@ -45,18 +45,29 @@ class posix_named_mutex
#endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
public:
posix_named_mutex(create_only_t create_only, const char *name, const permissions &perm = permissions());
posix_named_mutex(create_only_t, const char *name, const permissions &perm = permissions());
posix_named_mutex(open_or_create_t open_or_create, const char *name, const permissions &perm = permissions());
posix_named_mutex(open_or_create_t, const char *name, const permissions &perm = permissions());
posix_named_mutex(open_only_t open_only, const char *name);
posix_named_mutex(open_only_t, const char *name);
~posix_named_mutex();
void unlock();
void lock();
bool try_lock();
bool timed_lock(const boost::posix_time::ptime &abs_time);
template<class TimePoint>
bool timed_lock(const TimePoint &abs_time);
template<class TimePoint>
bool try_lock_until(const TimePoint &abs_time)
{ return this->timed_lock(abs_time); }
template<class Duration>
bool try_lock_for(const Duration &dur)
{ return this->timed_lock(duration_to_ustime(dur)); }
static bool remove(const char *name);
#if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
@@ -97,7 +108,8 @@ inline void posix_named_mutex::unlock()
inline bool posix_named_mutex::try_lock()
{ return m_sem.try_wait(); }
inline bool posix_named_mutex::timed_lock(const boost::posix_time::ptime &abs_time)
template<class TimePoint>
inline bool posix_named_mutex::timed_lock(const TimePoint &abs_time)
{ return m_sem.timed_wait(abs_time); }
inline bool posix_named_mutex::remove(const char *name)

View File

@@ -65,7 +65,8 @@ class posix_named_semaphore
bool try_wait()
{ return semaphore_try_wait(mp_sem); }
bool timed_wait(const boost::posix_time::ptime &abs_time)
template<class TimePoint>
bool timed_wait(const TimePoint &abs_time)
{ return semaphore_timed_wait(mp_sem, abs_time); }
static bool remove(const char *name)

View File

@@ -41,8 +41,12 @@ namespace ipcdetail{
if(pthread_mutexattr_init(&m_attr)!=0 ||
pthread_mutexattr_setpshared(&m_attr, PTHREAD_PROCESS_SHARED)!= 0 ||
(recursive &&
pthread_mutexattr_settype(&m_attr, PTHREAD_MUTEX_RECURSIVE)!= 0 ))
throw interprocess_exception("pthread_mutexattr_xxxx failed");
pthread_mutexattr_settype(&m_attr, PTHREAD_MUTEX_RECURSIVE) != 0 )
#ifdef BOOST_INTERPROCESS_POSIX_ROBUST_MUTEXES
|| pthread_mutexattr_setrobust(&m_attr, PTHREAD_MUTEX_ROBUST) != 0
#endif
)
throw interprocess_exception("pthread_mutexattr_xxxx failed");
}
//!Destructor
@@ -144,7 +148,7 @@ namespace ipcdetail{
//!Constructor. Takes barrier attributes to initialize the barrier
barrier_initializer(pthread_barrier_t &mut,
pthread_barrierattr_t &mut_attr,
int count)
unsigned int count)
: mp_barrier(&mut)
{
if(pthread_barrier_init(mp_barrier, &mut_attr, count) != 0)

View File

@@ -1,48 +0,0 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/interprocess for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTERPROCESS_DETAIL_PTIME_TO_TIMESPEC_HPP
#define BOOST_INTERPROCESS_DETAIL_PTIME_TO_TIMESPEC_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
namespace boost {
namespace interprocess {
namespace ipcdetail {
inline timespec ptime_to_timespec (const boost::posix_time::ptime &tm)
{
const boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
//Avoid negative absolute times
boost::posix_time::time_duration duration = (tm <= epoch) ? boost::posix_time::time_duration(epoch - epoch)
: boost::posix_time::time_duration(tm - epoch);
timespec ts;
ts.tv_sec = duration.total_seconds();
ts.tv_nsec = duration.total_nanoseconds() % 1000000000;
return ts;
}
} //namespace ipcdetail {
} //namespace interprocess {
} //namespace boost {
#endif //ifndef BOOST_INTERPROCESS_DETAIL_PTIME_TO_TIMESPEC_HPP

View File

@@ -41,8 +41,8 @@
#include <pthread.h>
#include <errno.h>
#include <boost/interprocess/sync/posix/pthread_helpers.hpp>
#include <boost/interprocess/sync/posix/ptime_to_timespec.hpp>
#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
#include <boost/interprocess/sync/posix/timepoint_to_timespec.hpp>
#include <boost/interprocess/detail/timed_utils.hpp>
#include <boost/interprocess/exceptions.hpp>
#ifndef BOOST_INTERPROCESS_POSIX_TIMEOUTS
# include <boost/interprocess/detail/os_thread_functions.hpp>
@@ -65,7 +65,7 @@ class posix_recursive_mutex
void lock();
bool try_lock();
bool timed_lock(const boost::posix_time::ptime &abs_time);
template<class TimePoint> bool timed_lock(const TimePoint &abs_time);
void unlock();
private:
@@ -87,29 +87,67 @@ inline posix_recursive_mutex::~posix_recursive_mutex()
inline void posix_recursive_mutex::lock()
{
if (pthread_mutex_lock(&m_mut) != 0)
int res = pthread_mutex_lock(&m_mut);
#ifdef BOOST_INTERPROCESS_POSIX_ROBUST_MUTEXES
if (res == EOWNERDEAD)
{
//We can't inform the application and data might
//corrupted, so be safe and mark the mutex as not recoverable
//so applications can act accordingly.
pthread_mutex_unlock(&m_mut);
throw lock_exception(not_recoverable);
}
else if (res == ENOTRECOVERABLE)
throw lock_exception(not_recoverable);
#endif
if (res != 0)
throw lock_exception();
}
inline bool posix_recursive_mutex::try_lock()
{
int res = pthread_mutex_trylock(&m_mut);
#ifdef BOOST_INTERPROCESS_POSIX_ROBUST_MUTEXES
if (res == EOWNERDEAD)
{
//We can't inform the application and data might
//corrupted, so be safe and mark the mutex as not recoverable
//so applications can act accordingly.
pthread_mutex_unlock(&m_mut);
throw lock_exception(not_recoverable);
}
else if (res == ENOTRECOVERABLE)
throw lock_exception(not_recoverable);
#endif
if (!(res == 0 || res == EBUSY))
throw lock_exception();
return res == 0;
return (res == 0);
}
inline bool posix_recursive_mutex::timed_lock(const boost::posix_time::ptime &abs_time)
template<class TimePoint>
inline bool posix_recursive_mutex::timed_lock(const TimePoint &abs_time)
{
#ifdef BOOST_INTERPROCESS_POSIX_TIMEOUTS
//Posix does not support infinity absolute time so handle it here
if(abs_time == boost::posix_time::pos_infin){
if(ipcdetail::is_pos_infinity(abs_time)){
this->lock();
return true;
}
timespec ts = ptime_to_timespec(abs_time);
timespec ts = timepoint_to_timespec(abs_time);
int res = pthread_mutex_timedlock(&m_mut, &ts);
#ifdef BOOST_INTERPROCESS_POSIX_ROBUST_MUTEXES
if (res == EOWNERDEAD)
{
//We can't inform the application and data might
//corrupted, so be safe and mark the mutex as not recoverable
//so applications can act accordingly.
pthread_mutex_unlock(&m_mut);
throw lock_exception(not_recoverable);
}
else if (res == ENOTRECOVERABLE)
throw lock_exception(not_recoverable);
#endif
if (res != 0 && res != ETIMEDOUT)
throw lock_exception();
return res == 0;

View File

@@ -22,7 +22,6 @@
#include <boost/interprocess/detail/config_begin.hpp>
#include <boost/interprocess/detail/workaround.hpp>
#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
#include <boost/interprocess/sync/posix/semaphore_wrapper.hpp>
namespace boost {
@@ -51,7 +50,8 @@ class posix_semaphore
bool try_wait()
{ return semaphore_try_wait(&m_sem); }
bool timed_wait(const boost::posix_time::ptime &abs_time)
template<class TimePoint>
bool timed_wait(const TimePoint &abs_time)
{ return semaphore_timed_wait(&m_sem, abs_time); }
private:

View File

@@ -19,11 +19,11 @@
# pragma once
#endif
#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
#include <boost/interprocess/exceptions.hpp>
#include <boost/interprocess/creation_tags.hpp>
#include <boost/interprocess/detail/os_file_functions.hpp>
#include <boost/interprocess/detail/shared_dir_helpers.hpp>
#include <boost/interprocess/detail/timed_utils.hpp>
#include <boost/interprocess/permissions.hpp>
#include <fcntl.h> //O_CREAT, O_*...
@@ -40,7 +40,7 @@
#endif
#ifdef BOOST_INTERPROCESS_POSIX_TIMEOUTS
#include <boost/interprocess/sync/posix/ptime_to_timespec.hpp>
#include <boost/interprocess/sync/posix/timepoint_to_timespec.hpp>
#else
#include <boost/interprocess/detail/os_thread_functions.hpp>
#include <boost/interprocess/sync/detail/locks.hpp>
@@ -122,7 +122,7 @@ inline void semaphore_close(sem_t *handle)
inline bool semaphore_unlink(const char *semname)
{
try{
BOOST_TRY{
std::string sem_str;
#ifndef BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SEMAPHORES
add_leading_slash(semname, sem_str);
@@ -131,9 +131,9 @@ inline bool semaphore_unlink(const char *semname)
#endif
return 0 == sem_unlink(sem_str.c_str());
}
catch(...){
BOOST_CATCH(...){
return false;
}
} BOOST_CATCH_END
}
#endif //BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
@@ -212,16 +212,17 @@ struct semaphore_wrapper_try_wrapper
#endif
inline bool semaphore_timed_wait(sem_t *handle, const boost::posix_time::ptime &abs_time)
template<class TimePoint>
inline bool semaphore_timed_wait(sem_t *handle, const TimePoint &abs_time)
{
#ifdef BOOST_INTERPROCESS_POSIX_TIMEOUTS
//Posix does not support infinity absolute time so handle it here
if(abs_time == boost::posix_time::pos_infin){
if(ipcdetail::is_pos_infinity(abs_time)){
semaphore_wait(handle);
return true;
}
timespec tspec = ptime_to_timespec(abs_time);
timespec tspec = timepoint_to_timespec(abs_time);
for (;;){
int res = sem_timedwait(handle, &tspec);
if(res == 0)

View File

@@ -0,0 +1,87 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/interprocess for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTERPROCESS_DETAIL_TIMEPOINT_TO_TIMESPEC_HPP
#define BOOST_INTERPROCESS_DETAIL_TIMEPOINT_TO_TIMESPEC_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/interprocess/detail/mpl.hpp>
#include <boost/interprocess/detail/type_traits.hpp>
#include <boost/interprocess/detail/timed_utils.hpp>
namespace boost {
namespace interprocess {
namespace ipcdetail {
template<class TimePoint>
inline timespec timepoint_to_timespec ( const TimePoint &tm
, typename enable_if_ptime<TimePoint>::type * = 0)
{
typedef typename TimePoint::date_type date_type;
typedef typename TimePoint::time_duration_type time_duration_type;
const TimePoint epoch(date_type(1970,1,1));
//Avoid negative absolute times
time_duration_type duration = (tm <= epoch) ? time_duration_type(epoch - epoch)
: time_duration_type(tm - epoch);
timespec ts;
ts.tv_sec = static_cast<time_t>(duration.total_seconds());
ts.tv_nsec = static_cast<long>(duration.total_nanoseconds() % 1000000000);
return ts;
}
inline timespec timepoint_to_timespec (const ustime &tm)
{
timespec ts;
ts.tv_sec = static_cast<time_t>(tm.get_microsecs()/1000000u);
ts.tv_nsec = static_cast<long>((tm.get_microsecs()%1000000u)*1000u);
return ts;
}
template<class TimePoint>
inline timespec timepoint_to_timespec ( const TimePoint &tm
, typename enable_if_time_point<TimePoint>::type * = 0)
{
typedef typename TimePoint::duration duration_t;
duration_t d(tm.time_since_epoch());
timespec ts;
BOOST_IF_CONSTEXPR(duration_t::period::num == 1 && duration_t::period::den == 1000000000)
{
ts.tv_sec = static_cast<time_t>(d.count()/duration_t::period::den);
ts.tv_nsec = static_cast<long>(d.count()%duration_t::period::den);
}
else
{
const double factor = double(duration_t::period::num)/double(duration_t::period::den);
const double res = d.count()*factor;
ts.tv_sec = static_cast<time_t>(res);
ts.tv_nsec = static_cast<long>(res - double(ts.tv_sec));
}
return ts;
}
} //namespace ipcdetail {
} //namespace interprocess {
} //namespace boost {
#endif //ifndef BOOST_INTERPROCESS_DETAIL_TIMEPOINT_TO_TIMESPEC_HPP