wrap_exit.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <reent.h>
  2. #include <sys/errno.h>
  3. #include <sys/time.h>
  4. #include <rtthread.h>
  5. #ifdef RT_USING_DFS
  6. #include <dfs_posix.h>
  7. #endif
  8. #ifdef RT_USING_PTHREADS
  9. #include <pthread.h>
  10. #endif
  11. void
  12. __wrap__exit (int status)
  13. {
  14. #ifdef RT_USING_MODULE
  15. rt_module_t module;
  16. module = rt_module_self();
  17. if (module != RT_NULL)
  18. {
  19. struct rt_list_node *list;
  20. struct rt_object *object;
  21. rt_enter_critical();
  22. /* delete all threads in the module */
  23. list = &module->module_object[RT_Object_Class_Thread].object_list;
  24. while (list->next != list)
  25. {
  26. object = rt_list_entry(list->next, struct rt_object, list);
  27. if (rt_object_is_systemobject(object) == RT_TRUE)
  28. {
  29. /* detach static object */
  30. rt_thread_detach((rt_thread_t)object);
  31. }
  32. else
  33. {
  34. /* delete dynamic object */
  35. rt_thread_delete((rt_thread_t)object);
  36. }
  37. }
  38. /* delete main thread */
  39. rt_thread_delete(module->module_thread);
  40. rt_exit_critical();
  41. /* re-schedule */
  42. rt_schedule();
  43. }
  44. #endif
  45. rt_kprintf("thread:%s exit with %d\n", rt_thread_self()->name, status);
  46. RT_ASSERT(0);
  47. while (1);
  48. }