1 // Copyright (c) 2007-2015 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_data_fwd.hpp 7 8 #if !defined(HPX_THREADS_THREAD_DATA_FWD_AUG_11_2015_0228PM) 9 #define HPX_THREADS_THREAD_DATA_FWD_AUG_11_2015_0228PM 10 11 #include <hpx/config.hpp> 12 #include <hpx/exception_fwd.hpp> 13 #include <hpx/runtime/threads/coroutines/coroutine_fwd.hpp> 14 #include <hpx/runtime/threads/thread_enums.hpp> 15 #include <hpx/runtime/threads/thread_id_type.hpp> 16 #include <hpx/util_fwd.hpp> 17 #include <hpx/util/function.hpp> 18 #include <hpx/util/unique_function.hpp> 19 #if defined(HPX_HAVE_APEX) 20 // forward declare the APEX object 21 namespace apex { struct task_wrapper; } 22 typedef std::shared_ptr<apex::task_wrapper> apex_task_wrapper; 23 #endif 24 25 #include <cstddef> 26 #include <cstdint> 27 #include <utility> 28 #include <memory> 29 30 namespace hpx 31 { 32 /// \cond NOINTERNAL 33 class HPX_EXPORT thread; 34 /// \endcond 35 } 36 37 namespace hpx { namespace threads 38 { 39 /// \cond NOINTERNAL 40 class HPX_EXPORT threadmanager; 41 struct HPX_EXPORT topology; 42 43 class HPX_EXPORT executor; 44 45 struct hpx_hwloc_bitmap_wrapper; 46 typedef std::shared_ptr<hpx_hwloc_bitmap_wrapper> hwloc_bitmap_ptr; 47 48 typedef coroutines::coroutine coroutine_type; 49 50 typedef coroutines::detail::coroutine_self thread_self; 51 typedef coroutines::detail::coroutine_impl thread_self_impl_type; 52 53 typedef std::pair<thread_state_enum, thread_id_type> thread_result_type; 54 typedef thread_state_ex_enum thread_arg_type; 55 56 typedef thread_result_type thread_function_sig(thread_arg_type); 57 typedef util::unique_function_nonser<thread_function_sig> thread_function_type; 58 /// \endcond 59 60 /////////////////////////////////////////////////////////////////////// 61 /// The function \a get_self returns a reference to the (OS thread 62 /// specific) self reference to the current HPX thread. 63 HPX_API_EXPORT thread_self& get_self(); 64 65 /// The function \a get_self_ptr returns a pointer to the (OS thread 66 /// specific) self reference to the current HPX thread. 67 HPX_API_EXPORT thread_self* get_self_ptr(); 68 69 /// The function \a get_ctx_ptr returns a pointer to the internal data 70 /// associated with each coroutine. 71 HPX_API_EXPORT thread_self_impl_type* get_ctx_ptr(); 72 73 /// The function \a get_self_ptr_checked returns a pointer to the (OS 74 /// thread specific) self reference to the current HPX thread. 75 HPX_API_EXPORT thread_self* get_self_ptr_checked(error_code& ec = throws); 76 77 /// The function \a get_self_id returns the HPX thread id of the current 78 /// thread (or zero if the current thread is not a HPX thread). 79 HPX_API_EXPORT thread_id_type get_self_id(); 80 81 /// The function \a get_parent_id returns the HPX thread id of the 82 /// current thread's parent (or zero if the current thread is not a 83 /// HPX thread). 84 /// 85 /// \note This function will return a meaningful value only if the 86 /// code was compiled with HPX_HAVE_THREAD_PARENT_REFERENCE 87 /// being defined. 88 HPX_API_EXPORT thread_id_type get_parent_id(); 89 90 /// The function \a get_parent_phase returns the HPX phase of the 91 /// current thread's parent (or zero if the current thread is not a 92 /// HPX thread). 93 /// 94 /// \note This function will return a meaningful value only if the 95 /// code was compiled with HPX_HAVE_THREAD_PARENT_REFERENCE 96 /// being defined. 97 HPX_API_EXPORT std::size_t get_parent_phase(); 98 99 /// The function \a get_self_stacksize returns the stack size of the 100 /// current thread (or zero if the current thread is not a HPX thread). 101 HPX_API_EXPORT std::size_t get_self_stacksize(); 102 103 /// The function \a get_parent_locality_id returns the id of the locality of 104 /// the current thread's parent (or zero if the current thread is not a 105 /// HPX thread). 106 /// 107 /// \note This function will return a meaningful value only if the 108 /// code was compiled with HPX_HAVE_THREAD_PARENT_REFERENCE 109 /// being defined. 110 HPX_API_EXPORT std::uint32_t get_parent_locality_id(); 111 112 /// The function \a get_self_component_id returns the lva of the 113 /// component the current thread is acting on 114 /// 115 /// \note This function will return a meaningful value only if the 116 /// code was compiled with HPX_HAVE_THREAD_TARGET_ADDRESS 117 /// being defined. 118 HPX_API_EXPORT std::uint64_t get_self_component_id(); 119 120 /// \cond NOINTERNAL 121 // The function get_thread_manager returns a reference to the 122 // current thread manager. 123 HPX_API_EXPORT threadmanager& get_thread_manager(); 124 /// \endcond 125 126 /// The function \a get_thread_count returns the number of currently 127 /// known threads. 128 /// 129 /// \param state [in] This specifies the thread-state for which the 130 /// number of threads should be retrieved. 131 /// 132 /// \note If state == unknown this function will not only return the 133 /// number of currently existing threads, but will add the number 134 /// of registered task descriptions (which have not been 135 /// converted into threads yet). 136 HPX_API_EXPORT std::int64_t get_thread_count( 137 thread_state_enum state = unknown); 138 139 /// The function \a get_thread_count returns the number of currently 140 /// known threads. 141 /// 142 /// \param priority [in] This specifies the thread-priority for which the 143 /// number of threads should be retrieved. 144 /// \param state [in] This specifies the thread-state for which the 145 /// number of threads should be retrieved. 146 /// 147 /// \note If state == unknown this function will not only return the 148 /// number of currently existing threads, but will add the number 149 /// of registered task descriptions (which have not been 150 /// converted into threads yet). 151 HPX_API_EXPORT std::int64_t get_thread_count( 152 thread_priority priority, thread_state_enum state = unknown); 153 154 /// The function \a enumerate_threads will invoke the given function \a f 155 /// for each thread with a matching thread state. 156 /// 157 /// \param f [in] The function which should be called for each 158 /// matching thread. Returning 'false' from this function 159 /// will stop the enumeration process. 160 /// \param state [in] This specifies the thread-state for which the 161 /// threads should be enumerated. 162 HPX_API_EXPORT bool enumerate_threads( 163 util::function_nonser<bool(thread_id_type)> const& f, 164 thread_state_enum state = unknown); 165 166 #if defined(HPX_HAVE_APEX) 167 HPX_API_EXPORT apex_task_wrapper get_self_apex_data(void); 168 HPX_API_EXPORT void set_self_apex_data(apex_task_wrapper data); 169 #endif 170 }} 171 172 #endif 173 174