-//$$CDS-header$$
+/*
+ This file is a part of libcds - Concurrent Data Structures library
-#ifndef __CDS_OS_ALLOC_ALIGNED_H
-#define __CDS_OS_ALLOC_ALIGNED_H
+ (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
+
+ Source code repo: http://github.com/khizmax/libcds/
+ Download: http://sourceforge.net/projects/libcds/files/
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef CDSLIB_OS_ALLOC_ALIGNED_H
+#define CDSLIB_OS_ALLOC_ALIGNED_H
#include <cds/details/defs.h>
#include <memory>
#include <cds/details/is_aligned.h>
-#include <cds/int_algo.h>
+#include <cds/algo/int_algo.h>
+#include <cds/details/throw_exception.h>
namespace cds {
/// OS specific wrappers
}
// construct default allocator (do nothing)
- aligned_allocator() throw()
+ aligned_allocator() CDS_NOEXCEPT
{}
/// construct by copying (do nothing)
- aligned_allocator(const aligned_allocator<T>&) throw()
+ aligned_allocator(const aligned_allocator<T>&) CDS_NOEXCEPT
{}
/// construct from a related allocator (do nothing)
template <class OTHER>
- aligned_allocator(const aligned_allocator<OTHER>&) throw()
+ aligned_allocator(const aligned_allocator<OTHER>&) CDS_NOEXCEPT
{}
/// assign from a related allocator (do nothing)
\code
sizeof(T) % nAlign == 0
\endcode
+
+ The function, like operator \p new does not return \p nullptr.
+ In no memory situation the function throws \p std::bad_alloc exception.
*/
pointer allocate( size_type nAlign, size_type nCount )
{
- assert( cds::beans::is_power2( nAlign ) );
- pointer p = reinterpret_cast<T *>( cds::OS::aligned_malloc( sizeof(T) * nCount, nAlign ) );
+ assert( cds::beans::is_power2( nAlign ));
+ pointer p = reinterpret_cast<T *>( cds::OS::aligned_malloc( sizeof(T) * nCount, nAlign ));
+ if ( !p )
+ CDS_THROW_EXCEPTION( std::bad_alloc());
assert( cds::details::is_aligned( p, nAlign ));
return p;
}
*/
pointer allocate(size_type nAlign, size_type nCount, const void *)
{
- return ( allocate( nAlign, nCount ) );
+ return ( allocate( nAlign, nCount ));
}
/// construct object at \p ptr with value \p val
}
/// estimate maximum array size
- size_type max_size() const throw()
+ size_type max_size() const CDS_NOEXCEPT
{
prototype a;
return a.max_size();
} // namespace OS
} // namespace cds
-#endif // #ifndef __CDS_OS_ALLOC_ALIGNED_H
+#endif // #ifndef CDSLIB_OS_ALLOC_ALIGNED_H