/[pcsx2_0.9.7]/trunk/3rdparty/w32pthreads/ptw32_tkAssocCreate.c
ViewVC logotype

Contents of /trunk/3rdparty/w32pthreads/ptw32_tkAssocCreate.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (show annotations) (download)
Mon Sep 6 11:40:06 2010 UTC (9 years, 5 months ago) by william
File MIME type: text/plain
File size: 4045 byte(s)
exported r3113 from ./upstream/trunk
1 /*
2 * ptw32_tkAssocCreate.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@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 "ptw32pch.h"
39
40 int
41 ptw32_tkAssocCreate (ptw32_thread_t * sp, pthread_key_t key)
42 /*
43 * -------------------------------------------------------------------
44 * This routine creates an association that
45 * is unique for the given (thread,key) combination.The association
46 * is referenced by both the thread and the key.
47 * This association allows us to determine what keys the
48 * current thread references and what threads a given key
49 * references.
50 * See the detailed description
51 * at the beginning of this file for further details.
52 *
53 * Notes:
54 * 1) New associations are pushed to the beginning of the
55 * chain so that the internal ptw32_selfThreadKey association
56 * is always last, thus allowing selfThreadExit to
57 * be implicitly called last by pthread_exit.
58 * 2)
59 *
60 * Parameters:
61 * thread
62 * current running thread.
63 * key
64 * key on which to create an association.
65 * Returns:
66 * 0 - if successful,
67 * ENOMEM - not enough memory to create assoc or other object
68 * EINVAL - an internal error occurred
69 * ENOSYS - an internal error occurred
70 * -------------------------------------------------------------------
71 */
72 {
73 ThreadKeyAssoc *assoc;
74
75 /*
76 * Have to create an association and add it
77 * to both the key and the thread.
78 *
79 * Both key->keyLock and thread->threadLock are locked on
80 * entry to this routine.
81 */
82 assoc = (ThreadKeyAssoc *) calloc (1, sizeof (*assoc));
83
84 if (assoc == NULL)
85 {
86 return ENOMEM;
87 }
88
89 assoc->thread = sp;
90 assoc->key = key;
91
92 /*
93 * Register assoc with key
94 */
95 assoc->prevThread = NULL;
96 assoc->nextThread = (ThreadKeyAssoc *) key->threads;
97 if (assoc->nextThread != NULL)
98 {
99 assoc->nextThread->prevThread = assoc;
100 }
101 key->threads = (void *) assoc;
102
103 /*
104 * Register assoc with thread
105 */
106 assoc->prevKey = NULL;
107 assoc->nextKey = (ThreadKeyAssoc *) sp->keys;
108 if (assoc->nextKey != NULL)
109 {
110 assoc->nextKey->prevKey = assoc;
111 }
112 sp->keys = (void *) assoc;
113
114 return (0);
115
116 } /* ptw32_tkAssocCreate */

  ViewVC Help
Powered by ViewVC 1.1.22