GNU Radio 3.7.0-50 C++ API
thread.h
Go to the documentation of this file.
1
/* -*- c++ -*- */
2
/*
3
* Copyright 2009-2013 Free Software Foundation, Inc.
4
*
5
* This file is part of GNU Radio
6
*
7
* GNU Radio is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 3, or (at your option)
10
* any later version.
11
*
12
* GNU Radio is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License along
18
* with this program; if not, write to the Free Software Foundation, Inc.,
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
*/
21
22
#ifndef INCLUDED_THREAD_H
23
#define INCLUDED_THREAD_H
24
25
#include <
gnuradio/api.h
>
26
#include <boost/thread/thread.hpp>
27
#include <boost/thread/mutex.hpp>
28
#include <boost/thread/locks.hpp>
29
#include <boost/thread/condition_variable.hpp>
30
#include <vector>
31
32
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
33
34
#ifndef WIN32_LEAN_AND_MEAN
35
#define WIN32_LEAN_AND_MEAN
36
#endif
37
38
#include <windows.h>
39
40
#endif
41
42
namespace
gr {
43
namespace
thread
{
44
45
typedef
boost::thread
thread
;
46
typedef
boost::mutex
mutex
;
47
typedef
boost::unique_lock<boost::mutex>
scoped_lock
;
48
typedef
boost::condition_variable
condition_variable
;
49
50
/*! \brief a system-dependent typedef for the underlying thread type.
51
*/
52
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
53
typedef
HANDLE
gr_thread_t
;
54
#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
55
typedef
pthread_t
gr_thread_t
;
56
#else
57
typedef
pthread_t
gr_thread_t
;
58
#endif
59
60
/*! \brief Get the current thread's ID as a gr_thread_t
61
*
62
* We use this when setting the thread affinity or any other
63
* low-level thread settings. Can be called withing a GNU Radio
64
* block to get a reference to its current thread ID.
65
*/
66
GR_RUNTIME_API
gr_thread_t
get_current_thread_id
();
67
68
/*! \brief Bind the current thread to a set of cores.
69
*
70
* Wrapper for system-dependent calls to set the affinity of the
71
* current thread to the processor mask. The mask is simply a
72
* 1-demensional vector containing the processor or core number
73
* from 0 to N-1 for N cores.
74
*
75
* Note: this does not work on OSX; it is a nop call since OSX
76
* does not support the concept of thread affinity (and what they
77
* do support in this way since 10.5 is not what we want or can
78
* use in this fashion).
79
*/
80
GR_RUNTIME_API
void
thread_bind_to_processor
(
const
std::vector<int> &mask);
81
82
/*! \brief Convineince function to bind the current thread to a single core.
83
*
84
* Wrapper for system-dependent calls to set the affinity of the
85
* current thread to a given core from 0 to N-1 for N cores.
86
*
87
* Note: this does not work on OSX; it is a nop call since OSX
88
* does not support the concept of thread affinity (and what they
89
* do support in this way since 10.5 is not what we want or can
90
* use in this fashion).
91
*/
92
GR_RUNTIME_API
void
thread_bind_to_processor
(
int
n);
93
94
/*! \brief Bind a thread to a set of cores.
95
*
96
* Wrapper for system-dependent calls to set the affinity of the
97
* given thread ID to the processor mask. The mask is simply a
98
* 1-demensional vector containing the processor or core number
99
* from 0 to N-1 for N cores.
100
*
101
* Note: this does not work on OSX; it is a nop call since OSX
102
* does not support the concept of thread affinity (and what they
103
* do support in this way since 10.5 is not what we want or can
104
* use in this fashion).
105
*/
106
GR_RUNTIME_API
void
thread_bind_to_processor
(
gr_thread_t
thread
,
107
const
std::vector<int> &mask);
108
109
110
/*! \brief Convineince function to bind the a thread to a single core.
111
*
112
* Wrapper for system-dependent calls to set the affinity of the
113
* given thread ID to a given core from 0 to N-1 for N cores.
114
*
115
* Note: this does not work on OSX; it is a nop call since OSX
116
* does not support the concept of thread affinity (and what they
117
* do support in this way since 10.5 is not what we want or can
118
* use in this fashion).
119
*/
120
GR_RUNTIME_API
void
thread_bind_to_processor
(
gr_thread_t
thread
,
121
unsigned
int
n);
122
123
/*! \brief Remove any thread-processor affinity for the current thread.
124
*
125
* Note: this does not work on OSX; it is a nop call since OSX
126
* does not support the concept of thread affinity (and what they
127
* do support in this way since 10.5 is not what we want or can
128
* use in this fashion).
129
*/
130
GR_RUNTIME_API
void
thread_unbind
();
131
132
/*! \brief Remove any thread-processor affinity for a given thread ID.
133
*
134
* Note: this does not work on OSX; it is a nop call since OSX
135
* does not support the concept of thread affinity (and what they
136
* do support in this way since 10.5 is not what we want or can
137
* use in this fashion).
138
*/
139
GR_RUNTIME_API
void
thread_unbind
(
gr_thread_t
thread
);
140
141
/*! \brief get current thread priority for a given thread ID
142
*
143
* Note: this does not work on OSX
144
*/
145
GR_RUNTIME_API
int
thread_priority
(
gr_thread_t
thread
);
146
147
/*! \brief get current thread priority for a given thread ID
148
*
149
* Note: this does not work on OSX
150
*/
151
GR_RUNTIME_API
int
set_thread_priority
(
gr_thread_t
thread
,
int
priority);
152
153
}
/* namespace thread */
154
}
/* namespace gr */
155
156
#endif
/* INCLUDED_THREAD_H */
gnuradio
gnuradio-runtime
include
gnuradio
thread
thread.h
Generated by
1.8.1.2