don't fail on multiple Start calls (#1396)

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2020-05-05 12:45:07 -07:00 committed by GitHub
parent 8d670c59ca
commit a26355fdd1
1 changed files with 7 additions and 0 deletions

View File

@ -25,6 +25,7 @@ class ThreadController : public ControllerBase
private: private:
THD_WORKING_AREA(m_threadstack, TStackSize); THD_WORKING_AREA(m_threadstack, TStackSize);
const tprio_t m_prio; const tprio_t m_prio;
bool m_isStarted = false;
/** /**
* The OS can only call a function with a single void* param. We have * The OS can only call a function with a single void* param. We have
@ -57,8 +58,14 @@ public:
*/ */
void Start() void Start()
{ {
if (m_isStarted) {
warning(CUSTOM_OBD_6003, "Tried to start thread %s but it was already running", GetName());
return;
}
m_thread = chThdCreateStatic(m_threadstack, sizeof(m_threadstack), m_prio, StaticThreadTaskAdapter, this); m_thread = chThdCreateStatic(m_threadstack, sizeof(m_threadstack), m_prio, StaticThreadTaskAdapter, this);
m_thread->name = GetName(); m_thread->name = GetName();
m_isStarted = true;
} }
}; };