Browse Source

AP_HAL_Linux: Thread: allow to override run method

master
Lucas De Marchi 9 years ago
parent
commit
66e6cd60d8
  1. 14
      libraries/AP_HAL_Linux/Thread.cpp
  2. 7
      libraries/AP_HAL_Linux/Thread.h

14
libraries/AP_HAL_Linux/Thread.cpp

@ -33,12 +33,22 @@ namespace Linux { @@ -33,12 +33,22 @@ namespace Linux {
void *Thread::_run_trampoline(void *arg)
{
Thread *thread = static_cast<Thread *>(arg);
thread->_task();
thread->_run();
return nullptr;
}
bool Thread::_run()
{
if (!_task) {
return false;
}
_task();
return true;
}
bool Thread::start(const char *name, int policy, int prio)
{
if (_started) {

7
libraries/AP_HAL_Linux/Thread.h

@ -43,6 +43,13 @@ public: @@ -43,6 +43,13 @@ public:
protected:
static void *_run_trampoline(void *arg);
/*
* Run the task assigned in the constructor. May be overriden in case it's
* preferred to use Thread as an interface or when user wants to aggregate
* some initialization or teardown for the thread.
*/
virtual bool _run();
task_t _task;
bool _started;
pthread_t _ctx;

Loading…
Cancel
Save