Loading...
Searching...
No Matches
sort.h
Go to the documentation of this file.
1//
2// Copyright 2024 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_WORK_SORT_H
8#define PXR_BASE_WORK_SORT_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/base/work/impl.h"
15
16#include <algorithm>
17
18PXR_NAMESPACE_OPEN_SCOPE
19
22template <typename C>
23void
24WorkParallelSort(C* container)
25{
26 // Don't bother with parallel_for, if concurrency is limited to 1.
27 if (WorkHasConcurrency()) {
28 PXR_WORK_IMPL_NAMESPACE_USING_DIRECTIVE;
29 WorkImpl_ParallelSort(container);
30 }else{
31 std::sort(container->begin(), container->end());
32 }
33}
34
35
39template <typename C, typename Compare>
40void
41WorkParallelSort(C* container, const Compare& comp)
42{
43 // Don't bother with parallel_for, if concurrency is limited to 1.
44 if (WorkHasConcurrency()) {
45 PXR_WORK_IMPL_NAMESPACE_USING_DIRECTIVE;
46 WorkImpl_ParallelSort(container, comp);
47 }else{
48 std::sort(container->begin(), container->end(), comp);
49 }
50}
51
52PXR_NAMESPACE_CLOSE_SCOPE
53
54#endif
void WorkParallelSort(C *container)
Sorts in-place a container that provides begin() and end() methods.
Definition: sort.h:24
WORK_API bool WorkHasConcurrency()
Return true if WorkGetPhysicalConcurrencyLimit() returns a number greater than 1 and PXR_WORK_THREAD_...