11 #include <boost/chrono.hpp> 12 #include <LibCyberRadio/Common/Thread.h> 24 _thisThread = boost::thread();
31 _isRunning = src._isRunning;
40 _isRunning = src._isRunning;
47 if ( _thisThread.get_id() != boost::thread::id() )
49 _thisThread.interrupt();
56 _thisThread = boost::thread(&Thread::thisThreadRun,
this);
57 pthread_setname_np(_thisThread.native_handle(), this->_name.c_str());
62 _thisThread.interrupt();
67 uint64_t u_ms = (uint64_t)secs * 1000;
68 boost::chrono::microseconds ms(u_ms);
69 boost::this_thread::sleep_for(boost::chrono::microseconds(ms));
93 return _thisThread.get_id();
101 else if ( _class !=
"" )
103 std::ostringstream oss;
104 oss << _class <<
"-" << _thisThread.get_id();
114 void Thread::thisThreadRun()
121 catch(boost::thread_interrupted& ex)
125 catch(std::exception& ex)
130 _thisThread = boost::thread();
virtual std::string getIdString() const
Gets the identifier string for this thread.
Thread(const std::string &name="", const std::string &cls="")
Creates a Thread object.
virtual bool isRunning() const
Determines if the thread is running or not.
virtual void run()=0
Executes the main processing loop for the thread.
virtual boost::thread::id getId() const
Gets the identifier of the underlying Boost thread.
virtual void interrupt()
Interrupts (stops) the thread.
virtual void start()
Starts thread processing.
virtual ~Thread()
Destroys a Thread object.
virtual void setClass(const std::string &cls)
Sets the class identifer string for the thread.
virtual Thread & operator=(const Thread &src)
Creates a Thread object by assignment from another Thread object.
Defines functionality for LibCyberRadio applications.
virtual void setName(const std::string &name)
Sets the name of the thread.
virtual void onException(const std::exception &ex)
Executes code that must run when an unhandled exception occurs within the thread. ...
Base class for a thread object, based on Boost Threads.
virtual void sleep(double secs)
Pauses thread execution for a given time, checking for user interrupts during that time...
virtual void onInterrupt()
Executes code that must run when the thread is interrupted.