18 #ifndef RAUL_THREAD_HPP
19 #define RAUL_THREAD_HPP
27 #include <boost/utility.hpp>
48 static Thread* create(
const std::string& name=
"")
49 {
return new Thread(name); }
53 {
return new Thread(pthread_self(), name); }
62 void set_scheduling(
int policy,
unsigned int priority);
64 const std::string& name()
const {
return _name; }
65 void set_name(
const std::string& name) { _name = name; }
67 bool is_context(
unsigned context)
const {
return _contexts.find(context) != _contexts.end(); }
68 void set_context(
unsigned context) { _contexts.insert(context); }
71 explicit Thread(
const std::string& name=
"");
72 Thread(pthread_t thread,
const std::string& name=
"");
87 static void* _static_run(
void* me);
90 static void thread_key_alloc() {
91 pthread_key_create(&_thread_key, NULL);
95 static pthread_key_t _thread_key;
98 static pthread_once_t _thread_key_once;
100 std::set<unsigned> _contexts;
102 bool _pthread_exists;
110 #endif // RAUL_THREAD_HPP
virtual void stop()
Stop and terminate the thread.
Definition: Thread.cpp:103
Abstract base class for a thread.
Definition: Thread.hpp:41
static Thread * create_for_this_thread(const std::string &name="")
Must be called from thread.
Definition: Thread.hpp:52
virtual void start()
Launch and start the thread.
Definition: Thread.cpp:87
virtual void _run()
Thread function to execute.
Definition: Thread.hpp:82