pthread: Fixes memory leaks and stack overflow in tests

Also this commit replaces FreeRTOS list used for pthread internals
with simple one from rom/queue.h
This commit is contained in:
Alexey Gerenkov
2017-11-14 11:43:32 +03:00
parent b83792f504
commit 7ce945a9de
3 changed files with 52 additions and 49 deletions

View File

@@ -22,6 +22,7 @@ static void thread_main()
{
int i = 0;
std::cout << "thread_main CXX " << std::hex << std::this_thread::get_id() << std::endl;
std::chrono::milliseconds dur = std::chrono::milliseconds(300);
while (i < 3) {
int old_val, new_val;
@@ -38,7 +39,6 @@ static void thread_main()
TEST_ASSERT_TRUE(new_val == old_val + 1);
// sleep_for test
std::chrono::milliseconds dur(300);
std::this_thread::sleep_for(dur);
// recursive mux test
@@ -59,7 +59,7 @@ static void thread_main()
std::time_t tt = system_clock::to_time_t(system_clock::now());
struct std::tm *ptm = std::localtime(&tt);
ptm->tm_sec++;
std::this_thread::sleep_until(system_clock::from_time_t (mktime(ptm)));
std::this_thread::sleep_until(system_clock::from_time_t(mktime(ptm)));
}
}
@@ -89,17 +89,25 @@ TEST_CASE("pthread C++", "[pthread]")
global_sp.reset(); // avoid reported leak
}
static void task_test_sandbox(void *arg)
static void task_test_sandbox()
{
bool *running = (bool *)arg;
std::stringstream ss;
ESP_LOGI(TAG, "About to create a string stream");
std::stringstream ss;
ESP_LOGI(TAG, "About to write to string stream");
ss << "Hello World!";
ESP_LOGI(TAG, "About to extract from stringstream");
ESP_LOGI(TAG, "Text: %s", ss.str().c_str());
}
static void task_test_sandbox_c(void *arg)
{
bool *running = (bool *)arg;
// wrap thread func to ensure that all C++ stack objects are cleaned up by their destructors
task_test_sandbox();
ESP_LOGI(TAG, "Task stk_wm = %d", uxTaskGetStackHighWaterMark(NULL));
if (running) {
*running = false;
vTaskDelete(NULL);
@@ -108,11 +116,11 @@ static void task_test_sandbox(void *arg)
TEST_CASE("pthread mix C/C++", "[pthread]")
{
bool running = true;
bool c_running = true;
std::thread t1(task_test_sandbox, (void *)NULL);
xTaskCreatePinnedToCore((TaskFunction_t)&task_test_sandbox, "task_test_sandbox", 2048, &running, 5, NULL, 0);
while (running) {
std::thread t1(task_test_sandbox);
xTaskCreatePinnedToCore((TaskFunction_t)&task_test_sandbox_c, "task_test_sandbox", 3072, &c_running, 5, NULL, 0);
while (c_running) {
vTaskDelay(1);
}
if (t1.joinable()) {