25 #if( defined( __linux__ ) && !defined( __ANDROID__ ) )
26 #include <sys/prctl.h>
32 #include "exceptions/WSignalSubscriptionFailed.h"
33 #include "WCondition.h"
34 #include "WConditionOneShot.h"
35 #include "WException.h"
37 #include "WThreadedRunner.h"
65 wlog::error( sender ) <<
"WException. Notifying. Message: " << e.
what();
120 catch(
const std::exception& e )
142 boost::this_thread::sleep( boost::posix_time::seconds( t ) );
147 boost::this_thread::sleep( boost::posix_time::microseconds( t ) );
177 #if( defined( __linux__ ) && !defined( __ANDROID__ ) )
181 prctl( PR_SET_NAME, (
"openwalnut (" + name +
")" ).c_str() );
Implements a WCondition, but can be fired only ONCE.
virtual const char * what() const
Returns the message string set on throw.
virtual void wait() const
Wait for the flag to change its value.
void addLogMessage(std::string message, std::string source="", LogLevel level=LL_DEBUG)
Appends a log message to the logging queue.
static WLogger * getLogger()
Returns pointer to the currently running logger instance.
General purpose exception and therefore base class for all kernel related exceptions.
void msleep(const int32_t t) const
Sets thread asleep.
virtual boost::signals2::connection subscribeSignal(THREAD_SIGNAL signal, t_ThreadErrorSignalHandlerType notifier)
Connects a specified notify function with a signal this thread instance is offering.
virtual void run()
Run thread.
void threadMainSave()
The is the thread entry point.
void yield() const
Give remaining execution timeslice to another thread.
boost::function< void(void) > THREADFUNCTION
Type used for simple thread functions.
const std::string & getCrashMessage() const
Get the message of the exception finally causing the crash.
std::string m_threadName
This threads name.
virtual void threadMain()
Function that has to be overwritten for execution.
std::string getThreadName() const
Returns the current thread name.
void setThreadName(std::string name)
Set the name of the thread.
std::string m_crashMessage
The crash message.
static void setThisThreadName(std::string name)
Static function to set the name of the calling thread.
void sleep(const int32_t t) const
Sets thread asleep.
void handleDeadlyException(const WException &e, std::string sender="WThreadedRunner")
Handle the specified exception which was not caught in the thread, which basically means the thread h...
WThreadedRunner()
Default constructor.
void waitForStop()
Let the thread sleep until a stop request was given.
virtual void requestStop()
This method's purpose is to request a stop without waiting for it.
virtual ~WThreadedRunner()
Destructor.
void wait(bool requestFinish=false)
Wait for the thread to be finished.
virtual void notifyStop()
Gets called when the thread should be stopped.
boost::thread m_thread
Thread instance.
WBoolFlag m_isCrashed
True whenever an exception is thrown during threadMain.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
t_ThreadErrorSignalType signal_thread_error
Signal fired whenever a thread throws an exception/error.
const WBoolFlag & isCrashed() const
Checks whether this thread has been crashed.
virtual void onThreadException(const WException &e)
This method is called if an exception was caught, which came from the custom thread code.
WStreamedLogger error(const std::string &source)
Logging an error message.