blob: 0b0199b84eab90867464f8030207eb3cf3694fdf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
//
// Copyright 2012 Josh Blum
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <gnuradio/thread_pool.hpp>
#include <gras_impl/block_actor.hpp>
#include <Theron/Framework.h>
using namespace gnuradio;
/***********************************************************************
* Thread pool implementation
**********************************************************************/
ThreadPool::ThreadPool(void)
{
//NOP
}
ThreadPool::ThreadPool(boost::weak_ptr<Theron::Framework> p):
boost::shared_ptr<Theron::Framework>(p.lock())
{
//NOP
}
ThreadPool::ThreadPool(const unsigned long threadCount)
{
if (threadCount == 0) this->reset(new Theron::Framework(Theron::Framework::Parameters()));
else this->reset(new Theron::Framework(Theron::Framework::Parameters(threadCount)));
}
ThreadPool::ThreadPool(const unsigned long threadCount, const unsigned long nodeMask)
{
this->reset(new Theron::Framework(Theron::Framework::Parameters(threadCount, nodeMask)));
}
ThreadPool::ThreadPool(const unsigned long threadCount, const unsigned long nodeMask, const unsigned long processorMask)
{
this->reset(new Theron::Framework(Theron::Framework::Parameters(threadCount, nodeMask, processorMask)));
}
/***********************************************************************
* Active framework implementation
**********************************************************************/
static boost::weak_ptr<Theron::Framework> weak_framework;
void ThreadPool::set_active(void)
{
weak_framework = *this;
}
static ThreadPool active_thread_pool;
static ThreadPool get_active_thread_pool(void)
{
if (not weak_framework.lock())
{
active_thread_pool = ThreadPool(0);
active_thread_pool.set_active();
std::cout << "Created default thread pool with " << active_thread_pool->GetNumThreads() << " threads." << std::endl;
}
return weak_framework;
}
/***********************************************************************
* Block actor construction - gets active framework
**********************************************************************/
BlockActor::BlockActor(void):
Apology::Worker(*get_active_thread_pool())
{
thread_pool = get_active_thread_pool();
active_thread_pool.reset(); //actors hold this, now its safe to reset, weak_framework only
this->register_handlers();
}
BlockActor::~BlockActor(void)
{
this->mark_done();
}
|