1 /*
2 * ptw32_processInitialize.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 * Pthreads4w - POSIX Threads for Windows
11 * Copyright 1998 John E. Bossom
12 * Copyright 1999-2018, Pthreads4w contributors
13 *
14 * Homepage: https://sourceforge.net/projects/pthreads4w/
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 *
21 * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
22 *
23 * Licensed under the Apache License, Version 2.0 (the "License");
24 * you may not use this file except in compliance with the License.
25 * You may obtain a copy of the License at
26 *
27 * http://www.apache.org/licenses/LICENSE-2.0
28 *
29 * Unless required by applicable law or agreed to in writing, software
30 * distributed under the License is distributed on an "AS IS" BASIS,
31 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32 * See the License for the specific language governing permissions and
33 * limitations under the License.
34 */
35
36 #ifdef HAVE_CONFIG_H
37 # include <config.h>
38 #endif
39
40 #include "pthread.h"
41 #include "implement.h"
42
43
44 int
__ptw32_processInitialize(void)45 __ptw32_processInitialize (void)
46 /*
47 * ------------------------------------------------------
48 * DOCPRIVATE
49 * This function performs process wide initialization for
50 * the pthread library.
51 *
52 * PARAMETERS
53 * N/A
54 *
55 * DESCRIPTION
56 * This function performs process wide initialization for
57 * the pthread library.
58 * If successful, this routine sets the global variable
59 * __ptw32_processInitialized to TRUE.
60 *
61 * RESULTS
62 * TRUE if successful,
63 * FALSE otherwise
64 *
65 * ------------------------------------------------------
66 */
67 {
68 if (__ptw32_processInitialized)
69 {
70 return __PTW32_TRUE;
71 }
72
73 /*
74 * Explicitly initialise all variables from global.c
75 */
76 __ptw32_threadReuseTop = __PTW32_THREAD_REUSE_EMPTY;
77 __ptw32_threadReuseBottom = __PTW32_THREAD_REUSE_EMPTY;
78 __ptw32_selfThreadKey = NULL;
79 __ptw32_cleanupKey = NULL;
80 __ptw32_cond_list_head = NULL;
81 __ptw32_cond_list_tail = NULL;
82
83 __ptw32_concurrency = 0;
84
85 /* What features have been auto-detected */
86 __ptw32_features = 0;
87
88 /*
89 * Global [process wide] thread sequence Number
90 */
91 __ptw32_threadSeqNumber = 0;
92
93 /*
94 * Function pointer to QueueUserAPCEx if it exists, otherwise
95 * it will be set at runtime to a substitute routine which cannot unblock
96 * blocked threads.
97 */
98 __ptw32_register_cancellation = NULL;
99
100 /*
101 * Global lock for managing pthread_t struct reuse.
102 */
103 __ptw32_thread_reuse_lock = 0;
104
105 /*
106 * Global lock for testing internal state of statically declared mutexes.
107 */
108 __ptw32_mutex_test_init_lock = 0;
109
110 /*
111 * Global lock for testing internal state of PTHREAD_COND_INITIALIZER
112 * created condition variables.
113 */
114 __ptw32_cond_test_init_lock = 0;
115
116 /*
117 * Global lock for testing internal state of PTHREAD_RWLOCK_INITIALIZER
118 * created read/write locks.
119 */
120 __ptw32_rwlock_test_init_lock = 0;
121
122 /*
123 * Global lock for testing internal state of PTHREAD_SPINLOCK_INITIALIZER
124 * created spin locks.
125 */
126 __ptw32_spinlock_test_init_lock = 0;
127
128 /*
129 * Global lock for condition variable linked list. The list exists
130 * to wake up CVs when a WM_TIMECHANGE message arrives. See
131 * w32_TimeChangeHandler.c.
132 */
133 __ptw32_cond_list_lock = 0;
134
135 #if defined(_UWIN)
136 /*
137 * Keep a count of the number of threads.
138 */
139 pthread_count = 0;
140 #endif
141
142 __ptw32_processInitialized = __PTW32_TRUE;
143
144 /*
145 * Initialize Keys
146 */
147 if ((pthread_key_create (&__ptw32_selfThreadKey, NULL) != 0) ||
148 (pthread_key_create (&__ptw32_cleanupKey, NULL) != 0))
149 {
150
151 __ptw32_processTerminate ();
152 }
153
154 return (__ptw32_processInitialized);
155
156 } /* processInitialize */
157