// -*- C++ -*-
-// Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2007-2014 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the terms
#ifndef _GLIBCXX_PARALLEL_BASE_H
#define _GLIBCXX_PARALLEL_BASE_H 1
-#include <functional>
+#include <bits/c++config.h>
+#include <bits/stl_function.h>
#include <omp.h>
#include <parallel/features.h>
#include <parallel/basic_iterator.h>
#include <parallel/parallel.h>
-
// Parallel mode namespaces.
/**
* @namespace std::__parallel
* @brief GNU parallel code, replaces standard behavior with parallel behavior.
*/
-namespace std
+namespace std _GLIBCXX_VISIBILITY(default)
{
namespace __parallel { }
}
{
// Import whatever is the serial version.
#ifdef _GLIBCXX_PARALLEL
- using namespace std::__norm;
+ using namespace std::_GLIBCXX_STD_A;
#else
using namespace std;
#endif
// the OpenMP runtime unless the parallel mode is actually invoked
// and active, which imples that the OpenMP runtime is actually
// going to be linked in.
- inline int
+ inline _ThreadIndex
__get_max_threads()
{
- int __i = omp_get_max_threads();
+ _ThreadIndex __i = omp_get_max_threads();
return __i > 1 ? __i : 1;
}
* @param __b Second integer, to be encoded in the least-significant
* @c _CASable_bits/2 bits.
* @return value encoding @c __a and @c __b.
- * @see decode2
+ * @see __decode2
*/
inline _CASable
__encode2(int __a, int __b) //must all be non-negative, actually
* @see __encode2
*/
inline void
- decode2(_CASable __x, int& __a, int& __b)
+ __decode2(_CASable __x, int& __a, int& __b)
{
__a = (int)((__x >> (_CASable_bits / 2)) & _CASable_mask);
__b = (int)((__x >> 0 ) & _CASable_mask);
/** @brief Equivalent to std::min. */
template<typename _Tp>
- const _Tp&
+ inline const _Tp&
min(const _Tp& __a, const _Tp& __b)
{ return (__a < __b) ? __a : __b; }
/** @brief Equivalent to std::max. */
template<typename _Tp>
- const _Tp&
+ inline const _Tp&
max(const _Tp& __a, const _Tp& __b)
{ return (__a > __b) ? __a : __b; }
};
- /** @brief Similar to std::binder1st,
+ /** @brief Similar to std::unary_negate,
* but giving the argument types explicitly. */
template<typename _Predicate, typename argument_type>
class __unary_negate
*/
template<typename _Operation, typename _FirstArgumentType,
typename _SecondArgumentType, typename _ResultType>
- class binder2nd
+ class __binder2nd
: public std::unary_function<_FirstArgumentType, _ResultType>
{
protected:
_SecondArgumentType _M_value;
public:
- binder2nd(const _Operation& __x, const _SecondArgumentType& __y)
+ __binder2nd(const _Operation& __x, const _SecondArgumentType& __y)
: _M_op(__x), _M_value(__y) { }
_ResultType
// Partial specialization for one type. Same as std::less.
template<typename _Tp>
- struct _Less<_Tp, _Tp> : public std::binary_function<_Tp, _Tp, bool>
- {
- bool
- operator()(const _Tp& __x, const _Tp& __y) const
- { return __x < __y; }
- };
-
+ struct _Less<_Tp, _Tp>
+ : public std::less<_Tp> { };
/** @brief Similar to std::plus, but allows two different types. */
- template<typename _Tp1, typename _Tp2>
- struct _Plus : public std::binary_function<_Tp1, _Tp2, _Tp1>
+ template<typename _Tp1, typename _Tp2, typename _Result
+ = __typeof__(*static_cast<_Tp1*>(0)
+ + *static_cast<_Tp2*>(0))>
+ struct _Plus : public std::binary_function<_Tp1, _Tp2, _Result>
{
- typedef __typeof__(*static_cast<_Tp1*>(NULL)
- + *static_cast<_Tp2*>(NULL)) __result;
-
- __result
+ _Result
operator()(const _Tp1& __x, const _Tp2& __y) const
{ return __x + __y; }
};
// Partial specialization for one type. Same as std::plus.
template<typename _Tp>
- struct _Plus<_Tp, _Tp> : public std::binary_function<_Tp, _Tp, _Tp>
- {
- typedef __typeof__(*static_cast<_Tp*>(NULL)
- + *static_cast<_Tp*>(NULL)) __result;
-
- __result
- operator()(const _Tp& __x, const _Tp& __y) const
- { return __x + __y; }
- };
-
+ struct _Plus<_Tp, _Tp, _Tp>
+ : public std::plus<_Tp> { };
/** @brief Similar to std::multiplies, but allows two different types. */
- template<typename _Tp1, typename _Tp2>
- struct _Multiplies : public std::binary_function<_Tp1, _Tp2, _Tp1>
+ template<typename _Tp1, typename _Tp2, typename _Result
+ = __typeof__(*static_cast<_Tp1*>(0)
+ * *static_cast<_Tp2*>(0))>
+ struct _Multiplies : public std::binary_function<_Tp1, _Tp2, _Result>
{
- typedef __typeof__(*static_cast<_Tp1*>(NULL)
- * *static_cast<_Tp2*>(NULL)) __result;
-
- __result
+ _Result
operator()(const _Tp1& __x, const _Tp2& __y) const
{ return __x * __y; }
};
// Partial specialization for one type. Same as std::multiplies.
template<typename _Tp>
- struct _Multiplies<_Tp, _Tp> : public std::binary_function<_Tp, _Tp, _Tp>
- {
- typedef __typeof__(*static_cast<_Tp*>(NULL)
- * *static_cast<_Tp*>(NULL)) __result;
-
- __result
- operator()(const _Tp& __x, const _Tp& __y) const
- { return __x * __y; }
- };
-
-
- template<typename _Tp, typename _DifferenceTp>
- class _PseudoSequence;
+ struct _Multiplies<_Tp, _Tp, _Tp>
+ : public std::multiplies<_Tp> { };
/** @brief _Iterator associated with __gnu_parallel::_PseudoSequence.
* If features the usual random-access iterator functionality.
* @param _Tp Sequence _M_value type.
- * @param _DifferenceType Sequence difference type.
+ * @param _DifferenceTp Sequence difference type.
*/
template<typename _Tp, typename _DifferenceTp>
class _PseudoSequenceIterator
public:
typedef _DifferenceTp _DifferenceType;
- private:
- const _Tp& _M_val;
- _DifferenceType _M_pos;
-
- public:
_PseudoSequenceIterator(const _Tp& __val, _DifferenceType __pos)
: _M_val(__val), _M_pos(__pos) { }
}
// Post-increment operator.
- const _PseudoSequenceIterator
+ _PseudoSequenceIterator
operator++(int)
{ return _PseudoSequenceIterator(_M_pos++); }
operator==(const _PseudoSequenceIterator& __i2)
{ return _M_pos == __i2._M_pos; }
- _DifferenceType
+ bool
operator!=(const _PseudoSequenceIterator& __i2)
{ return _M_pos != __i2._M_pos; }
_DifferenceType
operator-(const _PseudoSequenceIterator& __i2)
{ return _M_pos - __i2._M_pos; }
+
+ private:
+ const _Tp& _M_val;
+ _DifferenceType _M_pos;
};
/** @brief Sequence that conceptually consists of multiple copies of
the same element.
* The copies are not stored explicitly, of course.
* @param _Tp Sequence _M_value type.
- * @param _DifferenceType Sequence difference type.
+ * @param _DifferenceTp Sequence difference type.
*/
template<typename _Tp, typename _DifferenceTp>
class _PseudoSequence
typedef _PseudoSequenceIterator<_Tp, uint64_t> iterator;
/** @brief Constructor.
- * @param _M_val Element of the sequence.
+ * @param __val Element of the sequence.
* @param __count Number of (virtual) copies.
*/
_PseudoSequence(const _Tp& __val, _DifferenceType __count)
_DifferenceType _M_count;
};
- /** @brief Functor that does nothing */
- template<typename _ValueTp>
- class _VoidFunctor
- {
- inline void
- operator()(const _ValueTp& __v) const { }
- };
-
/** @brief Compute the median of three referenced elements,
according to @c __comp.
* @param __a First iterator.
template<typename _RAIter, typename _Compare>
_RAIter
__median_of_three_iterators(_RAIter __a, _RAIter __b,
- _RAIter __c, _Compare& __comp)
+ _RAIter __c, _Compare __comp)
{
if (__comp(*__a, *__b))
if (__comp(*__b, *__c))