/home/users/khuck/src/hpx-lsu/hpx/runtime/threads/detail/create_thread.hpp

Line% of fetchesSource
1  
//  Copyright (c) 2007-2013 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  
#if !defined(HPX_RUNTIME_THREADS_DETAIL_CREATE_THREAD_JAN_13_2013_0439PM)
7  
#define HPX_RUNTIME_THREADS_DETAIL_CREATE_THREAD_JAN_13_2013_0439PM
8  
9  
#include <hpx/config.hpp>
10  
#include <hpx/runtime/threads/policies/scheduler_base.hpp>
11  
#include <hpx/runtime/threads/thread_data.hpp>
12  
#include <hpx/runtime/threads/thread_init_data.hpp>
13  
#include <hpx/throw_exception.hpp>
14  
#include <hpx/util/logging.hpp>
15  
16  
#include <cstddef>
17  
#include <sstream>
18  
19  
namespace hpx { namespace threads { namespace detail
20  
{
21  
    inline void create_thread(
22  
        policies::scheduler_base* scheduler, thread_init_data& data,
23  
        threads::thread_id_type& id,
24  
        thread_state_enum initial_state = pending,
25  
        bool run_now = true, error_code& ec = throws)
26  
    {
27  
        // verify parameters
28  
        switch (initial_state) {
29  
        case pending:
30  
        case pending_do_not_schedule:
31  
        case suspended:
32  
            break;
33  
34  
        default:
35  
            {
36  
                std::ostringstream strm;
37  
                strm << "invalid initial state: "
38  
                     << get_thread_state_name(initial_state);
39  
                HPX_THROWS_IF(ec, bad_parameter,
40  
                    "threads::detail::create_thread",
41  
                    strm.str());
42  
                return;
43  
            }
44  
        }
45  
46  
#ifdef HPX_HAVE_THREAD_DESCRIPTION
47  
        if (!data.description)
48  
        {
49  
            HPX_THROWS_IF(ec, bad_parameter,
50  
                "threads::detail::create_thread", "description is nullptr");
51  
            return;
52  
        }
53  
#endif
54  
55  
        thread_self* self = get_self_ptr();
56  
57  
#ifdef HPX_HAVE_THREAD_PARENT_REFERENCE
58  
        if (nullptr == data.parent_id) {
59  
            if (self)
60  
            {
61  
                data.parent_id = threads::get_self_id().get();
62  
                data.parent_phase = self->get_thread_phase();
63  
            }
64  
        }
65  
        if (0 == data.parent_locality_id)
66  
            data.parent_locality_id = get_locality_id();
67  
#endif
68  
69  
        if (nullptr == data.scheduler_base)
70  
            data.scheduler_base = scheduler;
71  
72  
        // Pass critical priority from parent to child.
73  
        if (self)
74  
        {
75  
            if (thread_priority_critical == threads::get_self_id()->get_priority())
76  
                data.priority = thread_priority_critical;
77  
        }
78  
79  
        // create the new thread
80  
        std::size_t num_thread = data.num_os_thread;
81  
        scheduler->create_thread(data, &id, initial_state, run_now, ec, num_thread);
82  
83  
        LTM_(info) << "register_thread(" << id << "): initial_state("
84  
                   << get_thread_state_name(initial_state) << "), "
85  
                   << "run_now(" << (run_now ? "true" : "false")
86  
#ifdef HPX_HAVE_THREAD_DESCRIPTION
87  
                   << "), description(" << data.description
88  
#endif
89  
                   << ")";
90  
91  
        // potentially wake up waiting thread
92  
        scheduler->do_some_work(num_thread);
93  
    }
94  
}}}
95  
96  
#endif
97  
98  

Copyright (c) 2006-2012 Rogue Wave Software, Inc. All Rights Reserved.
Patents pending.