GNU Radio C++ API Reference  g65ab7ea
The Free & Open Software Radio Ecosystem
thread.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2009-2014 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef INCLUDED_THREAD_H
12 #define INCLUDED_THREAD_H
13 
14 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
15 #ifndef WIN32_LEAN_AND_MEAN
16 #define WIN32_LEAN_AND_MEAN
17 #endif
18 #include <windows.h>
19 #endif
20 
21 #include <gnuradio/api.h>
22 #include <boost/thread/barrier.hpp>
23 #include <boost/thread/condition_variable.hpp>
24 #include <boost/thread/locks.hpp>
25 #include <boost/thread/mutex.hpp>
26 #include <boost/thread/thread.hpp>
27 #include <memory>
28 #include <vector>
29 
30 namespace gr {
31 namespace thread {
32 
35 typedef boost::unique_lock<boost::mutex> scoped_lock;
38 typedef std::shared_ptr<barrier> barrier_sptr;
39 
40 /*! \brief a system-dependent typedef for the underlying thread type.
41  */
42 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
43 typedef HANDLE gr_thread_t;
44 #elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
45 typedef pthread_t gr_thread_t;
46 #else
47 typedef pthread_t gr_thread_t;
48 #endif
49 
50 /*! \brief Get the current thread's ID as a gr_thread_t
51  *
52  * We use this when setting the thread affinity or any other
53  * low-level thread settings. Can be called within a GNU Radio
54  * block to get a reference to its current thread ID.
55  */
57 
58 /*! \brief Bind the current thread to a set of cores.
59  *
60  * Wrapper for system-dependent calls to set the affinity of the
61  * current thread to the processor mask. The mask is simply a
62  * 1-demensional vector containing the processor or core number
63  * from 0 to N-1 for N cores.
64  *
65  * Note: this does not work on OSX; it is a nop call since OSX
66  * does not support the concept of thread affinity (and what they
67  * do support in this way since 10.5 is not what we want or can
68  * use in this fashion).
69  */
70 GR_RUNTIME_API void thread_bind_to_processor(const std::vector<int>& mask);
71 
72 /*! \brief Convineince function to bind the current thread to a single core.
73  *
74  * Wrapper for system-dependent calls to set the affinity of the
75  * current thread to a given core from 0 to N-1 for N cores.
76  *
77  * Note: this does not work on OSX; it is a nop call since OSX
78  * does not support the concept of thread affinity (and what they
79  * do support in this way since 10.5 is not what we want or can
80  * use in this fashion).
81  */
83 
84 /*! \brief Bind a thread to a set of cores.
85  *
86  * Wrapper for system-dependent calls to set the affinity of the
87  * given thread ID to the processor mask. The mask is simply a
88  * 1-demensional vector containing the processor or core number
89  * from 0 to N-1 for N cores.
90  *
91  * Note: this does not work on OSX; it is a nop call since OSX
92  * does not support the concept of thread affinity (and what they
93  * do support in this way since 10.5 is not what we want or can
94  * use in this fashion).
95  */
97  const std::vector<int>& mask);
98 
99 
100 /*! \brief Convineince function to bind the a thread to a single core.
101  *
102  * Wrapper for system-dependent calls to set the affinity of the
103  * given thread ID to a given core from 0 to N-1 for N cores.
104  *
105  * Note: this does not work on OSX; it is a nop call since OSX
106  * does not support the concept of thread affinity (and what they
107  * do support in this way since 10.5 is not what we want or can
108  * use in this fashion).
109  */
111 
112 /*! \brief Remove any thread-processor affinity for the current thread.
113  *
114  * Note: this does not work on OSX; it is a nop call since OSX
115  * does not support the concept of thread affinity (and what they
116  * do support in this way since 10.5 is not what we want or can
117  * use in this fashion).
118  */
120 
121 /*! \brief Remove any thread-processor affinity for a given thread ID.
122  *
123  * Note: this does not work on OSX; it is a nop call since OSX
124  * does not support the concept of thread affinity (and what they
125  * do support in this way since 10.5 is not what we want or can
126  * use in this fashion).
127  */
129 
130 /*! \brief get current thread priority for a given thread ID
131  */
133 
134 /*! \brief set current thread priority for a given thread ID
135  */
137 
139 
140 } /* namespace thread */
141 } /* namespace gr */
142 
143 #endif /* INCLUDED_THREAD_H */
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:18
boost::barrier barrier
Definition: thread.h:37
boost::mutex mutex
Definition: thread.h:34
boost::unique_lock< boost::mutex > scoped_lock
Definition: thread.h:35
GR_RUNTIME_API void set_thread_name(gr_thread_t thread, std::string name)
GR_RUNTIME_API int thread_priority(gr_thread_t thread)
get current thread priority for a given thread ID
GR_RUNTIME_API int set_thread_priority(gr_thread_t thread, int priority)
set current thread priority for a given thread ID
GR_RUNTIME_API void thread_unbind()
Remove any thread-processor affinity for the current thread.
boost::thread thread
Definition: thread.h:33
pthread_t gr_thread_t
a system-dependent typedef for the underlying thread type.
Definition: thread.h:47
GR_RUNTIME_API void thread_bind_to_processor(const std::vector< int > &mask)
Bind the current thread to a set of cores.
boost::condition_variable condition_variable
Definition: thread.h:36
GR_RUNTIME_API gr_thread_t get_current_thread_id()
Get the current thread's ID as a gr_thread_t.
GNU Radio logging wrapper.
Definition: basic_block.h:29