ptw32_threadDestroy.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * ptw32_threadDestroy.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-win32 - POSIX Threads Library for Win32
  11. * Copyright(C) 1998 John E. Bossom
  12. * Copyright(C) 1999,2005 Pthreads-win32 contributors
  13. *
  14. * Contact Email: [email protected]
  15. *
  16. * The current list of contributors is contained
  17. * in the file CONTRIBUTORS included with the source
  18. * code distribution. The list can also be seen at the
  19. * following World Wide Web location:
  20. * http://sources.redhat.com/pthreads-win32/contributors.html
  21. *
  22. * This library is free software; you can redistribute it and/or
  23. * modify it under the terms of the GNU Lesser General Public
  24. * License as published by the Free Software Foundation; either
  25. * version 2 of the License, or (at your option) any later version.
  26. *
  27. * This library is distributed in the hope that it will be useful,
  28. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  30. * Lesser General Public License for more details.
  31. *
  32. * You should have received a copy of the GNU Lesser General Public
  33. * License along with this library in the file COPYING.LIB;
  34. * if not, write to the Free Software Foundation, Inc.,
  35. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  36. */
  37. #include "pthread.h"
  38. #include "implement.h"
  39. void
  40. ptw32_threadDestroy (pthread_t thread)
  41. {
  42. ptw32_thread_t * tp = (ptw32_thread_t *) thread.p;
  43. ptw32_thread_t threadCopy;
  44. if (tp != NULL)
  45. {
  46. /*
  47. * Copy thread state so that the thread can be atomically NULLed.
  48. */
  49. memcpy (&threadCopy, tp, sizeof (threadCopy));
  50. /*
  51. * Thread ID structs are never freed. They're NULLed and reused.
  52. * This also sets the thread to PThreadStateInitial (invalid).
  53. */
  54. ptw32_threadReusePush (thread);
  55. /* Now work on the copy. */
  56. if (threadCopy.cancelEvent != NULL)
  57. {
  58. CloseHandle (threadCopy.cancelEvent);
  59. }
  60. #if ! (defined(__MINGW64__) || defined(__MINGW32__)) || defined (__MSVCRT__) || defined (__DMC__)
  61. /*
  62. * See documentation for endthread vs endthreadex.
  63. */
  64. if (threadCopy.threadH != 0)
  65. {
  66. CloseHandle (threadCopy.threadH);
  67. }
  68. #endif
  69. }
  70. } /* ptw32_threadDestroy */