BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmt_threadattributes.h
Go to the documentation of this file.
1/// @file bslmt_threadattributes.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmt_threadattributes.h -*-C++-*-
8#ifndef INCLUDED_BSLMT_THREADATTRIBUTES
9#define INCLUDED_BSLMT_THREADATTRIBUTES
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmt_threadattributes bslmt_threadattributes
15/// @brief Provide a description of the attributes of a thread.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmt
19/// @{
20/// @addtogroup bslmt_threadattributes
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmt_threadattributes-purpose"> Purpose</a>
25/// * <a href="#bslmt_threadattributes-classes"> Classes </a>
26/// * <a href="#bslmt_threadattributes-description"> Description </a>
27/// * <a href="#bslmt_threadattributes-attributes"> Attributes </a>
28/// * <a href="#bslmt_threadattributes-detachedstate-attribute"> detachedState Attribute </a>
29/// * <a href="#bslmt_threadattributes-stacksize-attribute"> stackSize Attribute </a>
30/// * <a href="#bslmt_threadattributes-guardsize-attribute"> guardSize Attribute </a>
31/// * <a href="#bslmt_threadattributes-inheritschedule-attribute"> inheritSchedule Attribute </a>
32/// * <a href="#bslmt_threadattributes-schedulingpolicy-attribute"> schedulingPolicy Attribute </a>
33/// * <a href="#bslmt_threadattributes-schedulingpriority-attribute"> schedulingPriority Attribute </a>
34/// * <a href="#bslmt_threadattributes-threadname-attribute"> threadName Attribute </a>
35/// * <a href="#bslmt_threadattributes-fluent-interface"> Fluent Interface </a>
36/// * <a href="#bslmt_threadattributes-usage"> Usage </a>
37/// * <a href="#bslmt_threadattributes-example-1-creating-and-modifying-thread-attributes-objects"> Example 1: Creating and Modifying Thread Attributes Objects </a>
38///
39/// # Purpose {#bslmt_threadattributes-purpose}
40/// Provide a description of the attributes of a thread.
41///
42/// # Classes {#bslmt_threadattributes-classes}
43///
44/// - bslmt::ThreadAttributes: description of the attributes of a thread
45///
46/// @see bslmt_threadutil, bslmt_configuration
47///
48/// # Description {#bslmt_threadattributes-description}
49/// This component provides a simply constrained (value-semantic)
50/// attribute class, `bslmt::ThreadAttributes`, for describing attributes of a
51/// thread in a platform-independent way.
52///
53/// ## Attributes {#bslmt_threadattributes-attributes}
54///
55///
56/// The default values and constraints for the attributes provided by
57/// `bslmt::ThreadAttributes` are listed in the following two tables:
58/// @code
59/// Name Type Default
60/// ------------------ --------------------- ----------------------
61/// detachedState enum DetachedState e_CREATE_JOINABLE
62/// stackSize int e_UNSET_STACK_SIZE
63/// guardSize int e_UNSET_GUARD_SIZE
64/// inheritSchedule bool 'true'
65/// schedulingPolicy enum SchedulingPolicy e_SCHED_DEFAULT
66/// schedulingPriority int e_UNSET_PRIORITY
67/// threadName bsl::string ""
68///
69/// Name Constraint
70/// --------- ---------------------------------------------------
71/// stackSize 'e_UNSET_STACK_SIZE == stackSize || 0 <= stackSize'
72/// guardSize 'e_UNSET_GUARD_SIZE == guardSize || 0 <= guardSize'
73/// @endcode
74///
75/// ### detachedState Attribute {#bslmt_threadattributes-detachedstate-attribute}
76///
77///
78/// The `detachedState` attribute indicates whether an associated thread should
79/// be created in a joinable or detached state, through the enum values
80/// `e_CREATE_JOINABLE` and `e_CREATE_DETACHED`, respectively. A thread in the
81/// joinable state will have its exit status maintained after thread
82/// termination. Any thread can join with a joinable thread (see
83/// @ref bslmt_threadutil ), in which case the joining thread will block, waiting
84/// for the joined thread's execution to complete, after which the joined
85/// thread's termination status will be reported back to the joining thread, and
86/// its resources reclaimed. A thread in a detached state will have its
87/// resources claimed at thread termination, and cannot be joined. Note that a
88/// joinable thread can be made detached after it is created, but not vice
89/// versa.
90///
91/// ### stackSize Attribute {#bslmt_threadattributes-stacksize-attribute}
92///
93///
94/// The `stackSize` attribute indicates the size, in bytes, of the stack that
95/// should be provided to a newly created thread. If the stack size is
96/// `e_UNSET_STACK_SIZE` then a created thread will be provided a default stack
97/// size (see @ref bslmt_configuration ). The `stackSize` attribute should be
98/// interpreted to mean that a created thread can safely define an automatic
99/// variable of the configured `stackSize` bytes in its thread-entry function.
100/// Note that, on some platforms, an adjusted value derived from the `stackSize`
101/// attribute may be supplied to the underlying representation by the thread
102/// creation function.
103///
104/// ### guardSize Attribute {#bslmt_threadattributes-guardsize-attribute}
105///
106///
107/// The `guardSize` attribute indicates the size of the memory region to provide
108/// past the end of a created thread's stack to protect against stack overflows.
109/// If a thread's stack pointer overflows into a guard area, the task will
110/// receive an error (e.g., a signal). If `guardSize` is `e_UNSET_GUARD_SIZE`,
111/// then a created thread will be provided with a default native guard size (see
112/// @ref bslmt_configuration ). Note that the interpretation of `guardSize` may
113/// vary among platforms, and the value may be adjusted up (e.g., by rounding up
114/// to a multiple of page size) or ignored entirely (e.g., the Windows platform
115/// does not support this attribute).
116///
117/// ### inheritSchedule Attribute {#bslmt_threadattributes-inheritschedule-attribute}
118///
119///
120/// The `inheritSchedule` attribute, if `true`, indicates that a created
121/// thread's `schedulingPolicy` and `schedulingPriority` attributes should be
122/// taken from its parent thread and the configured values of those thread
123/// attributes should be ignored. If `inheritSchedule` is `false`, then the
124/// `schedulingPolicy` and `schedulingPriority` attribute values should be used
125/// to configure a thread. See @ref bslmt_threadutil for information about support
126/// for this attribute.
127///
128/// ### schedulingPolicy Attribute {#bslmt_threadattributes-schedulingpolicy-attribute}
129///
130///
131/// The `schedulingPolicy` attribute indicates the policy that should be used to
132/// schedule the created thread for execution. Typically clients should use the
133/// default platform supplied scheduling policy, which is indicated by the
134/// `e_SCHED_DEFAULT` value. The alternative scheduling policies,
135/// `e_THREAD_FIFO` and `e_SCHED_RR`, are "real-time" scheduling policies, and
136/// may not be available unless the task is run with the appropriate privileges.
137/// `e_SCHED_FIFO` indicates a thread should run until it either yields or is
138/// interrupted by a thread of higher priority. `e_SCHED_RR` is the same as
139/// `e_SCHED_FIFO`, except that the created thread may be interrupted by a ready
140/// thread of equal priority after a finite time-slice. This attribute is
141/// ignored unless `inheritSchedule` is `false`. See @ref bslmt_threadutil for
142/// information about support for this attribute.
143///
144/// ### schedulingPriority Attribute {#bslmt_threadattributes-schedulingpriority-attribute}
145///
146///
147/// The `schedulingPriority` attribute is a platform specific value whose valid
148/// values range from the minimum to the maximum value for the associated
149/// `schedulingPolicy`, with higher numbers indicating a more urgent priority.
150/// Functions to obtain the minimum and maximum values are in this component and
151/// @ref bslmt_threadutil . This attribute is ignored unless `inheritSchedule` is
152/// `false`. See @ref bslmt_threadutil for information about support for this
153/// attribute.
154///
155/// ### threadName Attribute {#bslmt_threadattributes-threadname-attribute}
156///
157///
158/// The `threadName` attribute indicates the name the thread is to have. Thread
159/// names show up in debuggers on some platforms, and are unsupported on others.
160/// Thread names have unlimited lengths in a thread attributes object, but the
161/// thread names actually supported by specific platforms may have limited
162/// length, depending upon the platform, so thread names may be truncated when
163/// assigned to the actual thread. At this time, only Linux, Solaris, Darwin,
164/// and Windows support thread names. Unix platforms have a maximum thread name
165/// length of 15, while on Windows, the limit is 32767, or `(1 << 15) - 1`
166/// characters.
167///
168/// ## Fluent Interface {#bslmt_threadattributes-fluent-interface}
169///
170///
171/// `bslmt::ThreadAttributes` provides manipulators that return a non-`const`
172/// reference to the object so that setting individual attributes can be
173/// "chained" into a single expression statement, or that attributes can be
174/// "built" in place as a function argument. For example:
175/// @code
176/// bslmt::ThreadUtil::Handle handle;
177///
178/// int status = bslmt::ThreadUtil::create(
179/// &handle,
180/// bslmt::ThreadAttributes().setThreadName("myName")
181/// .setInheritSchedule(true),
182/// myThreadFunction,
183/// &myThreadArgument);
184/// @endcode
185///
186/// ## Usage {#bslmt_threadattributes-usage}
187///
188///
189/// This section illustrates intended use of this component.
190///
191/// ### Example 1: Creating and Modifying Thread Attributes Objects {#bslmt_threadattributes-example-1-creating-and-modifying-thread-attributes-objects}
192///
193///
194/// In this example we will demonstrate creating and configuring a
195/// `bslmt::ThreadAttributes` object, then using it with a hypothetical
196/// thread-creation function. Finally we show how a thread creation function
197/// might interpret those attributes for the underlying operating system.
198///
199/// First we forward declare a routine that we will use to create a thread:
200/// @code
201/// // Spawn a thread having properties described by the specified
202/// // `attributes` and that runs the specified `function`, and assign a
203/// // handle referring to the spawned thread to the specified
204/// // `*threadHandle`.
205/// void myThreadCreate(int *threadHandle,
206/// const bslmt::ThreadAttributes& attributes,
207/// void (*function)());
208/// @endcode
209/// Then, we declare two routines that will return the minimum and maximum
210/// thread priority given a scheduling policy. Note that similar methods exist
211/// in @ref bslmt_threadutil .
212/// @code
213/// int myMinPriority(bslmt::ThreadAttributes::SchedulingPolicy policy);
214/// int myMaxPriority(bslmt::ThreadAttributes::SchedulingPolicy policy);
215/// @endcode
216/// Next we define a function that we will use as our thread entry point. This
217/// function declares a single variable on the stack of predetermined size.
218/// @code
219/// enum { k_BUFFER_SIZE = 128 * 1024 };
220///
221/// void myThreadFunction()
222/// {
223/// int bufferLocal[k_BUFFER_SIZE];
224///
225/// // Perform some calculation that involves no subroutine calls or
226/// // additional automatic variables.
227/// }
228/// @endcode
229/// Then, we define our main function, in which we demonstrate configuring a
230/// `bslmt::ThreadAttributes` object describing the properties a thread we will
231/// create.
232/// @code
233/// void testMain()
234/// {
235/// @endcode
236/// Next, we create a thread attributes object, `attributes`, and set its
237/// `stackSize` attribute to a value large enough to accommodate the
238/// `BUFFER_SIZE` buffer used by `myThreadFunction`. Note that we use
239/// `BUFFER_SIZE` as an illustration; in practice, it is difficult or impossible
240/// to gauge the exact amount of stack size required for a typical thread, and
241/// the value supplied should be a reasonable *upper* bound on the anticipated
242/// requirement.
243/// @code
244/// bslmt::ThreadAttributes attributes;
245/// attributes.setStackSize(k_BUFFER_SIZE);
246/// @endcode
247/// Then, we set the `detachedState` property to `e_CREATE_DETACHED`, indicating
248/// that the thread will not be joinable, and its resources will be reclaimed
249/// upon termination.
250/// @code
251/// attributes.setDetachedState(
252/// bslmt::ThreadAttributes::e_CREATE_DETACHED);
253/// @endcode
254/// Now, we create a thread, using the attributes configured above:
255/// @code
256/// int handle;
257/// myThreadCreate(&handle, attributes, &myThreadFunction);
258/// }
259/// @endcode
260/// Finally, we define the thread creation function, and show how a thread
261/// attributes object might be interpreted by it:
262/// @code
263/// /// Spawn a thread with properties described by the specified
264/// /// `attributes`, running the specified `function`, and assign a handle
265/// /// referring to the spawned thread to the specified `*threadHandle`.
266/// void myThreadCreate(int *threadHandle,
267/// const bslmt::ThreadAttributes& attributes,
268/// void (*function)())
269/// {
270/// int stackSize = attributes.stackSize();
271/// if (bslmt::ThreadAttributes::e_UNSET_STACK_SIZE == stackSize) {
272/// stackSize = bslmt::Configuration::defaultThreadStackSize();
273/// }
274///
275/// // Add a "fudge factor" to `stackSize` to ensure that the client can
276/// // declare an object of `stackSize` bytes on the stack safely.
277///
278/// stackSize += 8192;
279///
280/// int guardSize = attributes.guardSize();
281/// if (bslmt::ThreadAttributes::e_UNSET_GUARD_SIZE == guardSize) {
282/// guardSize = bslmt::Configuration::nativeDefaultThreadGuardSize();
283/// }
284///
285/// int policy = attributes.schedulingPolicy();
286/// int priority = attributes.schedulingPriority();
287///
288/// // the following is pseudo-code for actually creating the thread
289/// /*
290/// if (bslmt::ThreadAttributes::e_UNSET_PRIORITY == priority) {
291/// priority = operatingSystemDefaultPriority(policy);
292/// }
293///
294/// operatingSystemThreadCreate(threadHandle,
295/// stackSize,
296/// guardSize,
297/// attributes.inheritSchedule(),
298/// policy,
299/// priority,
300/// attributes.detachedState()
301/// function);
302/// */
303/// }
304/// @endcode
305/// Notice that a new value derived from the `stackSize` attribute is used so
306/// that the meaning of the attribute is platform neutral.
307/// @}
308/** @} */
309/** @} */
310
311/** @addtogroup bsl
312 * @{
313 */
314/** @addtogroup bslmt
315 * @{
316 */
317/** @addtogroup bslmt_threadattributes
318 * @{
319 */
320
321#include <bslscm_version.h>
322
323#include <bslma_allocator.h>
325
326#include <bslmf_assert.h>
328
329#include <bsls_assert.h>
330#include <bsls_platform.h>
331
332#include <bsl_c_limits.h>
333#include <bsl_iosfwd.h>
334#include <bsl_string.h>
335
336
337namespace bslmt {
338
339 // ======================
340 // class ThreadAttributes
341 // ======================
342
343/// This simply constrained (value-semantic) attribute class characterizes a
344/// collection of thread attribute values. See the @ref bslmt_threadattributes-attributes section for
345/// information on the class attributes.
346///
347/// This class:
348/// * supports a complete set of *value* *semantic* operations
349/// - except for `bdex` serialization
350/// * is *exception-neutral*
351/// * is *alias-safe*
352/// * is `const` *thread-safe*
353/// For terminology see @ref bsldoc_glossary .
354///
355/// See @ref bslmt_threadattributes
357
358 public:
359 // PUBLIC TYPES
360
361 /// This enumeration provides two values used to distinguish among a
362 /// joinable thread and a non-joinable (detached) thread.
364
365 e_CREATE_JOINABLE = 0, // create a joinable thread
366 e_CREATE_DETACHED = 1 // create a non-joinable thread
367
368#ifndef BDE_OMIT_INTERNAL_DEPRECATED
373#endif // BDE_OMIT_INTERNAL_DEPRECATED
374 };
375
377 // This enumeration provides values used to distinguish between
378 // different thread scheduling policies.
379
380 e_SCHED_OTHER = 0, // unspecified, OS-dependent scheduling
381 // policy
382
383 e_SCHED_FIFO = 1, // first-in-first-out scheduling policy
384
385 e_SCHED_RR = 2, // round-robin scheduling policy
386
387 e_SCHED_DEFAULT = 3 // default OS scheduling policy, usually
388 // equivalent to 'e_SCHED_OTHER'
389#ifndef BDE_OMIT_INTERNAL_DEPRECATED
394#endif // BDE_OMIT_INTERNAL_DEPRECATED
395 };
396
397 /// The following constants indicate that the `stackSize`, `guardSize`,
398 /// and `schedulingPriority` attributes, respectively, are unspecified
399 /// and the thread creation routine is use platform-specific defaults.
400 /// These attributes are initialized to these values when a thread
401 /// attributes object is default constructed.
402 enum {
403
407
410#ifndef BDE_OMIT_INTERNAL_DEPRECATED
416#endif // BDE_OMIT_INTERNAL_DEPRECATED
417 };
418
419 private:
420 // DATA
421 DetachedState d_detachedState; // whether the thread is detached
422 // or joinable
423
424 int d_guardSize; // size of guard area provided
425 // beyond the end of the configured
426 // thread's stack
427
428 bool d_inheritScheduleFlag; // whether the thread inherits its
429 // scheduling policy & priority
430 // from its parent thread
431
432 SchedulingPolicy d_schedulingPolicy; // policy for scheduling thread
433 // execution
434
435 int d_schedulingPriority; // thread priority (higher numbers
436 // indicate more urgency)
437
438 int d_stackSize; // size of the thread's stack
439
440 bsl::string d_threadName; // name of the thread
441
442 public:
443 // TRAITS
446
447 // CREATORS
448
450 /// Create a `ThreadAttributes` object having the (default) attribute
451 /// values:
452 /// * `detachedState() == e_CREATE_JOINABLE`
453 /// * `guardSize() == e_UNSET_GUARD_SIZE`
454 /// * `inheritSchedule() == true`
455 /// * `schedulingPolicy() == e_SCHED_DEFAULT`
456 /// * `schedulingPriority() == e_UNSET_PRIORITY`
457 /// * `stackSize() == e_UNSET_STACK_SIZE`
458 /// * `threadName() == ""`
459 /// Optionally specify a `basicAllocator` used to supply memory. If
460 /// `basicAllocator` is 0, the currently installed default allocator is
461 /// used.
462 explicit ThreadAttributes(bslma::Allocator *basicAllocator);
463
464 /// Create a `ThreadAttributes` object having the same value as the
465 /// specified `original` object. Optionally specify a `basicAllocator`
466 /// used to supply memory. If `basicAllocator` is 0, the currently
467 /// installed default allocator is used.
469 bslma::Allocator *basicAllocator = 0);
470
471 // MANIPULATORS
472
473 /// Assign to this object the value of the specified `rhs` object, and
474 /// return a reference providing modifiable access to this object.
476
477 // MANIPULATORS
478
479 /// Set the `detachedState` attribute of this object to the specified
480 /// `value`. Return a non-`const` reference to this object (see also
481 /// {Fluent Interface}). A value of `e_CREATE_JOINABLE` (the default)
482 /// indicates that a thread must be joined to clean up its resources
483 /// after it terminates; a value of `e_CREATE_DETACHED` (the only other
484 /// legal value) indicates that the resources will be cleaned up
485 /// automatically upon thread termination, and that the thread must not
486 /// be joined.
488
489 /// Set the `guardSize` attribute of this object to the specified
490 /// `value` (in bytes). Return a non-`const` reference to this object
491 /// (see also {Fluent Interface}). `e_UNSET_GUARD_SIZE == guardSize` is
492 /// intended to indicate that the default value as defined by the
493 /// platform is to be used. This default value is typically the size of
494 /// one or two pages (see @ref bslmt_configuration ). The behavior is
495 /// undefined unless `e_UNSET_GUARD_SIZE == guardSize` or
496 /// `guardSize >= 0`.
497 ThreadAttributes& setGuardSize(int value);
498
499 /// Set the `inheritSchedule` attribute of this object to the specified
500 /// `value`. Return a non-`const` reference to this object (see also
501 /// {Fluent Interface}). A value of `false` for the inherit schedule
502 /// attribute indicates that a thread should *not* inherit the
503 /// scheduling policy and priority of the thread that created it and
504 /// instead should use the respective values supplied by this object;
505 /// whereas a value of `true` indicates that the thread *should* inherit
506 /// these attributes and ignore the respective values in this object.
507 /// See @ref bslmt_threadutil for information about support for this
508 /// attribute.
510
511 /// Set the value of the `schedulingPolicy` attribute of this object to
512 /// the specified `value`. Return a non-`const` reference to this
513 /// object (see also {Fluent Interface}). This attribute is ignored
514 /// unless `inheritSchedule` is `false`. See @ref bslmt_threadutil for
515 /// information about this attribute.
517
518 /// Set the `schedulingPriority` attribute of this object to the
519 /// specified `value`. Return a non-`const` reference to this object
520 /// (see also {Fluent Interface}). This attribute is ignored unless
521 /// `inheritSchedule()` is `false`. Higher values of `value` signify
522 /// more urgent priorities. Note that the valid range of priorities
523 /// depends upon the platform and `schedulingPolicy` attribute, and the
524 /// minimum and maximum priority values are determined by methods in
525 /// @ref bslmt_threadutil . See @ref bslmt_threadutil for information about
526 /// this attribute.
528
529 /// Set the `stackSize` attribute of this object to the specified
530 /// `value`. Return a non-`const` reference to this object (see also
531 /// {Fluent Interface}). If `stackSize` is `e_UNSET_STACK_SIZE`, thread
532 /// creation should use the default stack size value provided by
533 /// @ref bslmt_configuration . The behavior is undefined unless
534 /// `e_UNSET_STACK_SIZE == stackSize` or `0 <= stackSize`.
535 ThreadAttributes& setStackSize(int value);
536
537 /// Set the `threadName` attribute of this object to the specified
538 /// `value`. Return a non-`const` reference to this object (see also
539 /// {Fluent Interface}).
541
542 // ACCESSORS
543
544 /// Return the value of the `detachedState` attribute of this object. A
545 /// value of `e_CREATE_JOINABLE` indicates that a thread must be joined
546 /// after it terminates to clean up its resources; a value of
547 /// `e_CREATE_DETACHED` (the only other legal value) indicates that the
548 /// resources will be cleaned up automatically upon thread termination,
549 /// and that the thread must not be joined.
551
552 /// Return the value of the `guardSize` attribute of this object. The
553 /// value `e_UNSET_GUARD_SIZE == guardSize` is intended to indicate that
554 /// the default value as defined by the platform (which is typically the
555 /// size of one or two pages) should be obtained from
556 /// @ref bslmt_configuration and used.
557 int guardSize() const;
558
559 /// Return the value of the `inheritSchedule` attribute of this object.
560 /// A value of `false` for the inherit schedule attribute indicates that
561 /// a thread should *not* inherit the scheduling policy and priority of
562 /// the thread that created it and instead should use the respective
563 /// values supplied by this object; whereas a value of `true` indicates
564 /// that the thread *should* inherit these attributes and ignore the
565 /// respective values in this object. See @ref bslmt_threadutil for
566 /// information about support for this attribute.
567 bool inheritSchedule() const;
568
569 /// Format this object to the specified output `stream` at the (absolute
570 /// value of) the optionally specified indentation `level` and return a
571 /// reference to `stream`. If `level` is specified, optionally specify
572 /// `spacesPerLevel`, the number of spaces per indentation level for
573 /// this and all of its nested objects. If `level` is negative,
574 /// suppress indentation of the first line. If `spacesPerLevel` is
575 /// negative format the entire output on one line, suppressing all but
576 /// the initial indentation (as governed by `level`). If `stream` is
577 /// not valid on entry, this operation has no effect.
578 bsl::ostream& print(bsl::ostream& stream,
579 int level = 0,
580 int spacesPerLevel = 4) const;
581
582 /// Return the value of the `schedulingPolicy` attribute of this object.
583 /// This attribute is ignored unless `inheritSchedule` is `false`. See
584 /// @ref bslmt_threadutil for information about this attribute.
586
587 /// Return the value of the `schedulingPriority` attribute of this
588 /// object. This attribute is ignored unless `inheritSchedule()` is
589 /// `false`. Higher values of `value` signify more urgent priorities.
590 /// Note that the valid range of priorities depends upon the platform
591 /// and `schedulingPolicy` attribute, and the minimum and maximum
592 /// priority values are determined by methods in @ref bslmt_threadutil .
593 /// See @ref bslmt_threadutil for information about this attribute.
594 int schedulingPriority() const;
595
596 /// Return the value of the `stackSize` attribute of this object. If
597 /// `stackSize` is `e_UNSET_STACK_SIZE`, thread creation should use the
598 /// default stack size value provided by @ref bslmt_configuration .
599 int stackSize() const;
600
601 /// Return the `threadName` attribute of this object. Note that the
602 /// returned string reference will be invalidated if `setThreadName` is
603 /// subsequently called on this object.
605
606 // Aspects
607
608 /// Return the allocator used by this object to supply memory.
610};
611
612// FREE OPERATORS
613
614/// Return `true` if the specified `lhs` and `rhs` objects have the same
615/// value, and `false` otherwise. Two `ThreadAttributes` objects have the
616/// same value if the corresponding values of their `detachedState`,
617/// `guardSize`, `inheritSchedule`, `schedulingPolicy`,
618/// `schedulingPriority`, and `stackSize` attributes are the same.
619bool operator==(const ThreadAttributes& lhs, const ThreadAttributes& rhs);
620
621/// Return `true` if the specified `lhs` and `rhs` objects do not have the
622/// same value, and `false` otherwise. Two `baltzo::LocalTimeDescriptor`
623/// objects do not have the same value if the corresponding values of their
624/// `detachedState`, `guardSize`, `inheritSchedule`, `schedulingPolicy`,
625/// `schedulingPriority`, and `stackSize` attributes are not the same.
626bool operator!=(const ThreadAttributes& lhs, const ThreadAttributes& rhs);
627
628// FREE OPERATORS
629
630/// Write the value of the specified `object` object to the specified output
631/// `stream` in a single-line format, and return a reference to `stream`.
632/// If `stream` is not valid on entry, this operation has no effect. Note
633/// that this human-readable format is not fully specified, can change
634/// without notice, and is logically equivalent to:
635/// @code
636/// print(stream, 0, -1);
637/// @endcode
638bsl::ostream& operator<<(bsl::ostream& stream,
639 const ThreadAttributes& object);
640
641// ============================================================================
642// INLINE DEFINITIONS
643// ============================================================================
644
645 // ----------------------
646 // class ThreadAttributes
647 // ----------------------
648
649// MANIPULATORS
650inline
653{
655 e_CREATE_JOINABLE == value);
656
657 d_detachedState = value;
658
659 return *this;
660}
661
662inline
664{
666
667 BSLS_ASSERT_SAFE(-1 <= value);
668
669 d_guardSize = value;
670
671 return *this;
672}
673
674inline
676{
677 d_inheritScheduleFlag = value;
678
679 return *this;
680}
681
682inline
685{
686 BSLS_ASSERT_SAFE(e_SCHED_MIN <= (int) value);
687 BSLS_ASSERT_SAFE( (int) value <= e_SCHED_MAX);
688
689 d_schedulingPolicy = value;
690
691 return *this;
692}
693
694inline
696{
697 d_schedulingPriority = value;
698
699 return *this;
700}
701
702inline
704{
706
707 BSLS_ASSERT_SAFE(-1 <= value);
708
709 d_stackSize = value;
710
711 return *this;
712}
713
714inline
716 const bslstl::StringRef& value)
717{
718 d_threadName.assign(value);
719
720 return *this;
721}
722
723// ACCESSORS
724inline
726{
727 return d_detachedState;
728}
729
730inline
732{
733 return d_guardSize;
734}
735
736inline
738{
739 return d_inheritScheduleFlag;
740}
741
742inline
744{
745 return d_schedulingPolicy;
746}
747
748inline
750{
751 return d_schedulingPriority;
752}
753
754inline
756{
757 return d_stackSize;
758}
759
760inline
762{
763 return d_threadName;
764}
765
766 // Aspects
767
768inline
770{
771 return d_threadName.get_allocator().mechanism();
772}
773
774} // close package namespace
775
776// FREE OPERATORS
777inline
778bsl::ostream& bslmt::operator<<(bsl::ostream& stream,
779 const bslmt::ThreadAttributes& object)
780{
781 return object.print(stream, 0, -1);
782}
783
784
785
786#endif
787
788// ----------------------------------------------------------------------------
789// Copyright 2020 Bloomberg Finance L.P.
790//
791// Licensed under the Apache License, Version 2.0 (the "License");
792// you may not use this file except in compliance with the License.
793// You may obtain a copy of the License at
794//
795// http://www.apache.org/licenses/LICENSE-2.0
796//
797// Unless required by applicable law or agreed to in writing, software
798// distributed under the License is distributed on an "AS IS" BASIS,
799// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
800// See the License for the specific language governing permissions and
801// limitations under the License.
802// ----------------------------- END-OF-FILE ----------------------------------
803
804/** @} */
805/** @} */
806/** @} */
Definition bslstl_string.h:1281
basic_string & assign(const basic_string &replacement)
Definition bslstl_string.h:5716
allocator_type get_allocator() const BSLS_KEYWORD_NOEXCEPT
Return the allocator used by this string to supply memory.
Definition bslstl_string.h:6723
Definition bslma_allocator.h:457
Definition bslmt_threadattributes.h:356
bslstl::StringRef threadName() const
Definition bslmt_threadattributes.h:761
int schedulingPriority() const
Definition bslmt_threadattributes.h:749
bslma::Allocator * allocator() const
Return the allocator used by this object to supply memory.
Definition bslmt_threadattributes.h:769
SchedulingPolicy schedulingPolicy() const
Definition bslmt_threadattributes.h:743
int guardSize() const
Definition bslmt_threadattributes.h:731
int stackSize() const
Definition bslmt_threadattributes.h:755
ThreadAttributes & setThreadName(const bslstl::StringRef &value)
Definition bslmt_threadattributes.h:715
SchedulingPolicy
Definition bslmt_threadattributes.h:376
@ e_SCHED_FIFO
Definition bslmt_threadattributes.h:383
@ BCEMT_SCHED_DEFAULT
Definition bslmt_threadattributes.h:393
@ BCEMT_SCHED_OTHER
Definition bslmt_threadattributes.h:390
@ e_SCHED_RR
Definition bslmt_threadattributes.h:385
@ e_SCHED_OTHER
Definition bslmt_threadattributes.h:380
@ e_SCHED_DEFAULT
Definition bslmt_threadattributes.h:387
@ BCEMT_SCHED_FIFO
Definition bslmt_threadattributes.h:391
@ BCEMT_SCHED_RR
Definition bslmt_threadattributes.h:392
ThreadAttributes & operator=(const ThreadAttributes &rhs)
ThreadAttributes & setGuardSize(int value)
Definition bslmt_threadattributes.h:663
BSLMF_NESTED_TRAIT_DECLARATION(ThreadAttributes, bslma::UsesBslmaAllocator)
ThreadAttributes & setInheritSchedule(bool value)
Definition bslmt_threadattributes.h:675
ThreadAttributes & setSchedulingPriority(int value)
Definition bslmt_threadattributes.h:695
ThreadAttributes & setStackSize(int value)
Definition bslmt_threadattributes.h:703
DetachedState
Definition bslmt_threadattributes.h:363
@ BCEMT_CREATE_JOINABLE
Definition bslmt_threadattributes.h:369
@ CREATE_DETACHED
Definition bslmt_threadattributes.h:372
@ BCEMT_CREATE_DETACHED
Definition bslmt_threadattributes.h:370
@ e_CREATE_JOINABLE
Definition bslmt_threadattributes.h:365
@ CREATE_JOINABLE
Definition bslmt_threadattributes.h:371
@ e_CREATE_DETACHED
Definition bslmt_threadattributes.h:366
DetachedState detachedState() const
Definition bslmt_threadattributes.h:725
ThreadAttributes & setDetachedState(DetachedState value)
Definition bslmt_threadattributes.h:651
ThreadAttributes(const ThreadAttributes &original, bslma::Allocator *basicAllocator=0)
ThreadAttributes & setSchedulingPolicy(SchedulingPolicy value)
Definition bslmt_threadattributes.h:683
bool inheritSchedule() const
Definition bslmt_threadattributes.h:737
ThreadAttributes(bslma::Allocator *basicAllocator)
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
@ e_SCHED_MIN
Definition bslmt_threadattributes.h:408
@ BCEMT_UNSET_STACK_SIZE
Definition bslmt_threadattributes.h:411
@ BCEMT_SCHED_MIN
Definition bslmt_threadattributes.h:414
@ e_SCHED_MAX
Definition bslmt_threadattributes.h:409
@ e_UNSET_GUARD_SIZE
Definition bslmt_threadattributes.h:405
@ BCEMT_SCHED_MAX
Definition bslmt_threadattributes.h:415
@ BCEMT_UNSET_PRIORITY
Definition bslmt_threadattributes.h:413
@ e_UNSET_PRIORITY
Definition bslmt_threadattributes.h:406
@ e_UNSET_STACK_SIZE
Definition bslmt_threadattributes.h:404
@ BCEMT_UNSET_GUARD_SIZE
Definition bslmt_threadattributes.h:412
Definition bslstl_stringref.h:372
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:229
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bslmt_barrier.h:344
bsl::ostream & operator<<(bsl::ostream &stream, const ThreadAttributes &object)
Definition bslma_usesbslmaallocator.h:343