GNU Radio 3.6.5.1 C++ API
thread.h
Go to the documentation of this file.
1
/* -*- c++ -*- */
2
/*
3
* Copyright 2009-2012 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
#ifndef INCLUDED_THREAD_H
22
#define INCLUDED_THREAD_H
23
24
#include <
gruel/api.h
>
25
#include <boost/thread/thread.hpp>
26
#include <boost/thread/mutex.hpp>
27
#include <boost/thread/locks.hpp>
28
#include <boost/thread/condition_variable.hpp>
29
#include <vector>
30
31
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
32
33
#ifndef WIN32_LEAN_AND_MEAN
34
#define WIN32_LEAN_AND_MEAN
35
#endif
36
37
#include <windows.h>
38
39
#endif
40
41
namespace
gruel {
42
43
typedef
boost::thread
thread
;
44
typedef
boost::mutex
mutex
;
45
typedef
boost::unique_lock<boost::mutex>
scoped_lock
;
46
typedef
boost::condition_variable
condition_variable
;
47
48
/*! \brief a system-dependent typedef for the underlying thread type.
49
*/
50
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
51
typedef
HANDLE
gr_thread_t
;
52
#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
53
typedef
pthread_t
gr_thread_t
;
54
#else
55
typedef
pthread_t
gr_thread_t
;
56
#endif
57
58
/*! \brief Get the current thread's ID as a gr_thread_t
59
*
60
* We use this when setting the thread affinity or any other
61
* low-level thread settings. Can be called withing a GNU Radio
62
* block to get a reference to its current thread ID.
63
*/
64
GRUEL_API
gr_thread_t
get_current_thread_id
();
65
66
/*! \brief Bind the current thread to a set of cores.
67
*
68
* Wrapper for system-dependent calls to set the affinity of the
69
* current thread to the processor mask. The mask is simply a
70
* 1-demensional vector containing the processor or core number from
71
* 0 to N-1 for N cores.
72
*
73
* Note: this does not work on OSX; it is a nop call since OSX does
74
* not support the concept of thread affinity (and what they do
75
* support in this way since 10.5 is not what we want or can use in
76
* this fashion).
77
*/
78
GRUEL_API
void
thread_bind_to_processor
(
const
std::vector<int> &mask);
79
80
/*! \brief Convineince function to bind the current thread to a single core.
81
*
82
* Wrapper for system-dependent calls to set the affinity of the
83
* current thread to a given core from 0 to N-1 for N cores.
84
*
85
* Note: this does not work on OSX; it is a nop call since OSX does
86
* not support the concept of thread affinity (and what they do
87
* support in this way since 10.5 is not what we want or can use in
88
* this fashion).
89
*/
90
GRUEL_API
void
thread_bind_to_processor
(
int
n);
91
92
/*! \brief Bind a thread to a set of cores.
93
*
94
* Wrapper for system-dependent calls to set the affinity of the
95
* given thread ID to the processor mask. The mask is simply a
96
* 1-demensional vector containing the processor or core number from
97
* 0 to N-1 for N cores.
98
*
99
* Note: this does not work on OSX; it is a nop call since OSX does
100
* not support the concept of thread affinity (and what they do
101
* support in this way since 10.5 is not what we want or can use in
102
* this fashion).
103
*/
104
GRUEL_API
void
thread_bind_to_processor
(
gr_thread_t
thread
,
const
std::vector<int> &mask);
105
106
107
/*! \brief Convineince function to bind the a thread to a single core.
108
*
109
* Wrapper for system-dependent calls to set the affinity of the
110
* given thread ID to a given core from 0 to N-1 for N cores.
111
*
112
* Note: this does not work on OSX; it is a nop call since OSX does
113
* not support the concept of thread affinity (and what they do
114
* support in this way since 10.5 is not what we want or can use in
115
* this fashion).
116
*/
117
GRUEL_API
void
thread_bind_to_processor
(
gr_thread_t
thread
,
unsigned
int
n);
118
119
/*! \brief Remove any thread-processor affinity for the current thread.
120
*
121
* Note: this does not work on OSX; it is a nop call since OSX does
122
* not support the concept of thread affinity (and what they do
123
* support in this way since 10.5 is not what we want or can use in
124
* this fashion).
125
*/
126
GRUEL_API
void
thread_unbind
();
127
128
/*! \brief Remove any thread-processor affinity for a given thread ID.
129
*
130
* Note: this does not work on OSX; it is a nop call since OSX does
131
* not support the concept of thread affinity (and what they do
132
* support in this way since 10.5 is not what we want or can use in
133
* this fashion).
134
*/
135
GRUEL_API
void
thread_unbind
(
gr_thread_t
thread
);
136
137
}
/* namespace gruel */
138
139
#endif
/* INCLUDED_THREAD_H */
gruel
src
include
gruel
thread.h
Generated on Mon Aug 19 2013 15:37:31 for GNU Radio 3.6.5.1 C++ API by
1.8.1.2