mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #15059 from LDong-Arm/bd_greentea_fixes
Fix Thread::start() and general_block_device test's thread allocation/deallocationpull/15061/head
commit
988d165f8f
|
@ -131,7 +131,8 @@ public:
|
||||||
|
|
||||||
/** Starts a thread executing the specified function.
|
/** Starts a thread executing the specified function.
|
||||||
@param task function to be executed by this thread.
|
@param task function to be executed by this thread.
|
||||||
@return status code that indicates the execution status of the function.
|
@return status code that indicates the execution status of the function,
|
||||||
|
or osErrorNoMemory if stack allocation failed.
|
||||||
@note a thread can only be started once
|
@note a thread can only be started once
|
||||||
|
|
||||||
@note You cannot call this function ISR context.
|
@note You cannot call this function ISR context.
|
||||||
|
|
|
@ -81,8 +81,11 @@ osStatus Thread::start(mbed::Callback<void()> task)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_attr.stack_mem == nullptr) {
|
if (_attr.stack_mem == nullptr) {
|
||||||
_attr.stack_mem = new uint32_t[_attr.stack_size / sizeof(uint32_t)];
|
_attr.stack_mem = new (std::nothrow) uint32_t[_attr.stack_size / sizeof(uint32_t)];
|
||||||
MBED_ASSERT(_attr.stack_mem != nullptr);
|
if (_attr.stack_mem == nullptr) {
|
||||||
|
_mutex.unlock();
|
||||||
|
return osErrorNoMemory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Fill the stack with a magic word for maximum usage checking
|
//Fill the stack with a magic word for maximum usage checking
|
||||||
|
|
|
@ -421,40 +421,35 @@ void test_multi_threads()
|
||||||
|
|
||||||
osStatus threadStatus;
|
osStatus threadStatus;
|
||||||
int i_ind, j_ind;
|
int i_ind, j_ind;
|
||||||
char *dummy;
|
|
||||||
|
|
||||||
rtos::Thread **bd_thread = new (std::nothrow) rtos::Thread*[TEST_NUM_OF_THREADS];
|
rtos::Thread *bd_thread[TEST_NUM_OF_THREADS] {};
|
||||||
TEST_SKIP_UNLESS_MESSAGE((*bd_thread) != NULL, "not enough heap to run test.");
|
|
||||||
memset(bd_thread, 0, TEST_NUM_OF_THREADS * sizeof(rtos::Thread *));
|
|
||||||
|
|
||||||
for (i_ind = 0; i_ind < TEST_NUM_OF_THREADS; i_ind++) {
|
for (i_ind = 0; i_ind < TEST_NUM_OF_THREADS; i_ind++) {
|
||||||
|
|
||||||
bd_thread[i_ind] = new (std::nothrow) rtos::Thread((osPriority_t)((int)osPriorityNormal), TEST_THREAD_STACK_SIZE);
|
bd_thread[i_ind] = new (std::nothrow) rtos::Thread((osPriority_t)((int)osPriorityNormal), TEST_THREAD_STACK_SIZE);
|
||||||
dummy = new (std::nothrow) char[TEST_THREAD_STACK_SIZE];
|
|
||||||
|
|
||||||
if (!bd_thread[i_ind] || !dummy) {
|
if (!bd_thread[i_ind]) {
|
||||||
utest_printf("Not enough heap to run Thread %d !\n", i_ind + 1);
|
utest_printf("Not enough heap to create Thread %d\n", i_ind + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
delete[] dummy;
|
|
||||||
|
|
||||||
threadStatus = bd_thread[i_ind]->start(callback(test_thread_job));
|
threadStatus = bd_thread[i_ind]->start(callback(test_thread_job));
|
||||||
if (threadStatus != 0) {
|
if (threadStatus == osErrorNoMemory) {
|
||||||
utest_printf("Thread %d Start Failed!\n", i_ind + 1);
|
utest_printf("Not enough heap to start Thread %d\n", i_ind + 1);
|
||||||
|
} else if (threadStatus != osOK) {
|
||||||
|
utest_printf("Thread %d failed to start: %d\n", i_ind + 1, threadStatus);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Join threads that successfully started
|
||||||
for (j_ind = 0; j_ind < i_ind; j_ind++) {
|
for (j_ind = 0; j_ind < i_ind; j_ind++) {
|
||||||
bd_thread[j_ind]->join();
|
bd_thread[j_ind]->join();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bd_thread) {
|
// Delete all threads, even those that failed to start
|
||||||
for (j_ind = 0; j_ind < i_ind; j_ind++) {
|
for (j_ind = 0; j_ind < TEST_NUM_OF_THREADS; j_ind++) {
|
||||||
delete bd_thread[j_ind];
|
delete bd_thread[j_ind];
|
||||||
}
|
|
||||||
|
|
||||||
delete[] bd_thread;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue