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