[pstl] Use a different namespace for each backend

Also, use a single point of customization to set what namespace __par_backend
"points to", which provides a better separation of concerns.

llvm-svn: 365337
GitOrigin-RevId: b152f9f392d42e1c8e29f382f876480631575190
diff --git a/include/pstl/internal/algorithm_impl.h b/include/pstl/internal/algorithm_impl.h
index a584088..a9bf29a 100644
--- a/include/pstl/internal/algorithm_impl.h
+++ b/include/pstl/internal/algorithm_impl.h
@@ -2667,8 +2667,8 @@
             [__n, __move_values, __move_sequences](_BidirectionalIterator __f1, _BidirectionalIterator __l1,
                                                    _BidirectionalIterator __f2, _BidirectionalIterator __l2, _Tp* __f3,
                                                    _Compare __comp) {
-                (__par_backend::__serial_move_merge(__n))(__f1, __l1, __f2, __l2, __f3, __comp, __move_values,
-                                                          __move_values, __move_sequences, __move_sequences);
+                (__utils::__serial_move_merge(__n))(__f1, __l1, __f2, __l2, __f3, __comp, __move_values, __move_values,
+                                                    __move_sequences, __move_sequences);
                 return __f3 + (__l1 - __f1) + (__l2 - __f2);
             });
         __par_backend::__parallel_for(std::forward<_ExecutionPolicy>(__exec), __r, __r + __n,
diff --git a/include/pstl/internal/parallel_backend.h b/include/pstl/internal/parallel_backend.h
index c18007e..134ec50 100644
--- a/include/pstl/internal/parallel_backend.h
+++ b/include/pstl/internal/parallel_backend.h
@@ -14,8 +14,16 @@
 
 #if defined(_PSTL_PAR_BACKEND_SERIAL)
 #    include "parallel_backend_serial.h"
+namespace __pstl
+{
+namespace __par_backend = __serial_backend;
+}
 #elif defined(_PSTL_PAR_BACKEND_TBB)
 #    include "parallel_backend_tbb.h"
+namespace __pstl
+{
+namespace __par_backend = __tbb_backend;
+}
 #else
 _PSTL_PRAGMA_MESSAGE("Parallel backend was not specified");
 #endif
diff --git a/include/pstl/internal/parallel_backend_serial.h b/include/pstl/internal/parallel_backend_serial.h
index 5f79f60..969f199 100644
--- a/include/pstl/internal/parallel_backend_serial.h
+++ b/include/pstl/internal/parallel_backend_serial.h
@@ -20,7 +20,7 @@
 
 namespace __pstl
 {
-namespace __serial
+namespace __serial_backend
 {
 
 template <typename _Tp>
@@ -126,15 +126,7 @@
     std::forward<_F2>(__f2)();
 }
 
-} // namespace __serial
-} // namespace __pstl
-
-namespace __pstl
-{
-namespace __par_backend
-{
-using namespace __pstl::__serial;
-}
+} // namespace __serial_backend
 } // namespace __pstl
 
 #endif /* _PSTL_PARALLEL_BACKEND_SERIAL_H */
diff --git a/include/pstl/internal/parallel_backend_tbb.h b/include/pstl/internal/parallel_backend_tbb.h
index 81b2347..a32fd99 100644
--- a/include/pstl/internal/parallel_backend_tbb.h
+++ b/include/pstl/internal/parallel_backend_tbb.h
@@ -32,7 +32,7 @@
 
 namespace __pstl
 {
-namespace __par_backend
+namespace __tbb_backend
 {
 
 //! Raw memory buffer with automatic freeing and no exceptions.
@@ -875,7 +875,7 @@
 __stable_sort_task<_RandomAccessIterator1, _RandomAccessIterator2, _Compare, _LeafSort>::execute()
 {
     typedef __merge_task<_RandomAccessIterator1, _RandomAccessIterator2, _Compare, __serial_destroy,
-                         __serial_move_merge>
+                         __utils::__serial_move_merge>
         _MergeTaskType;
 
     const _SizeType __n = _M_xe - _M_xs;
@@ -897,10 +897,10 @@
     const _RandomAccessIterator1 __xm = _M_xs + __n / 2;
     const _RandomAccessIterator2 __zm = _M_zs + (__xm - _M_xs);
     const _RandomAccessIterator2 __ze = _M_zs + __n;
-    _MergeTaskType* __m = new (allocate_continuation())
-        _MergeTaskType(_M_xs - _M_x_beg, __xm - _M_x_beg, __xm - _M_x_beg, _M_xe - _M_x_beg, _M_zs - _M_z_beg, _M_comp,
-                       __serial_destroy(), __serial_move_merge(__nmerge), _M_nsort, _M_x_beg, _M_z_beg,
-                       /*x_orig*/ true, /*y_orig*/ true, /*root*/ _M_root);
+    _MergeTaskType* __m = new (allocate_continuation()) _MergeTaskType(
+        _M_xs - _M_x_beg, __xm - _M_x_beg, __xm - _M_x_beg, _M_xe - _M_x_beg, _M_zs - _M_z_beg, _M_comp,
+        __utils::__serial_destroy(), __utils::__serial_move_merge(__nmerge), _M_nsort, _M_x_beg, _M_z_beg,
+        /*x_orig*/ true, /*y_orig*/ true, /*root*/ _M_root);
 
     _M_root = false;
 
@@ -1049,7 +1049,7 @@
     tbb::this_task_arena::isolate([&]() { tbb::parallel_invoke(std::forward<_F1>(__f1), std::forward<_F2>(__f2)); });
 }
 
-} // namespace __par_backend
+} // namespace __tbb_backend
 } // namespace __pstl
 
 #endif /* _PSTL_PARALLEL_BACKEND_TBB_H */
diff --git a/include/pstl/internal/parallel_backend_utils.h b/include/pstl/internal/parallel_backend_utils.h
index cd4f72b..ced4963 100644
--- a/include/pstl/internal/parallel_backend_utils.h
+++ b/include/pstl/internal/parallel_backend_utils.h
@@ -19,7 +19,8 @@
 
 namespace __pstl
 {
-namespace __par_backend
+
+namespace __utils
 {
 
 //! Destroy sequence [xs,xe)
@@ -219,7 +220,7 @@
     }
 };
 
-} // namespace __par_backend
+} // namespace __utils
 } // namespace __pstl
 
 #endif /* _PSTL_PARALLEL_BACKEND_UTILS_H */