1 /* 2 * ptw32_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-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: rpj (at) callisto.canberra.edu.au 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 36 */ 37 38 #include "pthread.h" 39 #include "implement.h" 40 41 42 void 43 ptw32_tkAssocDestroy (ThreadKeyAssoc * assoc) 44 /* 45 * ------------------------------------------------------------------- 46 * This routine releases all resources for the given ThreadKeyAssoc 47 * once it is no longer being referenced 48 * ie) either the key or thread has stopped referencing it. 49 * 50 * Parameters: 51 * assoc 52 * an instance of ThreadKeyAssoc. 53 * Returns: 54 * N/A 55 * ------------------------------------------------------------------- 56 */ 57 { 58 59 /* 60 * Both key->keyLock and thread->threadLock are locked before 61 * entry to this routine. 62 */ 63 if (assoc != NULL) 64 { 65 ThreadKeyAssoc * prev, * next; 66 67 /* Remove assoc from thread's keys chain */ 68 prev = assoc->prevKey; 69 next = assoc->nextKey; 70 if (prev != NULL) 71 { 72 prev->nextKey = next; 73 } 74 if (next != NULL) 75 { 76 next->prevKey = prev; 77 } 78 79 if (assoc->thread->keys == assoc) 80 { 81 /* We're at the head of the thread's keys chain */ 82 assoc->thread->keys = next; 83 } 84 if (assoc->thread->nextAssoc == assoc) 85 { 86 /* 87 * Thread is exiting and we're deleting the assoc to be processed next. 88 * Hand thread the assoc after this one. 89 */ 90 assoc->thread->nextAssoc = next; 91 } 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 105 if (assoc->key->threads == assoc) 106 { 107 /* We're at the head of the key's threads chain */ 108 assoc->key->threads = next; 109 } 110 111 free (assoc); 112 } 113 114 } /* ptw32_tkAssocDestroy */ 115