pte_throw.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * pte_throw.c
  3. *
  4. * Description:
  5. * This translation unit implements routines which are private to
  6. * the implementation and may be used throughout it.
  7. *
  8. * --------------------------------------------------------------------------
  9. *
  10. * Pthreads-embedded (PTE) - POSIX Threads Library for embedded systems
  11. * Copyright(C) 2008 Jason Schmidlapp
  12. *
  13. * Contact Email: [email protected]
  14. *
  15. *
  16. * Based upon Pthreads-win32 - POSIX Threads Library for Win32
  17. * Copyright(C) 1998 John E. Bossom
  18. * Copyright(C) 1999,2005 Pthreads-win32 contributors
  19. *
  20. * Contact Email: [email protected]
  21. *
  22. * The original list of contributors to the Pthreads-win32 project
  23. * is contained in the file CONTRIBUTORS.ptw32 included with the
  24. * source code distribution. The list can also be seen at the
  25. * following World Wide Web location:
  26. * http://sources.redhat.com/pthreads-win32/contributors.html
  27. *
  28. * This library is free software; you can redistribute it and/or
  29. * modify it under the terms of the GNU Lesser General Public
  30. * License as published by the Free Software Foundation; either
  31. * version 2 of the License, or (at your option) any later version.
  32. *
  33. * This library is distributed in the hope that it will be useful,
  34. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  35. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  36. * Lesser General Public License for more details.
  37. *
  38. * You should have received a copy of the GNU Lesser General Public
  39. * License along with this library in the file COPYING.LIB;
  40. * if not, write to the Free Software Foundation, Inc.,
  41. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  42. */
  43. #include <stdlib.h>
  44. #include "pthread.h"
  45. #include "implement.h"
  46. /*
  47. * pte_throw
  48. *
  49. * All canceled and explicitly exited POSIX threads go through
  50. * here. This routine knows how to exit both POSIX initiated threads and
  51. * 'implicit' POSIX threads for each of the possible language modes (C,
  52. * C++).
  53. */
  54. void
  55. pte_throw (unsigned int exception)
  56. {
  57. /*
  58. * Don't use pthread_self() to avoid creating an implicit POSIX thread handle
  59. * unnecessarily.
  60. */
  61. pte_thread_t * sp = (pte_thread_t *) pthread_getspecific (pte_selfThreadKey);
  62. if (exception != PTE_EPS_CANCEL && exception != PTE_EPS_EXIT)
  63. {
  64. /* Should never enter here */
  65. exit (1);
  66. }
  67. if (NULL == sp || sp->implicit)
  68. {
  69. /*
  70. * We're inside a non-POSIX initialised OS thread
  71. * so there is no point to jump or throw back to. Just do an
  72. * explicit thread exit here after cleaning up POSIX
  73. * residue (i.e. cleanup handlers, POSIX thread handle etc).
  74. */
  75. unsigned exitCode = 0;
  76. switch (exception)
  77. {
  78. case PTE_EPS_CANCEL:
  79. exitCode = (unsigned) PTHREAD_CANCELED;
  80. break;
  81. case PTE_EPS_EXIT:
  82. exitCode = (unsigned) sp->exitStatus;;
  83. break;
  84. }
  85. pte_thread_detach_and_exit_np ();
  86. // pte_osThreadExit((void*)exitCode);
  87. }
  88. #ifdef PTE_CLEANUP_C
  89. pte_pop_cleanup_all (1);
  90. longjmp (sp->start_mark, exception);
  91. #else /* PTE_CLEANUP_C */
  92. #ifdef PTE_CLEANUP_CXX
  93. switch (exception)
  94. {
  95. case PTE_EPS_CANCEL:
  96. throw pte_exception_cancel ();
  97. break;
  98. case PTE_EPS_EXIT:
  99. throw pte_exception_exit ();
  100. break;
  101. }
  102. #else
  103. #error ERROR [__FILE__, line __LINE__]: Cleanup type undefined.
  104. #endif /* PTE_CLEANUP_CXX */
  105. #endif /* PTE_CLEANUP_C */
  106. /* Never reached */
  107. }
  108. void
  109. pte_pop_cleanup_all (int execute)
  110. {
  111. while (NULL != pte_pop_cleanup (execute))
  112. {
  113. }
  114. }
  115. unsigned int
  116. pte_get_exception_services_code (void)
  117. {
  118. return (unsigned int) NULL;
  119. }