| 148 | } |
| 149 | |
| 150 | static void *thread_run(void *parameter) |
| 151 | { |
| 152 | rt_thread_t tid; |
| 153 | thread_t *thread; |
| 154 | thread = THREAD_T(parameter); |
| 155 | int res; |
| 156 | |
| 157 | /* set signal mask, mask the timer! */ |
| 158 | signal_mask(); |
| 159 | |
| 160 | thread->status = SUSPEND_LOCK; |
| 161 | TRACE("pid <%08x> stop on sem...\n", (unsigned int)(thread->pthread)); |
| 162 | sem_wait(&thread->sem); |
| 163 | |
| 164 | tid = rt_thread_self(); |
| 165 | TRACE("pid <%08x> tid <%s> starts...\n", (unsigned int)(thread->pthread), |
| 166 | tid->parent.name); |
| 167 | thread->rtthread = tid; |
| 168 | thread->task(thread->para); |
| 169 | TRACE("pid <%08x> tid <%s> exit...\n", (unsigned int)(thread->pthread), |
| 170 | tid->parent.name); |
| 171 | thread->exit(); |
| 172 | |
| 173 | /*TODO: |
| 174 | * 最后一行的pthread_exit永远没有机会执行,这是因为在threead->exit函数中 |
| 175 | * 会发生线程切换,并永久将此pthread线程挂起,所以更完美的解决方案是在这 |
| 176 | * 里发送信号给主线程,主线程中再次唤醒此线程令其自动退出。 |
| 177 | */ |
| 178 | //sem_destroy(&thread->sem); |
| 179 | |
| 180 | pthread_exit(NULL); |
| 181 | } |
| 182 | static int thread_create( |
| 183 | thread_t *thread, void *task, void *parameter, void *pexit) |
| 184 | { |
nothing calls this directly
no test coverage detected