pthread_terminate.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * pthread_terminate.c
  3. *
  4. * Description:
  5. *
  6. * --------------------------------------------------------------------------
  7. *
  8. * Pthreads-embedded (PTE) - POSIX Threads Library for embedded systems
  9. * Copyright(C) 2008 Jason Schmidlapp
  10. *
  11. * Contact Email: jschmidlapp@users.sourceforge.net
  12. *
  13. *
  14. * Based upon Pthreads-win32 - POSIX Threads Library for Win32
  15. * Copyright(C) 1998 John E. Bossom
  16. * Copyright(C) 1999,2005 Pthreads-win32 contributors
  17. *
  18. * Contact Email: rpj@callisto.canberra.edu.au
  19. *
  20. * The original list of contributors to the Pthreads-win32 project
  21. * is contained in the file CONTRIBUTORS.ptw32 included with the
  22. * source code distribution. The list can also be seen at the
  23. * following World Wide Web location:
  24. * http://sources.redhat.com/pthreads-win32/contributors.html
  25. *
  26. * This library is free software; you can redistribute it and/or
  27. * modify it under the terms of the GNU Lesser General Public
  28. * License as published by the Free Software Foundation; either
  29. * version 2 of the License, or (at your option) any later version.
  30. *
  31. * This library is distributed in the hope that it will be useful,
  32. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  34. * Lesser General Public License for more details.
  35. *
  36. * You should have received a copy of the GNU Lesser General Public
  37. * License along with this library in the file COPYING.LIB;
  38. * if not, write to the Free Software Foundation, Inc.,
  39. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  40. */
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include <string.h>
  44. #include "pthread.h"
  45. #include "implement.h"
  46. void (*pthread_terminate_ptr)(void) __attribute__ ((section (".fini_array"))) = &pthread_terminate;
  47. void pthread_terminate(void)
  48. {
  49. if (pte_processInitialized)
  50. {
  51. pte_thread_t * tp, * tpNext;
  52. if (pte_selfThreadKey != NULL)
  53. {
  54. /*
  55. * Release pte_selfThreadKey
  56. */
  57. pthread_key_delete (pte_selfThreadKey);
  58. pte_selfThreadKey = NULL;
  59. }
  60. if (pte_cleanupKey != NULL)
  61. {
  62. /*
  63. * Release pte_cleanupKey
  64. */
  65. pthread_key_delete (pte_cleanupKey);
  66. pte_cleanupKey = NULL;
  67. }
  68. pte_osMutexLock (pte_thread_reuse_lock);
  69. tp = pte_threadReuseTop;
  70. while (tp != PTE_THREAD_REUSE_EMPTY)
  71. {
  72. tpNext = tp->prevReuse;
  73. free (tp);
  74. tp = tpNext;
  75. }
  76. pte_osMutexUnlock(pte_thread_reuse_lock);
  77. pte_processInitialized = PTE_FALSE;
  78. }
  79. }