Imported Upstream version 3.2.2
[debian/gnuradio] / usrp2 / host / lib / usrp2_thread.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008 Free Software Foundation, Inc.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22
23 #include "usrp2_thread.h"
24 #include "usrp2_impl.h"
25 #include <gruel/realtime.h>
26 #include <gruel/sys_pri.h>
27 #include <iostream>
28
29 #define USRP2_THREAD_DEBUG 1
30
31 namespace usrp2 {
32
33   usrp2_thread::usrp2_thread(usrp2::impl *u2) :
34     omni_thread(NULL, PRIORITY_HIGH),
35     d_u2(u2)
36   {
37   }
38   
39   usrp2_thread::~usrp2_thread()
40   {
41     // we don't own this, just forget it
42     d_u2 = 0;
43   }
44   
45   void
46   usrp2_thread::start()
47   {
48     start_undetached();
49   }
50   
51   void *
52   usrp2_thread::run_undetached(void *arg)
53   {
54     if (gruel::enable_realtime_scheduling(gruel::sys_pri::usrp2_backend()) != gruel::RT_OK)
55       std::cerr << "usrp2: failed to enable realtime scheduling" << std::endl;    
56
57     // This is the first code to run in the new thread context.
58     d_u2->bg_loop();
59     
60     return 0;
61   }
62
63 } // namespace usrp2
64