pthread_terminate.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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: [email protected]
  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: [email protected]
  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(void)
  47. {
  48. if (pte_processInitialized)
  49. {
  50. pte_thread_t * tp, * tpNext;
  51. if (pte_selfThreadKey != NULL)
  52. {
  53. /*
  54. * Release pte_selfThreadKey
  55. */
  56. pthread_key_delete (pte_selfThreadKey);
  57. pte_selfThreadKey = NULL;
  58. }
  59. if (pte_cleanupKey != NULL)
  60. {
  61. /*
  62. * Release pte_cleanupKey
  63. */
  64. pthread_key_delete (pte_cleanupKey);
  65. pte_cleanupKey = NULL;
  66. }
  67. pte_osMutexLock (pte_thread_reuse_lock);
  68. tp = pte_threadReuseTop;
  69. while (tp != PTE_THREAD_REUSE_EMPTY)
  70. {
  71. tpNext = tp->prevReuse;
  72. free (tp);
  73. tp = tpNext;
  74. }
  75. pte_osMutexUnlock(pte_thread_reuse_lock);
  76. pte_processInitialized = PTE_FALSE;
  77. }
  78. }