You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
1.3 KiB

#pragma once
#include "osbasic_h.hpp"
namespace iflytop {
typedef function<void()> zosthread_cb_t;
class ZThread {
public:
typedef enum {
kidle,
kworking,
kdead,
} status_t;
const char* m_name;
uint32_t m_stacksize;
osPriority m_uxPriority;
status_t m_status = kidle;
#if 0
bool m_threadisworkingFlag = false;
bool m_threadisWaitingForStopFlag = false;
#endif
bool m_threadisworkingFlagCallSide = false;
zosthread_cb_t m_taskfunction;
zosthread_cb_t m_taskfunction_exitcb;
EventGroupHandle_t m_zthreadstartworkevent;
osThreadId m_defaultTaskHandle;
SemaphoreHandle_t m_lock;
public:
/**
* @brief init in zos.cpp, called by zos_init
*/
static void zthread_module_init();
void init(const char* threadname, int stack_size = 512, osPriority priority = osPriorityNormal);
void start(zosthread_cb_t cb);
void start(zosthread_cb_t cb, zosthread_cb_t exitcb);
void stop();
bool getExitFlag() { return !m_threadisworkingFlagCallSide; }
bool isworking() { return m_status == kworking; }
void wake();
static void sleep(uint32_t ms);
static ZThread* getThread();
public:
void threadcb();
};
class ThisThread {
ZThread* thread;
public:
ThisThread();
bool getExitFlag();
bool isworking();
void sleep(uint32_t ms);
};
} // namespace iflytop