comparison src/c/urweb.c @ 2166:8a01e8f21de9

Make OpenSSL usage thread-safe (closes #206) Enable OpenSSL?s multithreading support by defining locking and thread-ID callbacks. Remove a lock obviated by this change.
author Benjamin Barenblat <bbaren@mit.edu>
date Thu, 06 Aug 2015 10:15:53 -0400
parents 4895c41b2ec6
children d2a98983f502 c05851bf7861
comparison
equal deleted inserted replaced
2165:7dfce558aca2 2166:8a01e8f21de9
165 165
166 void *uw_init_client_data(); 166 void *uw_init_client_data();
167 void uw_free_client_data(void *); 167 void uw_free_client_data(void *);
168 void uw_copy_client_data(void *dst, void *src); 168 void uw_copy_client_data(void *dst, void *src);
169 169
170 static pthread_mutex_t rand_mutex = PTHREAD_MUTEX_INITIALIZER;
171
172 static uw_Basis_int my_rand() { 170 static uw_Basis_int my_rand() {
173 pthread_mutex_lock(&rand_mutex);
174 int ret, r = RAND_bytes((unsigned char *)&ret, sizeof ret); 171 int ret, r = RAND_bytes((unsigned char *)&ret, sizeof ret);
175 pthread_mutex_unlock(&rand_mutex);
176
177 if (r) 172 if (r)
178 return abs(ret); 173 return abs(ret);
179 else 174 else
180 return -1; 175 return -1;
181 } 176 }