diff --git a/example/BasicExample/__main.cpp b/example/BasicExample/__main.cpp index 584e21ccfa7a3cb89691305dc5404d6072cb39db..478e66b10042f8fbec643a8b4a5c2e8eba2d3734 100644 --- a/example/BasicExample/__main.cpp +++ b/example/BasicExample/__main.cpp @@ -8,6 +8,8 @@ public: basic_task() : mthread("basic_task", 5, 2048) { } virtual void* on_thread() { + mthread::on_thread(); + int id = get_id(); int core = get_on_core(); @@ -25,7 +27,7 @@ extern "C" void app_main() { printf("Thank you for using libmnthread version: %s\n", libmn_version.to_string().c_str()); - sleep(3); + mn_sleep(3); basic_task basic_task; basic_task.create(TASk_ON_CPU); diff --git a/example/HelloWorld/__main.cpp b/example/HelloWorld/__main.cpp index 623a9fcb2b2a8a1cb29607097ee18896bc11717e..4fb3db16dd7e7c69a8be32ec4a3987e133570c2c 100644 --- a/example/HelloWorld/__main.cpp +++ b/example/HelloWorld/__main.cpp @@ -6,6 +6,8 @@ public: helloWorld_task() : mthread("hello_task", 5, 2048) { k = 0;} virtual void* on_thread() { + mthread::on_thread(); + int id = get_id(); int core = get_on_core(); @@ -24,7 +26,7 @@ extern "C" void app_main() { printf("Thank you for using libmnthread version: %s\n", libmn_version.to_string().c_str()); - sleep(3); + mn_sleep(3); helloWorld_task __test[10]; for(int i=0; i < 10; i++) { __test[i].create(i % 2); diff --git a/src/mn-sleep.cpp b/src/mn-sleep.cpp index 4602f4e5fb6caf57cae4553ae8e69ad3c2ead951..4a9670d3652ed544749186dc71c4e9a531a43752 100644 --- a/src/mn-sleep.cpp +++ b/src/mn-sleep.cpp @@ -16,16 +16,16 @@ -unsigned sleep(unsigned int secs) { +unsigned mn_sleep(unsigned int secs) { vTaskDelay( (secs * 1000) / ((TickType_t) 1000 / configTICK_RATE_HZ)); return 0; } -int usleep(useconds_t usec) { +int mn_usleep(useconds_t usec) { vTaskDelay(usec / ((TickType_t) 1000000 / configTICK_RATE_HZ)); return 0; } -int IRAM_ATTR nsleep(const struct timespec *req, struct timespec *rem) { +int IRAM_ATTR mn_nsleep(const struct timespec *req, struct timespec *rem) { struct timeval start, end; if ((req->tv_nsec < 0) || (req->tv_nsec > 999999999)) { diff --git a/src/mn-sleep.h b/src/mn-sleep.h index 2d84217793b809f575b4fd3911f193af7c9baf00..e2d187cd03c385d89118b1b3364e166732d1f0fe 100644 --- a/src/mn-sleep.h +++ b/src/mn-sleep.h @@ -11,9 +11,9 @@ #include <sys/signal.h> -unsigned sleep(unsigned int secs); -int usleep(useconds_t usec); +unsigned mn_sleep(unsigned int secs); +int mn_usleep(useconds_t usec); -int nsleep(const struct timespec *req, struct timespec *rem); +int mn_nsleep(const struct timespec *req, struct timespec *rem); #endif diff --git a/src/mn-thread.cpp b/src/mn-thread.cpp index 6c520b39b5cb0f47204dfa59d10ac3c58fa7fa95..6ac67cc3f0fe2bca667c1d50a9acd0e0f1c61f59 100644 --- a/src/mn-thread.cpp +++ b/src/mn-thread.cpp @@ -182,7 +182,9 @@ void basic_thread::runtaskstub(void* parm) { esp_thread->m_runningMutex->unlock(); } - +void basic_thread::thread_started() { + m_continuemutex2->unlock(); +} uint32_t __internal_id_base__ = 0; uint32_t basic_thread::get_new_id() { diff --git a/src/mn-thread.h b/src/mn-thread.h index 71ca6f0b10b43579c857349fa20c7fdc4a9d2d2a..bc74b0b23013ab18a575249cf8d56a9cacc11887 100644 --- a/src/mn-thread.h +++ b/src/mn-thread.h @@ -27,7 +27,6 @@ public: int create(int uiCore = -1); int kill(); - bool is_running(); const char* get_name(); @@ -44,7 +43,7 @@ public: void suspend(); void resume(); - virtual void* on_thread() { return NULL; } + virtual void* on_thread() { thread_started(); return NULL; } basic_thread* get_root(); basic_thread* get_child(); @@ -54,16 +53,17 @@ public: static void suspend(basic_thread *t) { t->suspend(); } static void resume(basic_thread *t) { t->resume(); } static void yield() { taskYIELD(); } - static void sleep(unsigned int secs) { ::sleep(secs); } - static void usleep(unsigned int usec) { ::usleep(usec); } + static void sleep(unsigned int secs) { ::mn_sleep(secs); } + static void usleep(unsigned int usec) { ::mn_usleep(usec); } static void nsleep(const struct timespec *req, struct timespec *rem) { - ::nsleep(req, rem); + ::mn_nsleep(req, rem); } static void lock(basic_thread * t) { t->m_runningMutex->lock(); } static void unlock(basic_thread * t) { t->m_runningMutex->unlock(); } protected: static void runtaskstub(void* parm); + void thread_started(); private: static uint32_t get_new_id(); protected: