1 //  Copyright (c) 2007-2016 Hartmut Kaiser
2 //
3 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 /// \file hpx/runtime/threads/thread_enums.hpp
7 
8 #if !defined(HPX_THREAD_ENUMS_JUL_23_2015_0852PM)
9 #define HPX_THREAD_ENUMS_JUL_23_2015_0852PM
10 
11 #include <hpx/config.hpp>
12 #include <hpx/runtime/threads/detail/combined_tagged_state.hpp>
13 
14 #include <cstddef>
15 #include <cstdint>
16 
17 namespace hpx { namespace threads
18 {
19     ///////////////////////////////////////////////////////////////////////////
20     /// \enum thread_state_enum
21     ///
22     /// The \a thread_state_enum enumerator encodes the current state of a
23     /// \a thread instance
24     enum thread_state_enum
25     {
26         unknown = 0,
27         active = 1,         /*!< thread is currently active (running,
28                                  has resources) */
29         pending = 2,        /*!< thread is pending (ready to run, but
30                                  no hardware resource available) */
31         suspended = 3,      /*!< thread has been suspended (waiting for
32                                  synchronization event, but still
33                                  known and under control of the
34                                  thread-manager) */
35         depleted = 4,       /*!< thread has been depleted (deeply
36                                  suspended, it is not known to the
37                                  thread-manager) */
38         terminated = 5,     /*!< thread has been stopped an may be
39                                  garbage collected */
40         staged = 6,         /*!< this is not a real thread state, but
41                                  allows to reference staged task descriptions,
42                                  which eventually will be converted into
43                                  thread objects */
44         pending_do_not_schedule = 7, /*< this is not a real thread state,
45                                  but allows to create a thread in pending state
46                                  without scheduling it (internal, do not use) */
47         pending_boost = 8   /*< this is not a real thread state,
48                                  but allows to suspend a thread in pending state
49                                  without high priority rescheduling */
50     };
51 
52     /// Get the readable string representing the name of the given
53     /// thread_state constant.
54     HPX_API_EXPORT char const* get_thread_state_name(thread_state_enum state);
55 
56     ///////////////////////////////////////////////////////////////////////////
57     /// This enumeration lists all possible thread-priorities for HPX threads.
58     ///
59     enum thread_priority
60     {
61         thread_priority_unknown = -1,
62         thread_priority_default = 0,      /*!< Will assign the priority of the
63             task to the default (normal) priority. */
64         thread_priority_low = 1,          /*!< Task goes onto a special low
65             priority queue and will not be executed until all high/normal
66             priority tasks are done, even if they are added after the low
67             priority task. */
68         thread_priority_normal = 2,       /*!< Task will be executed when it is
69             taken from the normal priority queue, this is usually a first
70             in-first-out ordering of tasks (depending on scheduler choice).
71             This is the default priority. */
72         thread_priority_high_recursive = 3, /*!< The task is a high priority
73             task and any child tasks spawned by this task will be made high
74             priority as well - unless they are specifically flagged as non
75             default priority. */
76         thread_priority_boost = 4,        /*!< Same as \a thread_priority_high
77             except that the thread will fall back to \a thread_priority_normal
78             if resumed after being suspended. */
79         thread_priority_high = 5,         /*!< Task goes onto a special high
80             priority queue and will be executed before normal/low priority
81             tasks are taken (some schedulers modify the behavior slightly and
82             the documentation for those should be consulted). */
83 
84         /// \cond NOINTERNAL
85         // obsolete, kept for compatibility only
86         thread_priority_critical = thread_priority_high_recursive,
87         /// \endcond
88     };
89 
90     /// Get the readable string representing the name of the given thread_priority
91     /// constant.
92     HPX_API_EXPORT char const* get_thread_priority_name(thread_priority priority);
93 
94     ///////////////////////////////////////////////////////////////////////////
95     /// \enum thread_state_ex_enum
96     ///
97     /// The \a thread_state_ex_enum enumerator encodes the reason why a
98     /// thread is being restarted
99     enum thread_state_ex_enum
100     {
101         wait_unknown = 0,
102         wait_signaled = 1,  ///< The thread has been signaled
103         wait_timeout = 2,   ///< The thread has been reactivated after a timeout
104         wait_terminate = 3, ///< The thread needs to be terminated
105         wait_abort = 4      ///< The thread needs to be aborted
106     };
107 
108     /// Get the readable string representing the name of the given
109     /// thread_state_ex_enum constant.
110     HPX_API_EXPORT char const* get_thread_state_ex_name(thread_state_ex_enum state);
111 
112     /// \cond NOINTERNAL
113     // special type storing both state in one tagged structure
114     typedef threads::detail::combined_tagged_state<
115             thread_state_enum, thread_state_ex_enum
116         > thread_state;
117     /// \endcond
118 
119     /// Get the readable string representing the name of the given
120     /// thread_state constant.
121     HPX_API_EXPORT char const* get_thread_state_name(thread_state state);
122 
123     ///////////////////////////////////////////////////////////////////////////
124     /// \enum thread_stacksize
125     ///
126     /// A \a thread_stacksize references any of the possible stack-sizes for
127     /// HPX threads.
128     enum thread_stacksize
129     {
130         thread_stacksize_unknown = -1,
131         thread_stacksize_small = 1,         ///< use small stack size
132         thread_stacksize_medium = 2,        ///< use medium sized stack size
133         thread_stacksize_large = 3,         ///< use large stack size
134         thread_stacksize_huge = 4,          ///< use very large stack size
135 
136         thread_stacksize_current = 5,      ///< use size of current thread's stack
137 
138         thread_stacksize_default = thread_stacksize_small,  ///< use default stack size
139         thread_stacksize_minimal = thread_stacksize_small,  ///< use minimally stack size
140         thread_stacksize_maximal = thread_stacksize_huge,   ///< use maximally stack size
141     };
142 
143     /// Get the readable string representing the given stack size
144     /// constant.
145     HPX_API_EXPORT char const* get_stack_size_name(std::ptrdiff_t size);
146 
147     ///////////////////////////////////////////////////////////////////////////
148     /// \enum thread_schedule_hint_mode
149     ///
150     /// The type of hint given when creating new tasks.
151     enum thread_schedule_hint_mode : std::int16_t
152     {
153         thread_schedule_hint_mode_none = 0,
154         thread_schedule_hint_mode_thread = 1,
155         thread_schedule_hint_mode_numa = 2,
156     };
157 
158     ///////////////////////////////////////////////////////////////////////////
159     struct thread_schedule_hint
160     {
thread_schedule_hinthpx::threads::thread_schedule_hint161         thread_schedule_hint()
162           : mode(thread_schedule_hint_mode_none)
163           , hint(-1)
164         {}
165 
thread_schedule_hinthpx::threads::thread_schedule_hint166         thread_schedule_hint(std::int16_t thread_hint)
167           : mode(thread_schedule_hint_mode_thread)
168           , hint(thread_hint)
169         {}
170 
thread_schedule_hinthpx::threads::thread_schedule_hint171         thread_schedule_hint(thread_schedule_hint_mode mode, std::int16_t hint)
172           : mode(mode)
173           , hint(hint)
174         {}
175 
176         thread_schedule_hint_mode mode;
177         std::int16_t hint;
178     };
179 }}
180 
181 #endif
182