pte_tkAssocDestroy.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * pte_tkAssocDestroy.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. void
  47. pte_tkAssocDestroy (ThreadKeyAssoc * assoc)
  48. /*
  49. * -------------------------------------------------------------------
  50. * This routine releases all resources for the given ThreadKeyAssoc
  51. * once it is no longer being referenced
  52. * ie) either the key or thread has stopped referencing it.
  53. *
  54. * Parameters:
  55. * assoc
  56. * an instance of ThreadKeyAssoc.
  57. * Returns:
  58. * N/A
  59. * -------------------------------------------------------------------
  60. */
  61. {
  62. /*
  63. * Both key->keyLock and thread->threadLock are locked on
  64. * entry to this routine.
  65. */
  66. if (assoc != NULL)
  67. {
  68. ThreadKeyAssoc * prev, * next;
  69. /* Remove assoc from thread's keys chain */
  70. prev = assoc->prevKey;
  71. next = assoc->nextKey;
  72. if (prev != NULL)
  73. {
  74. prev->nextKey = next;
  75. }
  76. if (next != NULL)
  77. {
  78. next->prevKey = prev;
  79. }
  80. if (assoc->thread->keys == assoc)
  81. {
  82. /* We're at the head of the thread's keys chain */
  83. assoc->thread->keys = next;
  84. }
  85. if (assoc->thread->nextAssoc == assoc)
  86. {
  87. /*
  88. * Thread is exiting and we're deleting the assoc to be processed next.
  89. * Hand thread the assoc after this one.
  90. */
  91. assoc->thread->nextAssoc = next;
  92. }
  93. /* Remove assoc from key's threads chain */
  94. prev = assoc->prevThread;
  95. next = assoc->nextThread;
  96. if (prev != NULL)
  97. {
  98. prev->nextThread = next;
  99. }
  100. if (next != NULL)
  101. {
  102. next->prevThread = prev;
  103. }
  104. if (assoc->key->threads == assoc)
  105. {
  106. /* We're at the head of the key's threads chain */
  107. assoc->key->threads = next;
  108. }
  109. free (assoc);
  110. }
  111. } /* pte_tkAssocDestroy */