|
|
@ -7,14 +7,22 @@ using namespace std; |
|
|
|
static void zosthread_default_task(void const *argument) { |
|
|
|
ZThread *thread = (ZThread *)argument; |
|
|
|
ZASSERT(thread); |
|
|
|
thread->m_threadisworkingFlag = false; |
|
|
|
thread->m_threadisWaitingForStopFlag = false; |
|
|
|
|
|
|
|
while (true) { |
|
|
|
thread->m_threadisworking = false; |
|
|
|
if (thread->m_threadisworkingFlagCallSide) { |
|
|
|
thread->m_threadisworkingFlag = true; |
|
|
|
thread->m_taskfunction(); |
|
|
|
|
|
|
|
// µÈ´ýtaskworking
|
|
|
|
xEventGroupWaitBits(thread->m_zthreadstartworkevent, 0x01, pdTRUE, pdTRUE, portMAX_DELAY); |
|
|
|
thread->m_threadisworking = true; |
|
|
|
thread->m_taskfunction(); |
|
|
|
thread->m_threadisWaitingForStopFlag = true; |
|
|
|
while (thread->m_threadisworkingFlagCallSide) { |
|
|
|
vTaskDelay(10); |
|
|
|
} |
|
|
|
thread->m_threadisworkingFlag = false; |
|
|
|
thread->m_threadisWaitingForStopFlag = false; |
|
|
|
} |
|
|
|
vTaskDelay(10); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
@ -40,8 +48,10 @@ void ZThread::start(zosthread_cb_t cb) { |
|
|
|
|
|
|
|
ZASSERT(m_taskfunction); |
|
|
|
xSemaphoreTake(m_lock, portMAX_DELAY); |
|
|
|
xEventGroupSetBits(m_zthreadstartworkevent, 0x01); |
|
|
|
while (m_threadisworking != true) { |
|
|
|
m_threadisworkingFlagCallSide = true; |
|
|
|
// xEventGroupSetBits(m_zthreadstartworkevent, 0x01);
|
|
|
|
while (!m_threadisworkingFlag) { |
|
|
|
xTaskNotifyGive(m_defaultTaskHandle); |
|
|
|
vTaskDelay(1); |
|
|
|
} |
|
|
|
xSemaphoreGive(m_lock); |
|
|
@ -49,16 +59,15 @@ void ZThread::start(zosthread_cb_t cb) { |
|
|
|
|
|
|
|
void ZThread::stop() { |
|
|
|
xSemaphoreTake(m_lock, portMAX_DELAY); |
|
|
|
m_expect_stop = true; |
|
|
|
while (m_threadisworking) { |
|
|
|
m_threadisworkingFlagCallSide = false; |
|
|
|
// xEventGroupSetBits(m_zthreadstartworkevent, 0x01);
|
|
|
|
while (m_threadisworkingFlag) { |
|
|
|
xTaskNotifyGive(m_defaultTaskHandle); |
|
|
|
vTaskDelay(1); |
|
|
|
} |
|
|
|
m_expect_stop = false; |
|
|
|
xSemaphoreGive(m_lock); |
|
|
|
} |
|
|
|
|
|
|
|
bool ZThread::isExpectStop() { return m_expect_stop; } |
|
|
|
void ZThread::sleep(uint32_t ms) { ulTaskNotifyTake(pdFALSE, pdMS_TO_TICKS(ms)); } |
|
|
|
void ZThread::wake() { |
|
|
|
BaseType_t state; |
|
|
|