2 * ptw32_tkAssocCreate.c
5 * This translation unit implements routines which are private to
6 * the implementation and may be used throughout it.
8 * --------------------------------------------------------------------------
10 * Pthreads-win32 - POSIX Threads Library for Win32
11 * Copyright(C) 1998 John E. Bossom
12 * Copyright(C) 1999,2005 Pthreads-win32 contributors
14 * Contact Email: rpj@callisto.canberra.edu.au
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
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.
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.
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
39 #include "implement.h"
43 ptw32_tkAssocCreate (ptw32_thread_t
* sp
, pthread_key_t key
)
45 * -------------------------------------------------------------------
46 * This routine creates an association that
47 * is unique for the given (thread,key) combination.The association
48 * is referenced by both the thread and the key.
49 * This association allows us to determine what keys the
50 * current thread references and what threads a given key
52 * See the detailed description
53 * at the beginning of this file for further details.
56 * 1) New associations are pushed to the beginning of the
57 * chain so that the internal ptw32_selfThreadKey association
58 * is always last, thus allowing selfThreadExit to
59 * be implicitly called last by pthread_exit.
64 * current running thread.
66 * key on which to create an association.
69 * ENOMEM - not enough memory to create assoc or other object
70 * EINVAL - an internal error occurred
71 * ENOSYS - an internal error occurred
72 * -------------------------------------------------------------------
75 ThreadKeyAssoc
*assoc
;
78 * Have to create an association and add it
79 * to both the key and the thread.
81 * Both key->keyLock and thread->threadLock are locked before
82 * entry to this routine.
84 assoc
= (ThreadKeyAssoc
*) calloc (1, sizeof (*assoc
));
95 * Register assoc with key
97 assoc
->prevThread
= NULL
;
98 assoc
->nextThread
= (ThreadKeyAssoc
*) key
->threads
;
99 if (assoc
->nextThread
!= NULL
)
101 assoc
->nextThread
->prevThread
= assoc
;
103 key
->threads
= (void *) assoc
;
106 * Register assoc with thread
108 assoc
->prevKey
= NULL
;
109 assoc
->nextKey
= (ThreadKeyAssoc
*) sp
->keys
;
110 if (assoc
->nextKey
!= NULL
)
112 assoc
->nextKey
->prevKey
= assoc
;
114 sp
->keys
= (void *) assoc
;
118 } /* ptw32_tkAssocCreate */