BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmt_configuration.h
Go to the documentation of this file.
1/// @file bslmt_configuration.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmt_configuration.h -*-C++-*-
8#ifndef INCLUDED_BSLMT_CONFIGURATION
9#define INCLUDED_BSLMT_CONFIGURATION
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmt_configuration bslmt_configuration
15/// @brief Provide utilities to allow configuration of values for BCE.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmt
19/// @{
20/// @addtogroup bslmt_configuration
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmt_configuration-purpose"> Purpose</a>
25/// * <a href="#bslmt_configuration-classes"> Classes </a>
26/// * <a href="#bslmt_configuration-description"> Description </a>
27/// * <a href="#bslmt_configuration-usage"> Usage </a>
28/// * <a href="#bslmt_configuration-example-1-demonstrate-accessing-&-modifying-the-default-thread-stack-size"> Example 1: Demonstrate Accessing & Modifying the Default Thread Stack Size </a>
29///
30/// # Purpose {#bslmt_configuration-purpose}
31/// Provide utilities to allow configuration of values for BCE.
32///
33/// # Classes {#bslmt_configuration-classes}
34///
35/// - bslmt::Configuration: namespace for utilities managing default BCE values
36///
37/// @see bslmt_threadattributes, bslmt_threadutil
38///
39/// # Description {#bslmt_configuration-description}
40/// This component defines a utility `struct`,
41/// `bslmt::Configuration`, that is a name space for pure functions used for
42/// providing access to, and configuring, default values for BCE-relevant
43/// parameters. The `bslmt::Configuration` utility currently provides static
44/// methods to access and modify the BCE library's default stack size, as well
45/// as functions that access the platform's native default stack size and guard
46/// size. The BDE default stack size is initially configured to
47/// `bslmt::ThreadAttributes::BSLMT_UNSET_STACK_SIZE`, in which case thread
48/// creation is to use the native default thread stack size.
49///
50/// ## Usage {#bslmt_configuration-usage}
51///
52///
53/// This section illustrates intended use of this component.
54///
55/// ### Example 1: Demonstrate Accessing & Modifying the Default Thread Stack Size {#bslmt_configuration-example-1-demonstrate-accessing-&-modifying-the-default-thread-stack-size}
56///
57///
58/// In this example we demonstrate how to access both the platform's native and
59/// BDE configured default stack sizes, and then to set the default stack size
60/// used by BDE. Note that the value returned by `defaultThreadStackSize` may
61/// be adjusted from that provided by the underlying operating system to reflect
62/// the actual amount of stack memory available to a created thread. Note that
63/// operations creating a thread should perform a similar inverse adjustment
64/// when configuring the new thread's stack size (see @ref bslmt_threadutil ).
65///
66/// First, we examine the platform's native thread stack size:
67/// @code
68/// const int nativeDefault =
69/// bslmt::Configuration::nativeDefaultThreadStackSize();
70///
71/// assert(nativeDefault > 0);
72/// @endcode
73/// Then, we verify that `defaultThreadStackSize` is unset.
74/// @code
75/// assert(bslmt::ThreadAttributes::e_UNSET_STACK_SIZE ==
76/// bslmt::Configuration::defaultThreadStackSize());
77/// @endcode
78/// Next, we define `newDefaultStackSize` to some size other than the platform's
79/// native default stack size:
80/// @code
81/// const int newDefaultStackSize = nativeDefault * 2;
82/// @endcode
83/// Now, we set the default size for BCE to the new size:
84/// @code
85/// bslmt::Configuration::setDefaultThreadStackSize(newDefaultStackSize);
86/// @endcode
87/// Finally, we verify that BCE's default thread stack size has been set to the
88/// value we specified:
89/// @code
90/// assert(bslmt::Configuration::defaultThreadStackSize() ==
91/// newDefaultStackSize);
92/// assert(bslmt::Configuration::defaultThreadStackSize() != nativeDefault);
93/// @endcode
94/// @}
95/** @} */
96/** @} */
97
98/** @addtogroup bsl
99 * @{
100 */
101/** @addtogroup bslmt
102 * @{
103 */
104/** @addtogroup bslmt_configuration
105 * @{
106 */
107
108#include <bslscm_version.h>
109
110
111namespace bslmt {
112
113 // ====================
114 // struct Configuration
115 // ====================
116
117/// This `struct` provides a namespace for a suite of functions that are
118/// used to manage the configuration of default values used in `bslmt`.
119/// Specifically, these functions manage the default value of thread stack
120/// size and provide access to the platform's native guard size, but may be
121/// extended to govern more traits in the future.
123
124 // CLASS METHODS
125
126 /// Return the value set by the last call to
127 /// `setDefaultThreadStackSize`; if `setDefaultThreadStackSize` has
128 /// never been called, return `ThreadAttributes::BSLMT_UNSET_STACK_SIZE`
129 /// which will signal thread creation to use the thread stack size
130 /// native to the platform.
132
133 /// Return the "native" default thread stack size (in bytes) as
134 /// determined by the underlying platform. Note that this value may be
135 /// influenced by the choice of platform, environment variables,
136 /// compiler/linker options, or shell configuration, and typically
137 /// varies wildly among different platforms.
139
140 /// Return the default thread stack guard size (in bytes) determined by
141 /// the underlying platform. Note that this value reflects semantics,
142 /// and may be influenced by the choice of platform, environment
143 /// variables, compiler/linker options, or shell configuration, and may
144 /// vary somewhat among different platforms.
146
147 /// Return a "reasonable" value for the default thread stack size (in
148 /// bytes), which, unlike `nativeDefaultThreadStackSize`, is constant
149 /// across all platforms of a given word size. This value is large
150 /// enough to guarantee that an automatic array of at least 250 * 1024
151 /// pointers may be declared in the top level routine of the thread.
153
154 /// Set the default thread stack size to the specified `numBytes`. If a
155 /// minimum thread stack size is known for the underlying platform (i.e.
156 /// `PTHREAD_STACK_MIN` is defined) and `numBytes` is below that
157 /// minimum, the stack size will be that minimum. The behavior is
158 /// undefined unless `0 <= numBytes`.
159 static void setDefaultThreadStackSize(int numBytes);
160};
161
162} // close package namespace
163
164
165#endif
166
167// ----------------------------------------------------------------------------
168// Copyright 2015 Bloomberg Finance L.P.
169//
170// Licensed under the Apache License, Version 2.0 (the "License");
171// you may not use this file except in compliance with the License.
172// You may obtain a copy of the License at
173//
174// http://www.apache.org/licenses/LICENSE-2.0
175//
176// Unless required by applicable law or agreed to in writing, software
177// distributed under the License is distributed on an "AS IS" BASIS,
178// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
179// See the License for the specific language governing permissions and
180// limitations under the License.
181// ----------------------------- END-OF-FILE ----------------------------------
182
183/** @} */
184/** @} */
185/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bslmt_barrier.h:344
Definition bslmt_configuration.h:122
static int defaultThreadStackSize()
static void setDefaultThreadStackSize(int numBytes)
static int recommendedDefaultThreadStackSize()
static int nativeDefaultThreadStackSize()
static int nativeDefaultThreadGuardSize()