HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
threadLimits.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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_THREAD_LIMITS_H
8 #define PXR_BASE_WORK_THREAD_LIMITS_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/base/work/api.h"
12 
14 
15 /// \file work/threadLimits.h
16 
17 /// Return the current concurrency limit, always >= 1.
18 ///
19 /// This value is determined by the underlying concurrency subsystem. It may
20 /// have been set by a third party, by a call to Work API below, or by Work
21 /// itself if the PXR_WORK_THREAD_LIMIT env setting was set. If the
22 /// PXR_WORK_THREAD_LIMIT env setting has been explicitly set to a non-zero
23 /// value, Work will attempt to configure the underlying concurrency subsystem
24 /// to use the specified limit and will ignore concurrency limits set via the
25 /// API calls below.
26 ///
27 /// Note that this can return a value larger than
28 /// WorkGetPhysicalConcurrencyLimit() if WorkSetConcurrencyLimit() was called
29 /// with such a value, or if PXR_WORK_THREAD_LIMIT was set with such a value.
30 ///
32 
33 /// Return the concurrency limit setting, computed from the physical
34 /// concurrency limit and the PXR_WORK_THREAD_LIMIT env setting. This is the
35 /// concurrency limit that work will try to implement at startup.
36 /// The concurrency limit will either be "0", meaning work doesn't try to apply
37 /// any concurrency limit, or a (normalized) positive number of threads.
39 
40 /// Return true if WorkGetPhysicalConcurrencyLimit() returns a number greater
41 /// than 1 and PXR_WORK_THREAD_LIMIT was not set in an attempt to limit the
42 /// process to a single thread, false otherwise.
43 ///
45 
46 /// Return the number of physical execution cores available to the program.
47 /// This is either the number of physical cores on the machine or the number of
48 /// cores specified by the process's affinity mask, whichever is smaller.
49 ///
51 
52 /// Set the concurrency limit to \p n, if \p n is a non-zero value.
53 ///
54 /// If \p n is zero, then do not change the current concurrency limit.
55 ///
56 /// Note, calling this function with n > WorkGetPhysicalConcurrencyLimit() may
57 /// overtax the machine.
58 ///
59 /// In general, very few places should call this function. Call it in places
60 /// where the number of allowed threads is dictated, for example, by a hosting
61 /// environment. Lower-level library code should never call this function.
62 ///
63 WORK_API void WorkSetConcurrencyLimit(unsigned n);
64 
65 /// Sanitize \p n as described below and set the concurrency limit accordingly.
66 /// This function is useful for interpreting command line arguments.
67 ///
68 /// If \p n is zero, then do not change the current concurrency limit.
69 ///
70 /// If \p n is a positive, non-zero value then call WorkSetConcurrencyLimit(n).
71 /// Note that calling this method with \p n greater than the value returned by
72 /// WorkGetPhysicalConcurrencyLimit() may overtax the machine.
73 ///
74 /// If \p n is negative, then set the concurrency limit to all but abs(\p n)
75 /// cores. The number of cores is determined by the value returned by
76 /// WorkGetPhysicalConcurrencyLimit().
77 /// For example, if \p n is -2, then use all but two cores. If abs(\p n) is
78 /// greater than the number of physical cores, then call
79 /// WorkSetConcurrencyLimit(1), effectively disabling concurrency.
80 ///
82 
83 /// Set the concurrency limit to be the maximum recommended for the hardware
84 /// on which it's running. Equivalent to:
85 /// \code
86 /// WorkSetConcurrencyLimit(WorkGetPhysicalConcurrencyLimit()).
87 /// \endcode
88 ///
90 
91 /// Returns true if a limit between 1 and the physical concurrency can be set,
92 /// and the implementation will make a best effort to respect the limit.
93 ///
94 /// Returns false if the implementation can only support 1 or the physical
95 /// concurrency. If there is an attempt to set a limit between 1 and the
96 /// physical concurrency the limit will default to the physical concurrency.
98 
100 
101 #endif
WORK_API unsigned WorkGetConcurrencyLimitSetting()
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
WORK_API unsigned WorkGetPhysicalConcurrencyLimit()
WORK_API void WorkSetMaximumConcurrencyLimit()
#define WORK_API
Definition: api.h:23
GLdouble n
Definition: glcorearb.h:2008
WORK_API unsigned WorkGetConcurrencyLimit()
WORK_API void WorkSetConcurrencyLimitArgument(int n)
WORK_API bool WorkHasConcurrency()
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
WORK_API void WorkSetConcurrencyLimit(unsigned n)
WORK_API bool WorkSupportsGranularThreadLimits()