mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-10-22 04:11:41 +02:00
Compare commits
9 Commits
feature/ow
...
feature/st
Author | SHA1 | Date | |
---|---|---|---|
|
bc677e9098 | ||
|
688cfed63e | ||
|
c63dc266b9 | ||
|
6c181a0707 | ||
|
4047290b85 | ||
|
dc6c76d7e9 | ||
|
5a18ffdc56 | ||
|
09fdd5ebfd | ||
|
911874e139 |
27
.travis.yml
27
.travis.yml
@@ -37,6 +37,10 @@ matrix:
|
||||
compiler: g++
|
||||
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03,11,14
|
||||
|
||||
- os: freebsd
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,17,2a
|
||||
|
||||
- os: linux
|
||||
compiler: g++-4.4
|
||||
env: TOOLSET=gcc COMPILER=g++-4.4 CXXSTD=98,0x
|
||||
@@ -156,6 +160,28 @@ matrix:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
dist: bionic
|
||||
compiler: g++-10
|
||||
env: TOOLSET=gcc COMPILER=g++-10 CXXSTD=03,11,14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-10
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
dist: bionic
|
||||
compiler: g++-10
|
||||
env: TOOLSET=gcc COMPILER=g++-10 CXXSTD=17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-10
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-7
|
||||
env: UBSAN=1 TOOLSET=gcc COMPILER=g++-7 CXXSTD=03,11,14,17 UBSAN_OPTIONS=print_stacktrace=1 LINKFLAGS=-fuse-ld=gold
|
||||
@@ -399,6 +425,7 @@ install:
|
||||
- git submodule init tools/boost_install
|
||||
- git submodule init tools/cmake
|
||||
- git submodule init libs/preprocessor
|
||||
- git submodule init libs/bind
|
||||
- git submodule update # no --jobs 3 on non-amd64
|
||||
- cp -r $TRAVIS_BUILD_DIR/* libs/smart_ptr
|
||||
- ./bootstrap.sh
|
||||
|
@@ -70,6 +70,7 @@ install:
|
||||
- git submodule init tools/build
|
||||
- git submodule init libs/headers
|
||||
- git submodule init tools/boost_install
|
||||
- git submodule init libs/bind
|
||||
- git submodule update --jobs 3
|
||||
- xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\smart_ptr\
|
||||
- cmd /c bootstrap
|
||||
|
@@ -21,168 +21,6 @@
|
||||
// template<class F> int lw_thread_create( lw_thread_t & th, F f );
|
||||
// void lw_thread_join( lw_thread_t th );
|
||||
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <memory>
|
||||
#include <cerrno>
|
||||
|
||||
#if defined( BOOST_HAS_PTHREADS )
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
typedef ::pthread_t lw_thread_t;
|
||||
|
||||
inline int lw_thread_create_( lw_thread_t* thread, const pthread_attr_t* attr, void* (*start_routine)( void* ), void* arg )
|
||||
{
|
||||
return ::pthread_create( thread, attr, start_routine, arg );
|
||||
}
|
||||
|
||||
inline void lw_thread_join( lw_thread_t th )
|
||||
{
|
||||
::pthread_join( th, 0 );
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace boost
|
||||
|
||||
#else // defined( BOOST_HAS_PTHREADS )
|
||||
|
||||
#include <windows.h>
|
||||
#include <process.h>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
typedef HANDLE lw_thread_t;
|
||||
|
||||
inline int lw_thread_create_( lw_thread_t * thread, void const *, unsigned (__stdcall * start_routine) (void*), void* arg )
|
||||
{
|
||||
HANDLE h = (HANDLE)_beginthreadex( 0, 0, start_routine, arg, 0, 0 );
|
||||
|
||||
if( h != 0 )
|
||||
{
|
||||
*thread = h;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EAGAIN;
|
||||
}
|
||||
}
|
||||
|
||||
inline void lw_thread_join( lw_thread_t thread )
|
||||
{
|
||||
::WaitForSingleObject( thread, INFINITE );
|
||||
::CloseHandle( thread );
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace boost
|
||||
|
||||
#endif // defined( BOOST_HAS_PTHREADS )
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class lw_abstract_thread
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~lw_abstract_thread() {}
|
||||
virtual void run() = 0;
|
||||
};
|
||||
|
||||
#if defined( BOOST_HAS_PTHREADS )
|
||||
|
||||
extern "C" void * lw_thread_routine( void * pv )
|
||||
{
|
||||
#if defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
|
||||
std::auto_ptr<lw_abstract_thread> pt( static_cast<lw_abstract_thread *>( pv ) );
|
||||
|
||||
#else
|
||||
|
||||
std::unique_ptr<lw_abstract_thread> pt( static_cast<lw_abstract_thread *>( pv ) );
|
||||
|
||||
#endif
|
||||
|
||||
pt->run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
unsigned __stdcall lw_thread_routine( void * pv )
|
||||
{
|
||||
#if defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
|
||||
std::auto_ptr<lw_abstract_thread> pt( static_cast<lw_abstract_thread *>( pv ) );
|
||||
|
||||
#else
|
||||
|
||||
std::unique_ptr<lw_abstract_thread> pt( static_cast<lw_abstract_thread *>( pv ) );
|
||||
|
||||
#endif
|
||||
|
||||
pt->run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template<class F> class lw_thread_impl: public lw_abstract_thread
|
||||
{
|
||||
public:
|
||||
|
||||
explicit lw_thread_impl( F f ): f_( f )
|
||||
{
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
f_();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
F f_;
|
||||
};
|
||||
|
||||
template<class F> int lw_thread_create( lw_thread_t & th, F f )
|
||||
{
|
||||
#if defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
|
||||
std::auto_ptr<lw_abstract_thread> p( new lw_thread_impl<F>( f ) );
|
||||
|
||||
#else
|
||||
|
||||
std::unique_ptr<lw_abstract_thread> p( new lw_thread_impl<F>( f ) );
|
||||
|
||||
#endif
|
||||
|
||||
int r = lw_thread_create_( &th, 0, lw_thread_routine, p.get() );
|
||||
|
||||
if( r == 0 )
|
||||
{
|
||||
p.release();
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace boost
|
||||
#include <boost/smart_ptr/detail/lightweight_thread.hpp>
|
||||
|
||||
#endif // #ifndef BOOST_DETAIL_LIGHTWEIGHT_THREAD_HPP_INCLUDED
|
||||
|
@@ -23,6 +23,13 @@
|
||||
# include <bits/atomicity.h>
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using libstdc++ atomic_count")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -13,6 +13,13 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using g++/x86 atomic_count")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -15,6 +15,13 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using single-threaded, non-atomic atomic_count")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -14,6 +14,13 @@
|
||||
#include <boost/assert.hpp>
|
||||
#include <pthread.h>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using pthread_mutex atomic_count")
|
||||
|
||||
#endif
|
||||
|
||||
//
|
||||
// The generic pthread_mutex-based implementation sometimes leads to
|
||||
// inefficiencies. Example: a class with two atomic_count members
|
||||
|
@@ -15,6 +15,13 @@
|
||||
|
||||
#include <atomic.h>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using Solaris atomic_count")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -13,6 +13,13 @@
|
||||
|
||||
#include <boost/smart_ptr/detail/spinlock_pool.hpp>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using spinlock-based atomic_count")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -16,6 +16,13 @@
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using std::atomic atomic_count")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -19,6 +19,13 @@
|
||||
# include <ia64intrin.h>
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using __sync atomic_count")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -19,6 +19,13 @@
|
||||
|
||||
#include <boost/smart_ptr/detail/sp_interlocked.hpp>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using Win32 atomic_count")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
188
include/boost/smart_ptr/detail/lightweight_thread.hpp
Normal file
188
include/boost/smart_ptr/detail/lightweight_thread.hpp
Normal file
@@ -0,0 +1,188 @@
|
||||
#ifndef BOOST_SMART_PTR_DETAIL_LIGHTWEIGHT_THREAD_HPP_INCLUDED
|
||||
#define BOOST_SMART_PTR_DETAIL_LIGHTWEIGHT_THREAD_HPP_INCLUDED
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
// boost/detail/lightweight_thread.hpp
|
||||
//
|
||||
// Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
|
||||
// Copyright (c) 2008, 2018 Peter Dimov
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//
|
||||
// typedef /*...*/ lw_thread_t; // as pthread_t
|
||||
// template<class F> int lw_thread_create( lw_thread_t & th, F f );
|
||||
// void lw_thread_join( lw_thread_t th );
|
||||
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <memory>
|
||||
#include <cerrno>
|
||||
|
||||
#if defined( BOOST_HAS_PTHREADS )
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
typedef ::pthread_t lw_thread_t;
|
||||
|
||||
inline int lw_thread_create_( lw_thread_t* thread, const pthread_attr_t* attr, void* (*start_routine)( void* ), void* arg )
|
||||
{
|
||||
return ::pthread_create( thread, attr, start_routine, arg );
|
||||
}
|
||||
|
||||
inline void lw_thread_join( lw_thread_t th )
|
||||
{
|
||||
::pthread_join( th, 0 );
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace boost
|
||||
|
||||
#else // defined( BOOST_HAS_PTHREADS )
|
||||
|
||||
#include <windows.h>
|
||||
#include <process.h>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
typedef HANDLE lw_thread_t;
|
||||
|
||||
inline int lw_thread_create_( lw_thread_t * thread, void const *, unsigned (__stdcall * start_routine) (void*), void* arg )
|
||||
{
|
||||
HANDLE h = (HANDLE)_beginthreadex( 0, 0, start_routine, arg, 0, 0 );
|
||||
|
||||
if( h != 0 )
|
||||
{
|
||||
*thread = h;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EAGAIN;
|
||||
}
|
||||
}
|
||||
|
||||
inline void lw_thread_join( lw_thread_t thread )
|
||||
{
|
||||
::WaitForSingleObject( thread, INFINITE );
|
||||
::CloseHandle( thread );
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace boost
|
||||
|
||||
#endif // defined( BOOST_HAS_PTHREADS )
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class lw_abstract_thread
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~lw_abstract_thread() {}
|
||||
virtual void run() = 0;
|
||||
};
|
||||
|
||||
#if defined( BOOST_HAS_PTHREADS )
|
||||
|
||||
extern "C" void * lw_thread_routine( void * pv )
|
||||
{
|
||||
#if defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
|
||||
std::auto_ptr<lw_abstract_thread> pt( static_cast<lw_abstract_thread *>( pv ) );
|
||||
|
||||
#else
|
||||
|
||||
std::unique_ptr<lw_abstract_thread> pt( static_cast<lw_abstract_thread *>( pv ) );
|
||||
|
||||
#endif
|
||||
|
||||
pt->run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
unsigned __stdcall lw_thread_routine( void * pv )
|
||||
{
|
||||
#if defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
|
||||
std::auto_ptr<lw_abstract_thread> pt( static_cast<lw_abstract_thread *>( pv ) );
|
||||
|
||||
#else
|
||||
|
||||
std::unique_ptr<lw_abstract_thread> pt( static_cast<lw_abstract_thread *>( pv ) );
|
||||
|
||||
#endif
|
||||
|
||||
pt->run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template<class F> class lw_thread_impl: public lw_abstract_thread
|
||||
{
|
||||
public:
|
||||
|
||||
explicit lw_thread_impl( F f ): f_( f )
|
||||
{
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
f_();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
F f_;
|
||||
};
|
||||
|
||||
template<class F> int lw_thread_create( lw_thread_t & th, F f )
|
||||
{
|
||||
#if defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
|
||||
std::auto_ptr<lw_abstract_thread> p( new lw_thread_impl<F>( f ) );
|
||||
|
||||
#else
|
||||
|
||||
std::unique_ptr<lw_abstract_thread> p( new lw_thread_impl<F>( f ) );
|
||||
|
||||
#endif
|
||||
|
||||
int r = lw_thread_create_( &th, 0, lw_thread_routine, p.get() );
|
||||
|
||||
if( r == 0 )
|
||||
{
|
||||
p.release();
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_DETAIL_LIGHTWEIGHT_THREAD_HPP_INCLUDED
|
@@ -19,6 +19,13 @@
|
||||
#include <boost/config.hpp>
|
||||
#include <machine/sys/inline.h>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using HP aCC++/HP-UX/IA64 sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -25,6 +25,13 @@
|
||||
#include <builtins.h>
|
||||
#include <sys/atomic_op.h>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using AIX sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -20,6 +20,13 @@
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using Clang/C11 sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -27,6 +27,13 @@
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using CodeWarrior/PowerPC sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -28,6 +28,13 @@
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using CodeWarrior/x86 sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -19,6 +19,13 @@
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using g++/IA64 sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -23,6 +23,13 @@
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using g++/MIPS sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -27,6 +27,13 @@
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using g++/PowerPC sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -23,6 +23,13 @@
|
||||
#include <boost/config.hpp>
|
||||
#include <inttypes.h> // int32_t
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using g++/Sparc sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -27,6 +27,13 @@
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using g++/x86 sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -23,6 +23,13 @@
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using single-threaded, non-atomic sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -24,6 +24,13 @@
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <pthread.h>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using pthread_mutex sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -6,7 +6,7 @@
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
// detail/sp_counted_base_gcc_sparc.hpp - g++ on Sparc V8+
|
||||
// detail/sp_counted_base_gcc_snc_ps3.hpp - PS3 Cell
|
||||
//
|
||||
// Copyright (c) 2006 Piotr Wyderski
|
||||
// Copyright (c) 2006 Tomas Puverle
|
||||
@@ -23,6 +23,13 @@
|
||||
#include <boost/config.hpp>
|
||||
#include <inttypes.h> // uint32_t
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using PS3 sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -24,6 +24,13 @@
|
||||
#include <boost/config.hpp>
|
||||
#include <atomic.h>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using Solaris sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -22,6 +22,13 @@
|
||||
#include <boost/smart_ptr/detail/spinlock_pool.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using spinlock-based sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -21,6 +21,13 @@
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using std::atomic sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -23,6 +23,13 @@
|
||||
# include <ia64intrin.h>
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using __sync sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -24,6 +24,13 @@
|
||||
#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using xlC/PowerPC sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
extern "builtin" void __lwsync(void);
|
||||
extern "builtin" void __isync(void);
|
||||
extern "builtin" int __fetch_and_add(volatile int* addr, int val);
|
||||
|
@@ -29,6 +29,13 @@
|
||||
#include <boost/config/workaround.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using Win32 sp_counted_base")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -11,6 +11,13 @@
|
||||
|
||||
#include <boost/smart_ptr/detail/yield_k.hpp>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using g++/ARM spinlock")
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_7S__)
|
||||
|
||||
# define BOOST_SP_ARM_BARRIER "dmb"
|
||||
|
@@ -17,6 +17,13 @@
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using single-threaded spinlock emulation")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -17,6 +17,13 @@
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using pthread_mutex spinlock emulation")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -19,6 +19,13 @@
|
||||
#include <boost/config.hpp>
|
||||
#include <atomic>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using std::atomic spinlock")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -21,6 +21,13 @@
|
||||
# include <ia64intrin.h>
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using __sync spinlock")
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
@@ -18,6 +18,13 @@
|
||||
#include <boost/smart_ptr/detail/sp_interlocked.hpp>
|
||||
#include <boost/smart_ptr/detail/yield_k.hpp>
|
||||
|
||||
#if defined(BOOST_SP_REPORT_IMPLEMENTATION)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("Using Win32 spinlock")
|
||||
|
||||
#endif
|
||||
|
||||
// BOOST_COMPILER_FENCE
|
||||
|
||||
#if defined(__INTEL_COMPILER)
|
||||
|
@@ -385,4 +385,23 @@ template< class T > std::size_t hash_value( boost::intrusive_ptr<T> const & p )
|
||||
|
||||
} // namespace boost
|
||||
|
||||
// std::hash
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
template<class T> struct hash< ::boost::intrusive_ptr<T> >
|
||||
{
|
||||
std::size_t operator()( ::boost::intrusive_ptr<T> const & p ) const BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return std::hash< T* >()( p.get() );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif // #if !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_INTRUSIVE_PTR_HPP_INCLUDED
|
||||
|
@@ -688,4 +688,23 @@ template< class T > std::size_t hash_value( local_shared_ptr<T> const & p ) BOOS
|
||||
|
||||
} // namespace boost
|
||||
|
||||
// std::hash
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
template<class T> struct hash< ::boost::local_shared_ptr<T> >
|
||||
{
|
||||
std::size_t operator()( ::boost::local_shared_ptr<T> const & p ) const BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return std::hash< typename ::boost::local_shared_ptr<T>::element_type* >()( p.get() );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif // #if !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_LOCAL_SHARED_PTR_HPP_INCLUDED
|
||||
|
@@ -1165,6 +1165,25 @@ template< class T > std::size_t hash_value( boost::shared_ptr<T> const & p ) BOO
|
||||
|
||||
} // namespace boost
|
||||
|
||||
// std::hash
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
template<class T> struct hash< ::boost::shared_ptr<T> >
|
||||
{
|
||||
std::size_t operator()( ::boost::shared_ptr<T> const & p ) const BOOST_SP_NOEXCEPT
|
||||
{
|
||||
return std::hash< typename ::boost::shared_ptr<T>::element_type* >()( p.get() );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif // #if !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
||||
|
||||
#include <boost/smart_ptr/detail/local_sp_deleter.hpp>
|
||||
|
||||
namespace boost
|
||||
|
@@ -10,6 +10,6 @@ if(HAVE_BOOST_TEST)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads)
|
||||
|
||||
boost_test_jamfile(FILE Jamfile LINK_LIBRARIES Boost::smart_ptr Boost::core Boost::align Boost::atomic Boost::container_hash Threads::Threads)
|
||||
boost_test_jamfile(FILE Jamfile LINK_LIBRARIES Boost::smart_ptr Boost::core Boost::align Boost::atomic Boost::container_hash Boost::bind Threads::Threads)
|
||||
|
||||
endif()
|
||||
|
22
test/Jamfile
22
test/Jamfile
@@ -376,3 +376,25 @@ run owner_equal_to_test.cpp ;
|
||||
run owner_equal_to_test2.cpp ;
|
||||
|
||||
run owner_less_test2.cpp ;
|
||||
|
||||
run ip_hash_test2.cpp ;
|
||||
run sp_hash_test4.cpp ;
|
||||
run lsp_hash_test.cpp ;
|
||||
run lsp_hash_test2.cpp ;
|
||||
|
||||
run atomic_count_mt_test.cpp
|
||||
: : : <threading>multi ;
|
||||
|
||||
run spinlock_mt_test.cpp
|
||||
: : : <threading>multi ;
|
||||
|
||||
run spinlock_pool_mt_test.cpp
|
||||
: : : <threading>multi ;
|
||||
|
||||
run shared_ptr_mt_test.cpp
|
||||
: : : <threading>multi ;
|
||||
|
||||
run weak_ptr_mt_test.cpp
|
||||
: : : <threading>multi ;
|
||||
|
||||
compile sp_report_implementation.cpp ;
|
||||
|
40
test/atomic_count_mt_test.cpp
Normal file
40
test/atomic_count_mt_test.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright 2018, 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/smart_ptr/detail/atomic_count.hpp>
|
||||
#include <boost/smart_ptr/detail/lightweight_thread.hpp>
|
||||
#include <boost/bind/bind.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
static boost::detail::atomic_count count( 0 );
|
||||
|
||||
void f( int n )
|
||||
{
|
||||
for( int i = 0; i < n; ++i )
|
||||
{
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int const N = 100000; // iterations
|
||||
int const M = 8; // threads
|
||||
|
||||
boost::detail::lw_thread_t th[ M ] = {};
|
||||
|
||||
for( int i = 0; i < M; ++i )
|
||||
{
|
||||
boost::detail::lw_thread_create( th[ i ], boost::bind( f, N ) );
|
||||
}
|
||||
|
||||
for( int i = 0; i < M; ++i )
|
||||
{
|
||||
boost::detail::lw_thread_join( th[ i ] );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( count, N * M );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
67
test/ip_hash_test2.cpp
Normal file
67
test/ip_hash_test2.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
// Copyright 2011, 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/intrusive_ptr.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <functional>
|
||||
|
||||
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
||||
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
class base
|
||||
{
|
||||
private:
|
||||
|
||||
int use_count_;
|
||||
|
||||
base(base const &);
|
||||
base & operator=(base const &);
|
||||
|
||||
protected:
|
||||
|
||||
base(): use_count_(0)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~base()
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
long use_count() const
|
||||
{
|
||||
return use_count_;
|
||||
}
|
||||
|
||||
inline friend void intrusive_ptr_add_ref(base * p)
|
||||
{
|
||||
++p->use_count_;
|
||||
}
|
||||
|
||||
inline friend void intrusive_ptr_release(base * p)
|
||||
{
|
||||
if(--p->use_count_ == 0) delete p;
|
||||
}
|
||||
};
|
||||
|
||||
struct X: public base
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::intrusive_ptr<X> p1, p2( new X );
|
||||
|
||||
BOOST_TEST_EQ( std::hash< boost::intrusive_ptr<X> >()( p1 ), std::hash< X* >()( p1.get() ) );
|
||||
BOOST_TEST_EQ( std::hash< boost::intrusive_ptr<X> >()( p2 ), std::hash< X* >()( p2.get() ) );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif // #if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
66
test/lsp_hash_test.cpp
Normal file
66
test/lsp_hash_test.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
// Copyright 2011, 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/smart_ptr/local_shared_ptr.hpp>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::hash< boost::local_shared_ptr<int> > hasher;
|
||||
|
||||
boost::local_shared_ptr<int> p1, p2( p1 ), p3( new int ), p4( p3 ), p5( new int );
|
||||
|
||||
BOOST_TEST_EQ( p1, p2 );
|
||||
BOOST_TEST_EQ( hasher( p1 ), hasher( p2 ) );
|
||||
|
||||
BOOST_TEST_NE( p1, p3 );
|
||||
BOOST_TEST_NE( hasher( p1 ), hasher( p3 ) );
|
||||
|
||||
BOOST_TEST_EQ( p3, p4 );
|
||||
BOOST_TEST_EQ( hasher( p3 ), hasher( p4 ) );
|
||||
|
||||
BOOST_TEST_NE( p3, p5 );
|
||||
BOOST_TEST_NE( hasher( p3 ), hasher( p5 ) );
|
||||
}
|
||||
|
||||
{
|
||||
boost::hash< boost::local_shared_ptr<int[]> > hasher;
|
||||
|
||||
boost::local_shared_ptr<int[]> p1, p2( p1 ), p3( new int[1] ), p4( p3 ), p5( new int[1] );
|
||||
|
||||
BOOST_TEST_EQ( p1, p2 );
|
||||
BOOST_TEST_EQ( hasher( p1 ), hasher( p2 ) );
|
||||
|
||||
BOOST_TEST_NE( p1, p3 );
|
||||
BOOST_TEST_NE( hasher( p1 ), hasher( p3 ) );
|
||||
|
||||
BOOST_TEST_EQ( p3, p4 );
|
||||
BOOST_TEST_EQ( hasher( p3 ), hasher( p4 ) );
|
||||
|
||||
BOOST_TEST_NE( p3, p5 );
|
||||
BOOST_TEST_NE( hasher( p3 ), hasher( p5 ) );
|
||||
}
|
||||
|
||||
{
|
||||
boost::hash< boost::local_shared_ptr<int[1]> > hasher;
|
||||
|
||||
boost::local_shared_ptr<int[1]> p1, p2( p1 ), p3( new int[1] ), p4( p3 ), p5( new int[1] );
|
||||
|
||||
BOOST_TEST_EQ( p1, p2 );
|
||||
BOOST_TEST_EQ( hasher( p1 ), hasher( p2 ) );
|
||||
|
||||
BOOST_TEST_NE( p1, p3 );
|
||||
BOOST_TEST_NE( hasher( p1 ), hasher( p3 ) );
|
||||
|
||||
BOOST_TEST_EQ( p3, p4 );
|
||||
BOOST_TEST_EQ( hasher( p3 ), hasher( p4 ) );
|
||||
|
||||
BOOST_TEST_NE( p3, p5 );
|
||||
BOOST_TEST_NE( hasher( p3 ), hasher( p5 ) );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
42
test/lsp_hash_test2.cpp
Normal file
42
test/lsp_hash_test2.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright 2011, 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/smart_ptr/local_shared_ptr.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <functional>
|
||||
|
||||
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
||||
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::local_shared_ptr<int> p1, p2( new int );
|
||||
|
||||
BOOST_TEST_EQ( std::hash< boost::local_shared_ptr<int> >()( p1 ), std::hash< int* >()( p1.get() ) );
|
||||
BOOST_TEST_EQ( std::hash< boost::local_shared_ptr<int> >()( p2 ), std::hash< int* >()( p2.get() ) );
|
||||
}
|
||||
|
||||
{
|
||||
boost::local_shared_ptr<int[]> p1, p2( new int[1] );
|
||||
|
||||
BOOST_TEST_EQ( std::hash< boost::local_shared_ptr<int[]> >()( p1 ), std::hash< int* >()( p1.get() ) );
|
||||
BOOST_TEST_EQ( std::hash< boost::local_shared_ptr<int[]> >()( p2 ), std::hash< int* >()( p2.get() ) );
|
||||
}
|
||||
|
||||
{
|
||||
boost::local_shared_ptr<int[1]> p1, p2( new int[1] );
|
||||
|
||||
BOOST_TEST_EQ( std::hash< boost::local_shared_ptr<int[1]> >()( p1 ), std::hash< int* >()( p1.get() ) );
|
||||
BOOST_TEST_EQ( std::hash< boost::local_shared_ptr<int[1]> >()( p2 ), std::hash< int* >()( p2.get() ) );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif // #if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
46
test/shared_ptr_mt_test.cpp
Normal file
46
test/shared_ptr_mt_test.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright 2018, 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/smart_ptr/detail/lightweight_thread.hpp>
|
||||
#include <boost/bind/bind.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
static boost::shared_ptr<int> sp( new int );
|
||||
|
||||
void f( int n )
|
||||
{
|
||||
for( int i = 0; i < n; ++i )
|
||||
{
|
||||
boost::shared_ptr<int> p1( sp );
|
||||
boost::weak_ptr<int> p2( p1 );
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int const N = 100000; // iterations
|
||||
int const M = 8; // threads
|
||||
|
||||
boost::detail::lw_thread_t th[ M ] = {};
|
||||
|
||||
for( int i = 0; i < M; ++i )
|
||||
{
|
||||
boost::detail::lw_thread_create( th[ i ], boost::bind( f, N ) );
|
||||
}
|
||||
|
||||
for( int i = 0; i < M; ++i )
|
||||
{
|
||||
boost::detail::lw_thread_join( th[ i ] );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( sp.use_count(), 1 );
|
||||
|
||||
sp.reset();
|
||||
|
||||
BOOST_TEST_EQ( sp.use_count(), 0 );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
42
test/sp_hash_test4.cpp
Normal file
42
test/sp_hash_test4.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright 2011, 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <functional>
|
||||
|
||||
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
||||
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::shared_ptr<int> p1, p2( new int );
|
||||
|
||||
BOOST_TEST_EQ( std::hash< boost::shared_ptr<int> >()( p1 ), std::hash< int* >()( p1.get() ) );
|
||||
BOOST_TEST_EQ( std::hash< boost::shared_ptr<int> >()( p2 ), std::hash< int* >()( p2.get() ) );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int[]> p1, p2( new int[1] );
|
||||
|
||||
BOOST_TEST_EQ( std::hash< boost::shared_ptr<int[]> >()( p1 ), std::hash< int* >()( p1.get() ) );
|
||||
BOOST_TEST_EQ( std::hash< boost::shared_ptr<int[]> >()( p2 ), std::hash< int* >()( p2.get() ) );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<int[1]> p1, p2( new int[1] );
|
||||
|
||||
BOOST_TEST_EQ( std::hash< boost::shared_ptr<int[1]> >()( p1 ), std::hash< int* >()( p1.get() ) );
|
||||
BOOST_TEST_EQ( std::hash< boost::shared_ptr<int[1]> >()( p2 ), std::hash< int* >()( p2.get() ) );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif // #if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
12
test/sp_report_implementation.cpp
Normal file
12
test/sp_report_implementation.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#define BOOST_SP_REPORT_IMPLEMENTATION
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/smart_ptr/detail/spinlock.hpp>
|
||||
#include <boost/smart_ptr/detail/atomic_count.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
42
test/spinlock_mt_test.cpp
Normal file
42
test/spinlock_mt_test.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright 2018, 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/smart_ptr/detail/spinlock.hpp>
|
||||
#include <boost/smart_ptr/detail/lightweight_thread.hpp>
|
||||
#include <boost/bind/bind.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
static int count = 0;
|
||||
static boost::detail::spinlock sp = BOOST_DETAIL_SPINLOCK_INIT;
|
||||
|
||||
void f( int n )
|
||||
{
|
||||
for( int i = 0; i < n; ++i )
|
||||
{
|
||||
boost::detail::spinlock::scoped_lock lock( sp );
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int const N = 100000; // iterations
|
||||
int const M = 8; // threads
|
||||
|
||||
boost::detail::lw_thread_t th[ M ] = {};
|
||||
|
||||
for( int i = 0; i < M; ++i )
|
||||
{
|
||||
boost::detail::lw_thread_create( th[ i ], boost::bind( f, N ) );
|
||||
}
|
||||
|
||||
for( int i = 0; i < M; ++i )
|
||||
{
|
||||
boost::detail::lw_thread_join( th[ i ] );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( count, N * M );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
41
test/spinlock_pool_mt_test.cpp
Normal file
41
test/spinlock_pool_mt_test.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright 2018, 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/smart_ptr/detail/spinlock_pool.hpp>
|
||||
#include <boost/smart_ptr/detail/lightweight_thread.hpp>
|
||||
#include <boost/bind/bind.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
static int count = 0;
|
||||
|
||||
void f( int n )
|
||||
{
|
||||
for( int i = 0; i < n; ++i )
|
||||
{
|
||||
boost::detail::spinlock_pool<0>::scoped_lock lock( &count );
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int const N = 100000; // iterations
|
||||
int const M = 8; // threads
|
||||
|
||||
boost::detail::lw_thread_t th[ M ] = {};
|
||||
|
||||
for( int i = 0; i < M; ++i )
|
||||
{
|
||||
boost::detail::lw_thread_create( th[ i ], boost::bind( f, N ) );
|
||||
}
|
||||
|
||||
for( int i = 0; i < M; ++i )
|
||||
{
|
||||
boost::detail::lw_thread_join( th[ i ] );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( count, N * M );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
74
test/weak_ptr_mt_test.cpp
Normal file
74
test/weak_ptr_mt_test.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
// Copyright 2018, 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/smart_ptr/detail/lightweight_thread.hpp>
|
||||
#include <boost/bind/bind.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
static boost::shared_ptr<int> sp( new int );
|
||||
static boost::weak_ptr<int> wp( sp );
|
||||
|
||||
void f1( int n )
|
||||
{
|
||||
for( int i = 0; i < n; ++i )
|
||||
{
|
||||
boost::weak_ptr<int> p1( wp );
|
||||
|
||||
BOOST_TEST( !wp.expired() );
|
||||
BOOST_TEST( wp.lock() != 0 );
|
||||
}
|
||||
}
|
||||
|
||||
void f2( int n )
|
||||
{
|
||||
for( int i = 0; i < n; ++i )
|
||||
{
|
||||
boost::weak_ptr<int> p1( wp );
|
||||
|
||||
BOOST_TEST( wp.expired() );
|
||||
BOOST_TEST( wp.lock() == 0 );
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int const N = 100000; // iterations
|
||||
int const M = 8; // threads
|
||||
|
||||
boost::detail::lw_thread_t th[ M ] = {};
|
||||
|
||||
for( int i = 0; i < M; ++i )
|
||||
{
|
||||
boost::detail::lw_thread_create( th[ i ], boost::bind( f1, N ) );
|
||||
}
|
||||
|
||||
for( int i = 0; i < M; ++i )
|
||||
{
|
||||
boost::detail::lw_thread_join( th[ i ] );
|
||||
}
|
||||
|
||||
BOOST_TEST_EQ( sp.use_count(), 1 );
|
||||
BOOST_TEST_EQ( wp.use_count(), 1 );
|
||||
|
||||
sp.reset();
|
||||
|
||||
BOOST_TEST_EQ( sp.use_count(), 0 );
|
||||
BOOST_TEST_EQ( wp.use_count(), 0 );
|
||||
|
||||
for( int i = 0; i < M; ++i )
|
||||
{
|
||||
boost::detail::lw_thread_create( th[ i ], boost::bind( f2, N ) );
|
||||
}
|
||||
|
||||
for( int i = 0; i < M; ++i )
|
||||
{
|
||||
boost::detail::lw_thread_join( th[ i ] );
|
||||
}
|
||||
|
||||
wp.reset();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user