summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/threads/th-lock.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/threads/th-lock.c')
-rw-r--r--src/lib/libcrypto/threads/th-lock.c55
1 files changed, 37 insertions, 18 deletions
diff --git a/src/lib/libcrypto/threads/th-lock.c b/src/lib/libcrypto/threads/th-lock.c
index afb4f4caf2..3ee978060c 100644
--- a/src/lib/libcrypto/threads/th-lock.c
+++ b/src/lib/libcrypto/threads/th-lock.c
@@ -74,6 +74,9 @@
74#include <ulocks.h> 74#include <ulocks.h>
75#include <sys/prctl.h> 75#include <sys/prctl.h>
76#endif 76#endif
77#ifdef PTHREADS
78#include <pthread.h>
79#endif
77#include <openssl/lhash.h> 80#include <openssl/lhash.h>
78#include <openssl/crypto.h> 81#include <openssl/crypto.h>
79#include <openssl/buffer.h> 82#include <openssl/buffer.h>
@@ -82,7 +85,7 @@
82#include <openssl/ssl.h> 85#include <openssl/ssl.h>
83#include <openssl/err.h> 86#include <openssl/err.h>
84 87
85int CRYPTO_thread_setup(void); 88void CRYPTO_thread_setup(void);
86void CRYPTO_thread_cleanup(void); 89void CRYPTO_thread_cleanup(void);
87 90
88static void irix_locking_callback(int mode,int type,char *file,int line); 91static void irix_locking_callback(int mode,int type,char *file,int line);
@@ -96,7 +99,7 @@ static unsigned long pthreads_thread_id(void );
96 99
97/* usage: 100/* usage:
98 * CRYPTO_thread_setup(); 101 * CRYPTO_thread_setup();
99 * applicaion code 102 * application code
100 * CRYPTO_thread_cleanup(); 103 * CRYPTO_thread_cleanup();
101 */ 104 */
102 105
@@ -104,13 +107,14 @@ static unsigned long pthreads_thread_id(void );
104 107
105#ifdef WIN32 108#ifdef WIN32
106 109
107static HANDLE lock_cs[CRYPTO_NUM_LOCKS]; 110static HANDLE *lock_cs;
108 111
109int CRYPTO_thread_setup(void) 112void CRYPTO_thread_setup(void)
110 { 113 {
111 int i; 114 int i;
112 115
113 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 116 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(HANDLE));
117 for (i=0; i<CRYPTO_num_locks(); i++)
114 { 118 {
115 lock_cs[i]=CreateMutex(NULL,FALSE,NULL); 119 lock_cs[i]=CreateMutex(NULL,FALSE,NULL);
116 } 120 }
@@ -125,8 +129,9 @@ static void CRYPTO_thread_cleanup(void)
125 int i; 129 int i;
126 130
127 CRYPTO_set_locking_callback(NULL); 131 CRYPTO_set_locking_callback(NULL);
128 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 132 for (i=0; i<CRYPTO_num_locks(); i++)
129 CloseHandle(lock_cs[i]); 133 CloseHandle(lock_cs[i]);
134 Free(lock_cs);
130 } 135 }
131 136
132void win32_locking_callback(int mode, int type, char *file, int line) 137void win32_locking_callback(int mode, int type, char *file, int line)
@@ -147,18 +152,24 @@ void win32_locking_callback(int mode, int type, char *file, int line)
147 152
148#define USE_MUTEX 153#define USE_MUTEX
149 154
150static mutex_t lock_cs[CRYPTO_NUM_LOCKS];
151#ifdef USE_MUTEX 155#ifdef USE_MUTEX
152static long lock_count[CRYPTO_NUM_LOCKS]; 156static mutex_t *lock_cs;
153#else 157#else
154static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; 158static rwlock_t *lock_cs;
155#endif 159#endif
160static long *lock_count;
156 161
157void CRYPTO_thread_setup(void) 162void CRYPTO_thread_setup(void)
158 { 163 {
159 int i; 164 int i;
160 165
161 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 166#ifdef USE_MUTEX
167 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(mutex_t));
168#else
169 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(rwlock_t));
170#endif
171 lock_count=Malloc(CRYPTO_num_locks() * sizeof(long));
172 for (i=0; i<CRYPTO_num_locks(); i++)
162 { 173 {
163 lock_count[i]=0; 174 lock_count[i]=0;
164#ifdef USE_MUTEX 175#ifdef USE_MUTEX
@@ -177,7 +188,7 @@ void CRYPTO_thread_cleanup(void)
177 int i; 188 int i;
178 189
179 CRYPTO_set_locking_callback(NULL); 190 CRYPTO_set_locking_callback(NULL);
180 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 191 for (i=0; i<CRYPTO_num_locks(); i++)
181 { 192 {
182#ifdef USE_MUTEX 193#ifdef USE_MUTEX
183 mutex_destroy(&(lock_cs[i])); 194 mutex_destroy(&(lock_cs[i]));
@@ -185,6 +196,8 @@ void CRYPTO_thread_cleanup(void)
185 rwlock_destroy(&(lock_cs[i])); 196 rwlock_destroy(&(lock_cs[i]));
186#endif 197#endif
187 } 198 }
199 Free(lock_cs);
200 Free(lock_count);
188 } 201 }
189 202
190void solaris_locking_callback(int mode, int type, char *file, int line) 203void solaris_locking_callback(int mode, int type, char *file, int line)
@@ -237,7 +250,7 @@ unsigned long solaris_thread_id(void)
237/* I don't think this works..... */ 250/* I don't think this works..... */
238 251
239static usptr_t *arena; 252static usptr_t *arena;
240static usema_t *lock_cs[CRYPTO_NUM_LOCKS]; 253static usema_t **lock_cs;
241 254
242void CRYPTO_thread_setup(void) 255void CRYPTO_thread_setup(void)
243 { 256 {
@@ -254,7 +267,8 @@ void CRYPTO_thread_setup(void)
254 arena=usinit(filename); 267 arena=usinit(filename);
255 unlink(filename); 268 unlink(filename);
256 269
257 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 270 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(usema_t *));
271 for (i=0; i<CRYPTO_num_locks(); i++)
258 { 272 {
259 lock_cs[i]=usnewsema(arena,1); 273 lock_cs[i]=usnewsema(arena,1);
260 } 274 }
@@ -268,7 +282,7 @@ void CRYPTO_thread_cleanup(void)
268 int i; 282 int i;
269 283
270 CRYPTO_set_locking_callback(NULL); 284 CRYPTO_set_locking_callback(NULL);
271 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 285 for (i=0; i<CRYPTO_num_locks(); i++)
272 { 286 {
273 char buf[10]; 287 char buf[10];
274 288
@@ -276,6 +290,7 @@ void CRYPTO_thread_cleanup(void)
276 usdumpsema(lock_cs[i],stdout,buf); 290 usdumpsema(lock_cs[i],stdout,buf);
277 usfreesema(lock_cs[i],arena); 291 usfreesema(lock_cs[i],arena);
278 } 292 }
293 Free(lock_cs);
279 } 294 }
280 295
281void irix_locking_callback(int mode, int type, char *file, int line) 296void irix_locking_callback(int mode, int type, char *file, int line)
@@ -302,14 +317,16 @@ unsigned long irix_thread_id(void)
302/* Linux and a few others */ 317/* Linux and a few others */
303#ifdef PTHREADS 318#ifdef PTHREADS
304 319
305static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS]; 320static pthread_mutex_t *lock_cs;
306static long lock_count[CRYPTO_NUM_LOCKS]; 321static long *lock_count;
307 322
308void CRYPTO_thread_setup(void) 323void CRYPTO_thread_setup(void)
309 { 324 {
310 int i; 325 int i;
311 326
312 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 327 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
328 lock_count=Malloc(CRYPTO_num_locks() * sizeof(long));
329 for (i=0; i<CRYPTO_num_locks(); i++)
313 { 330 {
314 lock_count[i]=0; 331 lock_count[i]=0;
315 pthread_mutex_init(&(lock_cs[i]),NULL); 332 pthread_mutex_init(&(lock_cs[i]),NULL);
@@ -324,10 +341,12 @@ void thread_cleanup(void)
324 int i; 341 int i;
325 342
326 CRYPTO_set_locking_callback(NULL); 343 CRYPTO_set_locking_callback(NULL);
327 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 344 for (i=0; i<CRYPTO_num_locks(); i++)
328 { 345 {
329 pthread_mutex_destroy(&(lock_cs[i])); 346 pthread_mutex_destroy(&(lock_cs[i]));
330 } 347 }
348 Free(lock_cs);
349 Free(lock_count);
331 } 350 }
332 351
333void pthreads_locking_callback(int mode, int type, char *file, 352void pthreads_locking_callback(int mode, int type, char *file,