Browse code

Clean-up: Remove pthread and mutex locking code

This code was not activated at all, and hard coded as disabled in syshead.h
with this code snippet:

/*
* Pthread support is currently experimental (and quite unfinished).
*/
#if 1 /* JYFIXME -- if defined, disable pthread */
#undef USE_PTHREAD
#endif

So no matter if --enable-pthread when running ./configure or not, this feature
was never enabled in reality. Further, by removing the blocker code above made
OpenVPN uncompilable in the current state.

As the threading part needs to be completely rewritten and pthreading will not be
supported in OpenVPN 2.x, removing this code seems most reasonable.

In addition, a lot of mutex locking code was also removed, as they were practically
NOP functions, due to pthreading being forcefully disabled

Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
Acked-by: James Yonan <james@openvpn.net>

David Sommerseth authored on 2010/08/29 03:14:36
Showing 32 changed files
... ...
@@ -137,7 +137,6 @@ openvpn_SOURCES = \
137 137
 	ssl.c ssl.h \
138 138
 	status.c status.h \
139 139
 	syshead.h \
140
-	thread.c thread.h \
141 140
 	tun.c tun.h \
142 141
 	win32.h win32.c \
143 142
 	cryptoapi.h cryptoapi.c
... ...
@@ -129,227 +129,3 @@ AC_DEFUN([TYPE_SOCKLEN_T],
129 129
       [#include <sys/types.h>
130 130
 #include <sys/socket.h>])
131 131
 ])
132
-
133
-dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
134
-dnl
135
-dnl This macro figures out how to build C programs using POSIX
136
-dnl threads.  It sets the PTHREAD_LIBS output variable to the threads
137
-dnl library and linker flags, and the PTHREAD_CFLAGS output variable
138
-dnl to any special C compiler flags that are needed.  (The user can also
139
-dnl force certain compiler flags/libs to be tested by setting these
140
-dnl environment variables.)
141
-dnl
142
-dnl Also sets PTHREAD_CC to any special C compiler that is needed for
143
-dnl multi-threaded programs (defaults to the value of CC otherwise).
144
-dnl (This is necessary on AIX to use the special cc_r compiler alias.)
145
-dnl
146
-dnl If you are only building threads programs, you may wish to
147
-dnl use these variables in your default LIBS, CFLAGS, and CC:
148
-dnl
149
-dnl        LIBS="$PTHREAD_LIBS $LIBS"
150
-dnl        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
151
-dnl        CC="$PTHREAD_CC"
152
-dnl
153
-dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
154
-dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE
155
-dnl to that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
156
-dnl
157
-dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
158
-dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands
159
-dnl to run it if it is not found.  If ACTION-IF-FOUND is not specified,
160
-dnl the default action will define HAVE_PTHREAD.
161
-dnl
162
-dnl Please let the authors know if this macro fails on any platform,
163
-dnl or if you have any other suggestions or comments.  This macro was
164
-dnl based on work by SGJ on autoconf scripts for FFTW (www.fftw.org)
165
-dnl (with help from M. Frigo), as well as ac_pthread and hb_pthread
166
-dnl macros posted by AFC to the autoconf macro repository.  We are also
167
-dnl grateful for the helpful feedback of numerous users.
168
-dnl
169
-dnl @author Steven G. Johnson <stevenj@alum.mit.edu> and Alejandro Forero Cuervo <bachue@bachue.com>
170
-
171
-AC_DEFUN([ACX_PTHREAD], [
172
-AC_REQUIRE([AC_CANONICAL_HOST])
173
-acx_pthread_ok=no
174
-
175
-# We used to check for pthread.h first, but this fails if pthread.h
176
-# requires special compiler flags (e.g. on True64 or Sequent).
177
-# It gets checked for in the link test anyway.
178
-
179
-# First of all, check if the user has set any of the PTHREAD_LIBS,
180
-# etcetera environment variables, and if threads linking works using
181
-# them:
182
-if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
183
-        save_CFLAGS="$CFLAGS"
184
-        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
185
-        save_LIBS="$LIBS"
186
-        LIBS="$PTHREAD_LIBS $LIBS"
187
-        AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
188
-        AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
189
-        AC_MSG_RESULT($acx_pthread_ok)
190
-        if test x"$acx_pthread_ok" = xno; then
191
-                PTHREAD_LIBS=""
192
-                PTHREAD_CFLAGS=""
193
-        fi
194
-        LIBS="$save_LIBS"
195
-        CFLAGS="$save_CFLAGS"
196
-fi
197
-
198
-# We must check for the threads library under a number of different
199
-# names; the ordering is very important because some systems
200
-# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
201
-# libraries is broken (non-POSIX).
202
-
203
-# Create a list of thread flags to try.  Items starting with a "-" are
204
-# C compiler flags, and other items are library names, except for "none"
205
-# which indicates that we try without any flags at all.
206
-
207
-acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt"
208
-
209
-# The ordering *is* (sometimes) important.  Some notes on the
210
-# individual items follow:
211
-
212
-# pthreads: AIX (must check this before -lpthread)
213
-# none: in case threads are in libc; should be tried before -Kthread and
214
-#       other compiler flags to prevent continual compiler warnings
215
-# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
216
-# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
217
-# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
218
-# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
219
-# -pthreads: Solaris/gcc
220
-# -mthreads: Mingw32/gcc, Lynx/gcc
221
-# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
222
-#      doesn't hurt to check since this sometimes defines pthreads too;
223
-#      also defines -D_REENTRANT)
224
-# pthread: Linux, etcetera
225
-# --thread-safe: KAI C++
226
-
227
-case "$target" in
228
-        *solaris*)
229
-
230
-        # On Solaris (at least, for some versions), libc contains stubbed
231
-        # (non-functional) versions of the pthreads routines, so link-based
232
-        # tests will erroneously succeed.  (We need to link with -pthread or
233
-        # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
234
-        # a function called by this macro, so we could check for that, but
235
-        # who knows whether they'll stub that too in a future libc.)  So,
236
-        # we'll just look for -pthreads and -lpthread first:
237
-
238
-        acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags"
239
-        ;;
240
-esac
241
-
242
-if test x"$acx_pthread_ok" = xno; then
243
-for flag in $acx_pthread_flags; do
244
-
245
-        case $flag in
246
-                none)
247
-                AC_MSG_CHECKING([whether pthreads work without any flags])
248
-                ;;
249
-
250
-                -*)
251
-                AC_MSG_CHECKING([whether pthreads work with $flag])
252
-                PTHREAD_CFLAGS="$flag"
253
-                ;;
254
-
255
-                *)
256
-                AC_MSG_CHECKING([for the pthreads library -l$flag])
257
-                PTHREAD_LIBS="-l$flag"
258
-                ;;
259
-        esac
260
-
261
-        save_LIBS="$LIBS"
262
-        save_CFLAGS="$CFLAGS"
263
-        LIBS="$PTHREAD_LIBS $LIBS"
264
-        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
265
-
266
-        # Check for various functions.  We must include pthread.h,
267
-        # since some functions may be macros.  (On the Sequent, we
268
-        # need a special flag -Kthread to make this header compile.)
269
-        # We check for pthread_join because it is in -lpthread on IRIX
270
-        # while pthread_create is in libc.  We check for pthread_attr_init
271
-        # due to DEC craziness with -lpthreads.  We check for
272
-        # pthread_cleanup_push because it is one of the few pthread
273
-        # functions on Solaris that doesn't have a non-functional libc stub.
274
-        # We try pthread_create on general principles.
275
-        AC_TRY_LINK([#include <pthread.h>],
276
-                    [pthread_t th; pthread_join(th, 0);
277
-                     pthread_attr_init(0); pthread_cleanup_push(0, 0);
278
-                     pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
279
-                    [acx_pthread_ok=yes])
280
-
281
-        LIBS="$save_LIBS"
282
-        CFLAGS="$save_CFLAGS"
283
-
284
-        AC_MSG_RESULT($acx_pthread_ok)
285
-        if test "x$acx_pthread_ok" = xyes; then
286
-                break;
287
-        fi
288
-
289
-        PTHREAD_LIBS=""
290
-        PTHREAD_CFLAGS=""
291
-done
292
-fi
293
-
294
-# Various other checks:
295
-if test "x$acx_pthread_ok" = xyes; then
296
-        save_LIBS="$LIBS"
297
-        LIBS="$PTHREAD_LIBS $LIBS"
298
-        save_CFLAGS="$CFLAGS"
299
-        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
300
-
301
-        # Detect AIX lossage: threads are created detached by default
302
-        # and the JOINABLE attribute has a nonstandard name (UNDETACHED).
303
-        AC_MSG_CHECKING([for joinable pthread attribute])
304
-        AC_TRY_LINK([#include <pthread.h>],
305
-                    [int attr=PTHREAD_CREATE_JOINABLE;],
306
-                    ok=PTHREAD_CREATE_JOINABLE, ok=unknown)
307
-        if test x"$ok" = xunknown; then
308
-                AC_TRY_LINK([#include <pthread.h>],
309
-                            [int attr=PTHREAD_CREATE_UNDETACHED;],
310
-                            ok=PTHREAD_CREATE_UNDETACHED, ok=unknown)
311
-        fi
312
-        if test x"$ok" != xPTHREAD_CREATE_JOINABLE; then
313
-                AC_DEFINE(PTHREAD_CREATE_JOINABLE, $ok,
314
-                          [Define to the necessary symbol if this constant
315
-                           uses a non-standard name on your system.])
316
-        fi
317
-        AC_MSG_RESULT(${ok})
318
-        if test x"$ok" = xunknown; then
319
-                AC_MSG_WARN([we do not know how to create joinable pthreads])
320
-        fi
321
-
322
-        AC_MSG_CHECKING([if more special flags are required for pthreads])
323
-        flag=no
324
-        case "$target" in
325
-                *-aix* | *-freebsd*)               flag="-D_THREAD_SAFE";;
326
-                *solaris* | alpha*-osf* | *linux*) flag="-D_REENTRANT";;
327
-        esac
328
-        AC_MSG_RESULT(${flag})
329
-        if test "x$flag" != xno; then
330
-                PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
331
-        fi
332
-
333
-        LIBS="$save_LIBS"
334
-        CFLAGS="$save_CFLAGS"
335
-
336
-        # More AIX lossage: must compile with cc_r
337
-        AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC})
338
-else
339
-        PTHREAD_CC="$CC"
340
-fi
341
-
342
-AC_SUBST(PTHREAD_LIBS)
343
-AC_SUBST(PTHREAD_CFLAGS)
344
-AC_SUBST(PTHREAD_CC)
345
-
346
-# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
347
-if test x"$acx_pthread_ok" = xyes; then
348
-        ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
349
-        :
350
-else
351
-        acx_pthread_ok=no
352
-        $2
353
-fi
354
-
355
-])dnl ACX_PTHREAD
... ...
@@ -28,7 +28,6 @@
28 28
 #include "buffer.h"
29 29
 #include "error.h"
30 30
 #include "mtu.h"
31
-#include "thread.h"
32 31
 
33 32
 #include "memdbg.h"
34 33
 
... ...
@@ -26,7 +26,6 @@
26 26
 #define BUFFER_H
27 27
 
28 28
 #include "basic.h"
29
-#include "thread.h"
30 29
 
31 30
 #define BUF_SIZE_MAX 1000000
32 31
 
... ...
@@ -298,11 +298,6 @@ typedef unsigned long in_addr_t;
298 298
 /* Route command */
299 299
 #define ROUTE_PATH "route"
300 300
 
301
-/* Windows doesn't support PTHREAD yet */
302
-#ifdef USE_PTHREAD
303
-#error The Windows version of OpenVPN does not support PTHREAD yet
304
-#endif
305
-
306 301
 #ifdef _MSC_VER
307 302
 /* MSVC++ hacks */
308 303
 #include <io.h>
... ...
@@ -153,12 +153,6 @@ AC_ARG_ENABLE(small,
153 153
    [SMALL="no"]
154 154
 )
155 155
 
156
-AC_ARG_ENABLE(pthread,
157
-   [  --enable-pthread        Enable pthread support (Experimental for OpenVPN 2.0)],
158
-   [PTHREAD="$enableval"],
159
-   [PTHREAD="no"]
160
-)
161
-
162 156
 AC_ARG_ENABLE(password-save,
163 157
    [  --enable-password-save  Allow --askpass and --auth-user-pass passwords to be read from a file],
164 158
    [PASSWORD_SAVE="$enableval"],
... ...
@@ -566,32 +560,6 @@ if test "$MEMCHECK" = "valgrind"; then
566 566
 fi
567 567
 
568 568
 dnl
569
-dnl check for pthread library
570
-dnl
571
-
572
-if test "$PTHREAD" = "yes"; then
573
-  AC_CHECKING([for pthread support])
574
-  AC_MSG_RESULT([********* WARNING: pthread support is experimental for OpenVPN 2.0])
575
-  ACX_PTHREAD(
576
-        [
577
-	    case "$target" in
578
-	    *openbsd*)
579
-		AC_MSG_RESULT([WARNING: pthread support on OpenBSD is unstable!])
580
-		CFLAGS="$CFLAGS -pthread"
581
-		;;
582
-	    esac
583
-	    LIBS="$PTHREAD_LIBS $LIBS"
584
-	    CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
585
-	    CC="$PTHREAD_CC"
586
-	    AC_DEFINE(USE_PTHREAD, 1, [Use pthread-based multithreading])
587
-	],
588
-	[
589
-	    AC_MSG_RESULT([I don't know how to build with pthread support on this platform.])
590
-	    AC_MSG_ERROR([try ./configure --disable-pthread])
591
-	])
592
-fi
593
-
594
-dnl
595 569
 dnl check for dmalloc library
596 570
 dnl
597 571
 
... ...
@@ -600,11 +568,7 @@ if test "$MEMCHECK" = "dmalloc"; then
600 600
    AC_CHECK_HEADER(dmalloc.h, 
601 601
         [AC_CHECK_LIB(dmalloc, malloc,
602 602
 	    [
603
-               if test "$PTHREAD" = "yes"; then
604
-                   OPENVPN_ADD_LIBS(-ldmallocth)
605
-               else
606
-                   OPENVPN_ADD_LIBS(-ldmalloc)
607
-               fi
603
+               OPENVPN_ADD_LIBS(-ldmalloc)
608 604
 	       AC_DEFINE(DMALLOC, 1, [Use dmalloc memory debugging library])
609 605
 	    ],
610 606
 	    [AC_MSG_ERROR([dmalloc library not found.])]
... ...
@@ -29,7 +29,6 @@
29 29
 #include "crypto.h"
30 30
 #include "error.h"
31 31
 #include "misc.h"
32
-#include "thread.h"
33 32
 
34 33
 #include "memdbg.h"
35 34
 
... ...
@@ -1702,7 +1701,6 @@ prng_bytes (uint8_t *output, int len)
1702 1702
     {
1703 1703
       EVP_MD_CTX ctx;
1704 1704
       const int md_size = EVP_MD_size (nonce_md);
1705
-      mutex_lock_static (L_PRNG);
1706 1705
       while (len > 0)
1707 1706
 	{
1708 1707
 	  unsigned int outlen = 0;
... ...
@@ -1716,7 +1714,6 @@ prng_bytes (uint8_t *output, int len)
1716 1716
 	  output += blen;
1717 1717
 	  len -= blen;
1718 1718
 	}
1719
-      mutex_unlock_static (L_PRNG);
1720 1719
     }
1721 1720
   else
1722 1721
     RAND_bytes (output, len);
... ...
@@ -26,7 +26,6 @@
26 26
 
27 27
 #include "error.h"
28 28
 #include "buffer.h"
29
-#include "thread.h"
30 29
 #include "misc.h"
31 30
 #include "win32.h"
32 31
 #include "socket.h"
... ...
@@ -229,8 +228,6 @@ void x_msg (const unsigned int flags, const char *format, ...)
229 229
 
230 230
   gc_init (&gc);
231 231
 
232
-  mutex_lock_static (L_MSG);
233
-
234 232
   m1 = (char *) gc_malloc (ERR_BUF_SIZE, false, &gc);
235 233
   m2 = (char *) gc_malloc (ERR_BUF_SIZE, false, &gc);
236 234
 
... ...
@@ -330,22 +327,12 @@ void x_msg (const unsigned int flags, const char *format, ...)
330 330
 	    }
331 331
 	  else
332 332
 	    {
333
-#ifdef USE_PTHREAD
334
-	      fprintf (fp, "%s [%d] %s%s%s%s",
335
-		       time_string (0, 0, show_usec, &gc),
336
-		       (int) openvpn_thread_self (),
337
-		       prefix,
338
-		       prefix_sep,
339
-		       m1,
340
-		       (flags&M_NOLF) ? "" : "\n");
341
-#else
342 333
 	      fprintf (fp, "%s %s%s%s%s",
343 334
 		       time_string (0, 0, show_usec, &gc),
344 335
 		       prefix,
345 336
 		       prefix_sep,
346 337
 		       m1,
347 338
 		       (flags&M_NOLF) ? "" : "\n");
348
-#endif
349 339
 	    }
350 340
 	  fflush(fp);
351 341
 	  ++x_msg_line_num;
... ...
@@ -355,8 +342,6 @@ void x_msg (const unsigned int flags, const char *format, ...)
355 355
   if (flags & M_FATAL)
356 356
     msg (M_INFO, "Exiting");
357 357
 
358
-  mutex_unlock_static (L_MSG);
359
-  
360 358
   if (flags & M_FATAL)
361 359
     openvpn_exit (OPENVPN_EXIT_STATUS_ERROR); /* exit point */
362 360
 
... ...
@@ -645,10 +630,6 @@ x_check_status (int status,
645 645
  */
646 646
 const char *x_msg_prefix; /* GLOBAL */
647 647
 
648
-#ifdef USE_PTHREAD
649
-pthread_key_t x_msg_prefix_key; /* GLOBAL */
650
-#endif
651
-
652 648
 /*
653 649
  * Allow MSG to be redirected through a virtual_output object
654 650
  */
... ...
@@ -656,26 +637,6 @@ pthread_key_t x_msg_prefix_key; /* GLOBAL */
656 656
 const struct virtual_output *x_msg_virtual_output; /* GLOBAL */
657 657
 
658 658
 /*
659
- * Init thread-local variables
660
- */
661
-
662
-void
663
-msg_thread_init (void)
664
-{
665
-#ifdef USE_PTHREAD
666
-  ASSERT (!pthread_key_create (&x_msg_prefix_key, NULL));
667
-#endif
668
-}
669
-
670
-void
671
-msg_thread_uninit (void)
672
-{
673
-#ifdef USE_PTHREAD
674
-  pthread_key_delete (x_msg_prefix_key);
675
-#endif
676
-}
677
-
678
-/*
679 659
  * Exiting.
680 660
  */
681 661
 
... ...
@@ -26,7 +26,6 @@
26 26
 #define ERROR_H
27 27
 
28 28
 #include "basic.h"
29
-#include "thread.h"
30 29
 
31 30
 /* #define ABORT_ON_ERROR */
32 31
 
... ...
@@ -282,34 +281,18 @@ set_check_status_error_delay (unsigned int milliseconds)
282 282
 
283 283
 extern const char *x_msg_prefix;
284 284
 
285
-#ifdef USE_PTHREAD
286
-extern pthread_key_t x_msg_prefix_key;
287
-#endif
288
-
289 285
 void msg_thread_init (void);
290 286
 void msg_thread_uninit (void);
291 287
 
292 288
 static inline void
293 289
 msg_set_prefix (const char *prefix)
294 290
 {
295
-#ifdef USE_PTHREAD
296
-  if (openvpn_thread_enabled ())
297
-    {
298
-      ASSERT (!pthread_setspecific (x_msg_prefix_key, prefix));
299
-    }
300
-  else
301
-#endif
302 291
     x_msg_prefix = prefix;
303 292
 }
304 293
 
305 294
 static inline const char *
306 295
 msg_get_prefix (void)
307 296
 {
308
-#ifdef USE_PTHREAD
309
-  if (openvpn_thread_enabled ())
310
-    return (const char *) pthread_getspecific (x_msg_prefix_key);
311
-  else
312
-#endif
313 297
     return x_msg_prefix;
314 298
 }
315 299
 
... ...
@@ -506,8 +506,6 @@ init_static (void)
506 506
 void
507 507
 uninit_static (void)
508 508
 {
509
-  openvpn_thread_cleanup ();
510
-
511 509
 #ifdef USE_CRYPTO
512 510
   free_ssl_lib ();
513 511
 #endif
... ...
@@ -3280,23 +3278,6 @@ close_context (struct context *c, int sig, unsigned int flags)
3280 3280
 
3281 3281
 #ifdef USE_CRYPTO
3282 3282
 
3283
-static void
3284
-test_malloc (void)
3285
-{
3286
-  int i, j;
3287
-  msg (M_INFO, "Multithreaded malloc test...");
3288
-  for (i = 0; i < 25; ++i)
3289
-    {
3290
-      struct gc_arena gc = gc_new ();
3291
-      const int limit = get_random () & 0x03FF;
3292
-      for (j = 0; j < limit; ++j)
3293
-	{
3294
-	  gc_malloc (get_random () & 0x03FF, false, &gc);
3295
-	}
3296
-      gc_free (&gc);
3297
-    }
3298
-}
3299
-
3300 3283
 /*
3301 3284
  * Do a loopback test
3302 3285
  * on the crypto subsystem.
... ...
@@ -3306,50 +3287,19 @@ test_crypto_thread (void *arg)
3306 3306
 {
3307 3307
   struct context *c = (struct context *) arg;
3308 3308
   const struct options *options = &c->options;
3309
-#if defined(USE_PTHREAD)
3310
-  struct context *child = NULL;
3311
-  openvpn_thread_t child_id = 0;
3312
-#endif
3313 3309
 
3314 3310
   ASSERT (options->test_crypto);
3315 3311
   init_verb_mute (c, IVM_LEVEL_1);
3316 3312
   context_init_1 (c);
3317 3313
   do_init_crypto_static (c, 0);
3318 3314
 
3319
-#if defined(USE_PTHREAD)
3320
-  {
3321
-    if (c->first_time && options->n_threads > 1)
3322
-      {
3323
-	if (options->n_threads > 2)
3324
-	  msg (M_FATAL, "ERROR: --test-crypto option only works with --threads set to 1 or 2");
3325
-	openvpn_thread_init ();
3326
-	ALLOC_OBJ (child, struct context);
3327
-	context_clear (child);
3328
-	child->options = *options;
3329
-	options_detach (&child->options);
3330
-	child->first_time = false;
3331
-	child_id = openvpn_thread_create (test_crypto_thread, (void *) child);
3332
-      }
3333
-  }
3334
-#endif
3335 3315
   frame_finalize_options (c, options);
3336 3316
 
3337
-#if defined(USE_PTHREAD)
3338
-  if (options->n_threads == 2)
3339
-    test_malloc ();
3340
-#endif
3341
-
3342 3317
   test_crypto (&c->c2.crypto_options, &c->c2.frame);
3343 3318
 
3344 3319
   key_schedule_free (&c->c1.ks, true);
3345 3320
   packet_id_free (&c->c2.packet_id);
3346 3321
 
3347
-#if defined(USE_PTHREAD)
3348
-  if (c->first_time && options->n_threads > 1)
3349
-    openvpn_thread_join (child_id);
3350
-  if (child)
3351
-    free (child);
3352
-#endif
3353 3322
   context_gc_free (c);
3354 3323
   return NULL;
3355 3324
 }
... ...
@@ -52,7 +52,6 @@ hash_init (const int n_buckets,
52 52
     {
53 53
       struct hash_bucket *b = &h->buckets[i];
54 54
       b->list = NULL;
55
-      mutex_init (&b->mutex);
56 55
     }
57 56
   return h;
58 57
 }
... ...
@@ -66,7 +65,6 @@ hash_free (struct hash *hash)
66 66
       struct hash_bucket *b = &hash->buckets[i];
67 67
       struct hash_element *he = b->list;
68 68
 
69
-      mutex_destroy (&b->mutex);
70 69
       while (he)
71 70
 	{
72 71
 	  struct hash_element *next = he->next;
... ...
@@ -148,7 +146,6 @@ hash_add (struct hash *hash, const void *key, void *value, bool replace)
148 148
 
149 149
   hv = hash_value (hash, key);
150 150
   bucket = &hash->buckets[hv & hash->mask];
151
-  mutex_lock (&bucket->mutex);
152 151
 
153 152
   if ((he = hash_lookup_fast (hash, bucket, key, hv))) /* already exists? */
154 153
     {
... ...
@@ -164,8 +161,6 @@ hash_add (struct hash *hash, const void *key, void *value, bool replace)
164 164
       ret = true;
165 165
     }
166 166
 
167
-  mutex_unlock (&bucket->mutex);
168
-
169 167
   return ret;
170 168
 }
171 169
 
... ...
@@ -257,10 +252,6 @@ hash_iterator_init (struct hash *hash,
257 257
 static inline void
258 258
 hash_iterator_lock (struct hash_iterator *hi, struct hash_bucket *b)
259 259
 {
260
-  if (hi->autolock)
261
-    {
262
-      mutex_lock (&b->mutex);
263
-    }
264 260
   hi->bucket = b;
265 261
   hi->last = NULL;
266 262
   hi->bucket_marked = false;
... ...
@@ -276,10 +267,6 @@ hash_iterator_unlock (struct hash_iterator *hi)
276 276
 	  hash_remove_marked (hi->hash, hi->bucket);
277 277
 	  hi->bucket_marked = false;
278 278
 	}
279
-      if (hi->autolock)
280
-	{
281
-	  mutex_unlock (&hi->bucket->mutex);
282
-	}
283 279
       hi->bucket = NULL;
284 280
       hi->last = NULL;
285 281
     }
... ...
@@ -40,7 +40,6 @@
40 40
 /*#define LIST_TEST*/
41 41
 
42 42
 #include "basic.h"
43
-#include "thread.h"
44 43
 #include "buffer.h"
45 44
 
46 45
 #define hashsize(n) ((uint32_t)1<<(n))
... ...
@@ -56,7 +55,6 @@ struct hash_element
56 56
 
57 57
 struct hash_bucket
58 58
 {
59
-  MUTEX_DEFINE (mutex);
60 59
   struct hash_element *list;
61 60
 };
62 61
 
... ...
@@ -152,13 +150,11 @@ hash_bucket (struct hash *hash, uint32_t hv)
152 152
 static inline void
153 153
 hash_bucket_lock (struct hash_bucket *bucket)
154 154
 {
155
-  mutex_lock (&bucket->mutex);
156 155
 }
157 156
 
158 157
 static inline void
159 158
 hash_bucket_unlock (struct hash_bucket *bucket)
160 159
 {
161
-  mutex_unlock (&bucket->mutex);
162 160
 }
163 161
 
164 162
 static inline void *
... ...
@@ -168,11 +164,9 @@ hash_lookup_lock (struct hash *hash, const void *key, uint32_t hv)
168 168
   struct hash_element *he;
169 169
   struct hash_bucket *bucket = &hash->buckets[hv & hash->mask];
170 170
 
171
-  mutex_lock (&bucket->mutex);
172 171
   he = hash_lookup_fast (hash, bucket, key, hv);
173 172
   if (he)
174 173
     ret = he->value;
175
-  mutex_unlock (&bucket->mutex);
176 174
 
177 175
   return ret;
178 176
 }
... ...
@@ -211,9 +205,7 @@ hash_remove (struct hash *hash, const void *key)
211 211
 
212 212
   hv = hash_value (hash, key);
213 213
   bucket = &hash->buckets[hv & hash->mask];
214
-  mutex_lock (&bucket->mutex);
215 214
   ret = hash_remove_fast (hash, bucket, key, hv);
216
-  mutex_unlock (&bucket->mutex);
217 215
   return ret;
218 216
 }
219 217
 
... ...
@@ -38,7 +38,6 @@ mbuf_init (unsigned int size)
38 38
 {
39 39
   struct mbuf_set *ret;
40 40
   ALLOC_OBJ_CLEAR (ret, struct mbuf_set);
41
-  mutex_init (&ret->mutex);
42 41
   ret->capacity = adjust_power_of_2 (size);
43 42
   ALLOC_ARRAY (ret->array, struct mbuf_item, ret->capacity);
44 43
   return ret;
... ...
@@ -56,7 +55,6 @@ mbuf_free (struct mbuf_set *ms)
56 56
 	  mbuf_free_buf (item->buffer);
57 57
 	}
58 58
       free (ms->array);
59
-      mutex_destroy (&ms->mutex);
60 59
       free (ms);
61 60
     }
62 61
 }
... ...
@@ -89,7 +87,6 @@ void
89 89
 mbuf_add_item (struct mbuf_set *ms, const struct mbuf_item *item)
90 90
 {
91 91
   ASSERT (ms);
92
-  mutex_lock (&ms->mutex);
93 92
   if (ms->len == ms->capacity)
94 93
     {
95 94
       struct mbuf_item rm;
... ...
@@ -104,7 +101,6 @@ mbuf_add_item (struct mbuf_set *ms, const struct mbuf_item *item)
104 104
   if (++ms->len > ms->max_queued)
105 105
     ms->max_queued = ms->len;
106 106
   ++item->buffer->refcount;
107
-  mutex_unlock (&ms->mutex);
108 107
 }
109 108
 
110 109
 bool
... ...
@@ -113,8 +109,6 @@ mbuf_extract_item (struct mbuf_set *ms, struct mbuf_item *item, const bool lock)
113 113
   bool ret = false;
114 114
   if (ms)
115 115
     {
116
-      if (lock)
117
-	mutex_lock (&ms->mutex);
118 116
       while (ms->len)
119 117
 	{
120 118
 	  *item = ms->array[ms->head];
... ...
@@ -126,8 +120,6 @@ mbuf_extract_item (struct mbuf_set *ms, struct mbuf_item *item, const bool lock)
126 126
 	      break;
127 127
 	    }
128 128
 	}
129
-      if (lock)
130
-	mutex_unlock (&ms->mutex);
131 129
     }
132 130
   return ret;
133 131
 }
... ...
@@ -139,7 +131,6 @@ mbuf_peek_dowork (struct mbuf_set *ms)
139 139
   if (ms)
140 140
     {
141 141
       int i;
142
-      mutex_lock (&ms->mutex);
143 142
       for (i = 0; i < (int) ms->len; ++i)
144 143
 	{
145 144
 	  struct mbuf_item *item = &ms->array[MBUF_INDEX(ms->head, i, ms->capacity)];
... ...
@@ -149,7 +140,6 @@ mbuf_peek_dowork (struct mbuf_set *ms)
149 149
 	      break;
150 150
 	    }
151 151
 	}
152
-      mutex_unlock (&ms->mutex);
153 152
     }
154 153
   return ret;
155 154
 }
... ...
@@ -160,7 +150,6 @@ mbuf_dereference_instance (struct mbuf_set *ms, struct multi_instance *mi)
160 160
   if (ms)
161 161
     {
162 162
       int i;
163
-      mutex_lock (&ms->mutex);
164 163
       for (i = 0; i < (int) ms->len; ++i)
165 164
 	{
166 165
 	  struct mbuf_item *item = &ms->array[MBUF_INDEX(ms->head, i, ms->capacity)];
... ...
@@ -172,7 +161,6 @@ mbuf_dereference_instance (struct mbuf_set *ms, struct multi_instance *mi)
172 172
 	      msg (D_MBUF, "MBUF: dereferenced queued packet");
173 173
 	    }
174 174
 	}
175
-      mutex_unlock (&ms->mutex);
176 175
     }
177 176
 }
178 177
 
... ...
@@ -58,7 +58,6 @@ struct mbuf_item
58 58
 
59 59
 struct mbuf_set
60 60
 {
61
-  MUTEX_DEFINE (mutex);
62 61
   unsigned int head;
63 62
   unsigned int len;
64 63
   unsigned int capacity;
... ...
@@ -28,7 +28,6 @@
28 28
 #include "misc.h"
29 29
 #include "tun.h"
30 30
 #include "error.h"
31
-#include "thread.h"
32 31
 #include "otime.h"
33 32
 #include "plugin.h"
34 33
 #include "options.h"
... ...
@@ -639,9 +638,7 @@ strerror_ts (int errnum, struct gc_arena *gc)
639 639
 #ifdef HAVE_STRERROR
640 640
   struct buffer out = alloc_buf_gc (256, gc);
641 641
 
642
-  mutex_lock_static (L_STRERR);
643 642
   buf_printf (&out, "%s", openvpn_strerror (errnum, gc));
644
-  mutex_unlock_static (L_STRERR);
645 643
   return BSTR (&out);
646 644
 #else
647 645
   return "[error string unavailable]";
... ...
@@ -779,18 +776,15 @@ struct env_set *
779 779
 env_set_create (struct gc_arena *gc)
780 780
 {
781 781
   struct env_set *es;
782
-  mutex_lock_static (L_ENV_SET);
783 782
   ALLOC_OBJ_CLEAR_GC (es, struct env_set, gc);
784 783
   es->list = NULL;
785 784
   es->gc = gc;
786
-  mutex_unlock_static (L_ENV_SET);
787 785
   return es;
788 786
 }
789 787
 
790 788
 void
791 789
 env_set_destroy (struct env_set *es)
792 790
 {
793
-  mutex_lock_static (L_ENV_SET);
794 791
   if (es && es->gc == NULL)
795 792
     {
796 793
       struct env_item *e = es->list;
... ...
@@ -803,7 +797,6 @@ env_set_destroy (struct env_set *es)
803 803
 	}
804 804
       free (es);
805 805
     }
806
-  mutex_unlock_static (L_ENV_SET);
807 806
 }
808 807
 
809 808
 bool
... ...
@@ -812,9 +805,7 @@ env_set_del (struct env_set *es, const char *str)
812 812
   bool ret;
813 813
   ASSERT (es);
814 814
   ASSERT (str);
815
-  mutex_lock_static (L_ENV_SET);
816 815
   ret = env_set_del_nolock (es, str);
817
-  mutex_unlock_static (L_ENV_SET);
818 816
   return ret;
819 817
 }
820 818
 
... ...
@@ -823,9 +814,7 @@ env_set_add (struct env_set *es, const char *str)
823 823
 {
824 824
   ASSERT (es);
825 825
   ASSERT (str);
826
-  mutex_lock_static (L_ENV_SET);
827 826
   env_set_add_nolock (es, str);
828
-  mutex_unlock_static (L_ENV_SET);
829 827
 }
830 828
 
831 829
 void
... ...
@@ -838,7 +827,6 @@ env_set_print (int msglevel, const struct env_set *es)
838 838
 
839 839
       if (es)
840 840
 	{
841
-	  mutex_lock_static (L_ENV_SET);
842 841
 	  e = es->list;
843 842
 	  i = 0;
844 843
 
... ...
@@ -849,7 +837,6 @@ env_set_print (int msglevel, const struct env_set *es)
849 849
 	      ++i;
850 850
 	      e = e->next;
851 851
 	    }
852
-	  mutex_unlock_static (L_ENV_SET);
853 852
 	}
854 853
     }
855 854
 }
... ...
@@ -863,14 +850,12 @@ env_set_inherit (struct env_set *es, const struct env_set *src)
863 863
 
864 864
   if (src)
865 865
     {
866
-      mutex_lock_static (L_ENV_SET);
867 866
       e = src->list;
868 867
       while (e)
869 868
 	{
870 869
 	  env_set_add_nolock (es, e->string);
871 870
 	  e = e->next;
872 871
 	}
873
-      mutex_unlock_static (L_ENV_SET);
874 872
     }
875 873
 }
876 874
 
... ...
@@ -882,7 +867,6 @@ env_set_add_to_environment (const struct env_set *es)
882 882
       struct gc_arena gc = gc_new ();
883 883
       const struct env_item *e;
884 884
 
885
-      mutex_lock_static (L_ENV_SET);
886 885
       e = es->list;
887 886
 
888 887
       while (e)
... ...
@@ -895,7 +879,6 @@ env_set_add_to_environment (const struct env_set *es)
895 895
 
896 896
 	  e = e->next;
897 897
 	}
898
-      mutex_unlock_static (L_ENV_SET);
899 898
       gc_free (&gc);
900 899
     }
901 900
 }
... ...
@@ -908,7 +891,6 @@ env_set_remove_from_environment (const struct env_set *es)
908 908
       struct gc_arena gc = gc_new ();
909 909
       const struct env_item *e;
910 910
 
911
-      mutex_lock_static (L_ENV_SET);
912 911
       e = es->list;
913 912
 
914 913
       while (e)
... ...
@@ -921,7 +903,6 @@ env_set_remove_from_environment (const struct env_set *es)
921 921
 
922 922
 	  e = e->next;
923 923
 	}
924
-      mutex_unlock_static (L_ENV_SET);
925 924
       gc_free (&gc);
926 925
     }
927 926
 }
... ...
@@ -1040,12 +1021,10 @@ setenv_str_ex (struct env_set *es,
1040 1040
 	char *str = construct_name_value (name_tmp, val_tmp, NULL);
1041 1041
 	int status;
1042 1042
 
1043
-	mutex_lock_static (L_PUTENV);
1044 1043
 	status = putenv (str);
1045 1044
 	/*msg (M_INFO, "PUTENV '%s'", str);*/
1046 1045
 	if (!status)
1047 1046
 	  manage_env (str);
1048
-	mutex_unlock_static (L_PUTENV);
1049 1047
 	if (status)
1050 1048
 	  msg (M_WARN | M_ERRNO, "putenv('%s') failed", str);
1051 1049
       }
... ...
@@ -1173,9 +1152,7 @@ create_temp_filename (const char *directory, const char *prefix, struct gc_arena
1173 1173
   static unsigned int counter;
1174 1174
   struct buffer fname = alloc_buf_gc (256, gc);
1175 1175
 
1176
-  mutex_lock_static (L_CREATE_TEMP);
1177 1176
   ++counter;
1178
-  mutex_unlock_static (L_CREATE_TEMP);
1179 1177
 
1180 1178
   {
1181 1179
     uint8_t rndbytes[16];
... ...
@@ -633,7 +633,6 @@ multi_create_instance (struct multi_context *m, const struct mroute_addr *real)
633 633
 
634 634
   ALLOC_OBJ_CLEAR (mi, struct multi_instance);
635 635
 
636
-  mutex_init (&mi->mutex);
637 636
   mi->gc = gc_new ();
638 637
   multi_instance_inc_refcount (mi);
639 638
   mi->vaddr_handle = -1;
... ...
@@ -56,7 +56,6 @@ struct multi_reap
56 56
 struct multi_instance {
57 57
   struct schedule_entry se;    /* this must be the first element of the structure */
58 58
   struct gc_arena gc;
59
-  MUTEX_DEFINE (mutex);
60 59
   bool defined;
61 60
   bool halt;
62 61
   int refcount;
... ...
@@ -274,7 +273,6 @@ multi_instance_dec_refcount (struct multi_instance *mi)
274 274
   if (--mi->refcount <= 0)
275 275
     {
276 276
       gc_free (&mi->gc);
277
-      mutex_destroy (&mi->mutex);
278 277
       free (mi);
279 278
     }
280 279
 }
... ...
@@ -69,9 +69,6 @@ const char title_string[] =
69 69
 #ifdef PRODUCT_TAP_DEBUG
70 70
   " [TAPDBG]"
71 71
 #endif
72
-#ifdef USE_PTHREAD
73
-  " [PTHREAD]"
74
-#endif
75 72
 #ifdef ENABLE_PKCS11
76 73
   " [PKCS11]"
77 74
 #endif
... ...
@@ -288,13 +285,6 @@ static const char usage_message[] =
288 288
   "--suppress-timestamps : Don't log timestamps to stdout/stderr.\n"
289 289
   "--writepid file : Write main process ID to file.\n"
290 290
   "--nice n        : Change process priority (>0 = lower, <0 = higher).\n"
291
-#if 0
292
-#ifdef USE_PTHREAD
293
-  "--nice-work n   : Change thread priority of work thread.  The work\n"
294
-  "                  thread is used for background processing such as\n"
295
-  "                  RSA key number crunching.\n"
296
-#endif
297
-#endif
298 291
   "--echo [parms ...] : Echo parameters to log output.\n"
299 292
   "--verb n        : Set output verbosity to n (default=%d):\n"
300 293
   "                  (Level 3 is recommended if you want a good summary\n"
... ...
@@ -725,9 +715,6 @@ init_options (struct options *o, const bool init_gc)
725 725
   o->tuntap_options.dhcp_masq_offset = 0;       /* use network address as internal DHCP server address */
726 726
   o->route_method = ROUTE_METHOD_ADAPTIVE;
727 727
 #endif
728
-#ifdef USE_PTHREAD
729
-  o->n_threads = 1;
730
-#endif
731 728
 #if P2MP_SERVER
732 729
   o->real_hash_size = 256;
733 730
   o->virtual_hash_size = 256;
... ...
@@ -875,9 +862,6 @@ is_persist_option (const struct options *o)
875 875
       || o->persist_key
876 876
       || o->persist_local_ip
877 877
       || o->persist_remote_ip
878
-#ifdef USE_PTHREAD
879
-      || o->n_threads >= 2
880
-#endif
881 878
     ;
882 879
 }
883 880
 
... ...
@@ -4033,26 +4017,6 @@ add_option (struct options *options,
4033 4033
       goto err;
4034 4034
 #endif
4035 4035
     }
4036
-#ifdef USE_PTHREAD
4037
-  else if (streq (p[0], "nice-work") && p[1])
4038
-    {
4039
-      VERIFY_PERMISSION (OPT_P_NICE);
4040
-      options->nice_work = atoi (p[1]);
4041
-    }
4042
-  else if (streq (p[0], "threads") && p[1])
4043
-    {
4044
-      int n_threads;
4045
-
4046
-      VERIFY_PERMISSION (OPT_P_GENERAL);
4047
-      n_threads = positive_atoi (p[1]);
4048
-      if (n_threads < 1)
4049
-	{
4050
-	  msg (msglevel, "--threads parameter must be at least 1");
4051
-	  goto err;
4052
-	}
4053
-      options->n_threads = n_threads;
4054
-    }
4055
-#endif
4056 4036
   else if (streq (p[0], "shaper") && p[1])
4057 4037
     {
4058 4038
 #ifdef HAVE_GETTIMEOFDAY
... ...
@@ -328,11 +328,6 @@ struct options
328 328
   struct plugin_option_list *plugin_list;
329 329
 #endif
330 330
 
331
-#ifdef USE_PTHREAD
332
-  int n_threads;
333
-  int nice_work;
334
-#endif
335
-
336 331
 #if P2MP
337 332
 
338 333
 #if P2MP_SERVER
... ...
@@ -123,10 +123,8 @@ time_string (time_t t, int usec, bool show_usec, struct gc_arena *gc)
123 123
 	}
124 124
     }
125 125
 
126
-  mutex_lock_static (L_CTIME);
127 126
   t = tv.tv_sec;
128 127
   buf_printf (&out, "%s", ctime(&t));
129
-  mutex_unlock_static (L_CTIME);
130 128
   buf_rmtail (&out, '\n');
131 129
 
132 130
   if (show_usec && tv.tv_usec)
... ...
@@ -28,7 +28,6 @@
28 28
 #include "common.h"
29 29
 #include "integer.h"
30 30
 #include "buffer.h"
31
-#include "thread.h"
32 31
 
33 32
 struct frequency_limit
34 33
 {
... ...
@@ -33,10 +33,6 @@
33 33
 
34 34
 #include "memdbg.h"
35 35
 
36
-#ifdef USE_PTHREAD
37
-#error ENABLE_PERFORMANCE_METRICS is incompatible with USE_PTHREAD
38
-#endif
39
-
40 36
 static const char *metric_names[] = {
41 37
   "PERF_BIO_READ_PLAINTEXT",
42 38
   "PERF_BIO_WRITE_PLAINTEXT",
... ...
@@ -558,8 +558,6 @@ plugin_call (const struct plugin_list *pl,
558 558
       bool error = false;
559 559
       bool deferred = false;
560 560
       
561
-      mutex_lock_static (L_PLUGIN);
562
-
563 561
       setenv_del (es, "script_type");
564 562
       envp = make_env_array (es, false, &gc);
565 563
 
... ...
@@ -588,8 +586,6 @@ plugin_call (const struct plugin_list *pl,
588 588
       if (pr)
589 589
 	pr->n = i;
590 590
 
591
-      mutex_unlock_static (L_PLUGIN);
592
-
593 591
       gc_free (&gc);
594 592
 
595 593
       if (type == OPENVPN_PLUGIN_ENABLE_PF && success)
... ...
@@ -31,7 +31,6 @@
31 31
 
32 32
 #include "basic.h"
33 33
 #include "status.h"
34
-#include "thread.h"
35 34
 
36 35
 #define IFCONFIG_POOL_MAX         65536
37 36
 #define IFCONFIG_POOL_MIN_NETBITS    16
... ...
@@ -363,24 +363,20 @@ schedule_init (void)
363 363
   struct schedule *s;
364 364
 
365 365
   ALLOC_OBJ_CLEAR (s, struct schedule);
366
-  mutex_init (&s->mutex);
367 366
   return s;
368 367
 }
369 368
 
370 369
 void
371 370
 schedule_free (struct schedule *s)
372 371
 {
373
-  mutex_destroy (&s->mutex);
374 372
   free (s);
375 373
 }
376 374
 
377 375
 void
378 376
 schedule_remove_entry (struct schedule *s, struct schedule_entry *e)
379 377
 {
380
-  mutex_lock (&s->mutex);
381 378
   s->earliest_wakeup = NULL; /* invalidate cache */
382 379
   schedule_remove_node (s, e);
383
-  mutex_unlock (&s->mutex);
384 380
 }
385 381
 
386 382
 /*
... ...
@@ -42,7 +42,6 @@
42 42
 /*#define SCHEDULE_TEST*/
43 43
 
44 44
 #include "otime.h"
45
-#include "thread.h"
46 45
 #include "error.h"
47 46
 
48 47
 struct schedule_entry
... ...
@@ -56,7 +55,6 @@ struct schedule_entry
56 56
 
57 57
 struct schedule
58 58
 {
59
-  MUTEX_DEFINE (mutex);
60 59
   struct schedule_entry *earliest_wakeup; /* cached earliest wakeup */
61 60
   struct schedule_entry *root;            /* the root of the treap (btree) */
62 61
 };
... ...
@@ -100,14 +98,12 @@ schedule_add_entry (struct schedule *s,
100 100
 		    const struct timeval *tv,
101 101
 		    unsigned int sigma)
102 102
 {
103
-  mutex_lock (&s->mutex);
104 103
   if (!IN_TREE (e) || !sigma || !tv_within_sigma (tv, &e->tv, sigma))
105 104
     {
106 105
       e->tv = *tv;
107 106
       schedule_add_modify (s, e);
108 107
       s->earliest_wakeup = NULL; /* invalidate cache */
109 108
     }
110
-  mutex_unlock (&s->mutex);
111 109
 }
112 110
 
113 111
 /*
... ...
@@ -122,8 +118,6 @@ schedule_get_earliest_wakeup (struct schedule *s,
122 122
 {
123 123
   struct schedule_entry *ret;
124 124
 
125
-  mutex_lock (&s->mutex);
126
-
127 125
   /* cache result */
128 126
   if (!s->earliest_wakeup)
129 127
     s->earliest_wakeup = schedule_find_least (s->root);
... ...
@@ -131,8 +125,6 @@ schedule_get_earliest_wakeup (struct schedule *s,
131 131
   if (ret)
132 132
     *wakeup = ret->tv;
133 133
 
134
-  mutex_unlock (&s->mutex);
135
-
136 134
   return ret;
137 135
 }
138 136
 
... ...
@@ -26,7 +26,6 @@
26 26
 
27 27
 #include "socket.h"
28 28
 #include "fdmisc.h"
29
-#include "thread.h"
30 29
 #include "misc.h"
31 30
 #include "gremlin.h"
32 31
 #include "plugin.h"
... ...
@@ -1933,10 +1932,8 @@ print_sockaddr_ex (const struct openvpn_sockaddr *addr,
1933 1933
       struct buffer out = alloc_buf_gc (64, gc);
1934 1934
       const int port = ntohs (addr->sa.sin_port);
1935 1935
 
1936
-      mutex_lock_static (L_INET_NTOA);
1937 1936
       if (!(flags & PS_DONT_SHOW_ADDR))
1938 1937
 	buf_printf (&out, "%s", (addr_defined (addr) ? inet_ntoa (addr->sa.sin_addr) : "[undef]"));
1939
-      mutex_unlock_static (L_INET_NTOA);
1940 1938
 
1941 1939
       if (((flags & PS_SHOW_PORT) || (addr_defined (addr) && (flags & PS_SHOW_PORT_IF_DEFINED)))
1942 1940
 	  && port)
... ...
@@ -1998,9 +1995,7 @@ print_in_addr_t (in_addr_t addr, unsigned int flags, struct gc_arena *gc)
1998 1998
       CLEAR (ia);
1999 1999
       ia.s_addr = (flags & IA_NET_ORDER) ? addr : htonl (addr);
2000 2000
 
2001
-      mutex_lock_static (L_INET_NTOA);
2002 2001
       buf_printf (&out, "%s", inet_ntoa (ia));
2003
-      mutex_unlock_static (L_INET_NTOA);
2004 2002
     }
2005 2003
   return BSTR (&out);
2006 2004
 }
... ...
@@ -2016,9 +2011,7 @@ setenv_sockaddr (struct env_set *es, const char *name_prefix, const struct openv
2016 2016
   else
2017 2017
     openvpn_snprintf (name_buf, sizeof (name_buf), "%s", name_prefix);
2018 2018
 
2019
-  mutex_lock_static (L_INET_NTOA);
2020 2019
   setenv_str (es, name_buf, inet_ntoa (addr->sa.sin_addr));
2021
-  mutex_unlock_static (L_INET_NTOA);
2022 2020
 
2023 2021
   if ((flags & SA_IP_PORT) && addr->sa.sin_port)
2024 2022
     {
... ...
@@ -39,7 +39,6 @@
39 39
 #include "common.h"
40 40
 #include "integer.h"
41 41
 #include "socket.h"
42
-#include "thread.h"
43 42
 #include "misc.h"
44 43
 #include "fdmisc.h"
45 44
 #include "interval.h"
... ...
@@ -42,7 +42,6 @@
42 42
 #include "reliable.h"
43 43
 #include "socket.h"
44 44
 #include "mtu.h"
45
-#include "thread.h"
46 45
 #include "options.h"
47 46
 #include "plugin.h"
48 47
 
... ...
@@ -538,24 +538,6 @@ socket_defined (const socket_descriptor_t sd)
538 538
 #endif
539 539
 
540 540
 /*
541
- * Do we have pthread capability?
542
- */
543
-#ifdef USE_PTHREAD
544
-#if defined(USE_CRYPTO) && defined(USE_SSL) && P2MP
545
-#include <pthread.h>
546
-#else
547
-#undef USE_PTHREAD
548
-#endif
549
-#endif
550
-
551
-/*
552
- * Pthread support is currently experimental (and quite unfinished).
553
- */
554
-#if 1 /* JYFIXME -- if defined, disable pthread */
555
-#undef USE_PTHREAD
556
-#endif
557
-
558
-/*
559 541
  * Should we include OCC (options consistency check) code?
560 542
  */
561 543
 #ifndef ENABLE_SMALL
562 544
deleted file mode 100644
... ...
@@ -1,156 +0,0 @@
1
-/*
2
- *  OpenVPN -- An application to securely tunnel IP networks
3
- *             over a single UDP port, with support for SSL/TLS-based
4
- *             session authentication and key exchange,
5
- *             packet encryption, packet authentication, and
6
- *             packet compression.
7
- *
8
- *  Copyright (C) 2002-2009 OpenVPN Technologies, Inc. <sales@openvpn.net>
9
- *
10
- *  This program is free software; you can redistribute it and/or modify
11
- *  it under the terms of the GNU General Public License version 2
12
- *  as published by the Free Software Foundation.
13
- *
14
- *  This program is distributed in the hope that it will be useful,
15
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
- *  GNU General Public License for more details.
18
- *
19
- *  You should have received a copy of the GNU General Public License
20
- *  along with this program (see the file COPYING included with this
21
- *  distribution); if not, write to the Free Software Foundation, Inc.,
22
- *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
- */
24
-
25
-#include "syshead.h"
26
-
27
-#ifdef USE_PTHREAD
28
-
29
-#include "thread.h"
30
-#include "buffer.h"
31
-#include "common.h"
32
-#include "error.h"
33
-#include "crypto.h"
34
-
35
-#include "memdbg.h"
36
-
37
-static struct sparse_mutex *ssl_mutex;  /* GLOBAL */
38
-
39
-static void
40
-ssl_pthreads_locking_callback (int mode, int type, char *file, int line)
41
-{
42
-  dmsg (D_OPENSSL_LOCK, "SSL LOCK thread=%4lu mode=%s lock=%s %s:%d",
43
-	   CRYPTO_thread_id (),
44
-	   (mode & CRYPTO_LOCK) ? "l" : "u",
45
-	   (type & CRYPTO_READ) ? "r" : "w", file, line);
46
-
47
-  if (mode & CRYPTO_LOCK)
48
-    pthread_mutex_lock (&ssl_mutex[type].mutex);
49
-  else
50
-    pthread_mutex_unlock (&ssl_mutex[type].mutex);
51
-}
52
-
53
-static unsigned long
54
-ssl_pthreads_thread_id (void)
55
-{
56
-  unsigned long ret;
57
-
58
-  ret = (unsigned long) pthread_self ();
59
-  return ret;
60
-}
61
-
62
-static void
63
-ssl_thread_setup (void)
64
-{
65
-  int i;
66
-
67
-#error L_MSG needs to be initialized as a recursive mutex
68
-
69
-  ssl_mutex = OPENSSL_malloc (CRYPTO_num_locks () * sizeof (struct sparse_mutex));
70
-  for (i = 0; i < CRYPTO_num_locks (); i++)
71
-    pthread_mutex_init (&ssl_mutex[i].mutex, NULL);
72
-
73
-  CRYPTO_set_id_callback ((unsigned long (*)(void)) ssl_pthreads_thread_id);
74
-  CRYPTO_set_locking_callback ((void (*)(int, int, const char*, int)) ssl_pthreads_locking_callback);
75
-}
76
-
77
-static void
78
-ssl_thread_cleanup (void)
79
-{
80
-  int i;
81
-
82
-  dmsg (D_OPENSSL_LOCK, "SSL LOCK cleanup");
83
-  CRYPTO_set_locking_callback (NULL);
84
-  for (i = 0; i < CRYPTO_num_locks (); i++)
85
-    pthread_mutex_destroy (&ssl_mutex[i].mutex);
86
-  OPENSSL_free (ssl_mutex);
87
-}
88
-
89
-struct sparse_mutex mutex_array[N_MUTEXES]; /* GLOBAL */
90
-bool pthread_initialized;                   /* GLOBAL */
91
-
92
-openvpn_thread_t
93
-openvpn_thread_create (void *(*start_routine) (void *), void* arg)
94
-{
95
-  openvpn_thread_t ret;
96
-  ASSERT (pthread_initialized);
97
-  ASSERT (!pthread_create (&ret, NULL, start_routine, arg));
98
-  dmsg (D_THREAD_DEBUG, "CREATE THREAD ID=%lu", (unsigned long)ret);
99
-  return ret;
100
-}
101
-
102
-void
103
-openvpn_thread_join (openvpn_thread_t id)
104
-{
105
-  ASSERT (pthread_initialized);
106
-  pthread_join (id, NULL);
107
-}
108
-
109
-void
110
-openvpn_thread_init ()
111
-{
112
-  int i;
113
-
114
-  ASSERT (!pthread_initialized);
115
-
116
-  msg (M_INFO, "PTHREAD support initialized");
117
-
118
-  /* initialize OpenSSL library locking */
119
-#if defined(USE_CRYPTO) && defined(USE_SSL)
120
-  ssl_thread_setup();
121
-#endif
122
-  
123
-  /* initialize static mutexes */
124
-  for (i = 0; i < N_MUTEXES; i++)
125
-    ASSERT (!pthread_mutex_init (&mutex_array[i].mutex, NULL));
126
-
127
-  msg_thread_init ();
128
-
129
-  pthread_initialized = true;
130
-}
131
-
132
-void
133
-openvpn_thread_cleanup ()
134
-{
135
-  if (pthread_initialized)
136
-    {
137
-      int i;
138
-
139
-      pthread_initialized = false;
140
-
141
-      /* cleanup OpenSSL library locking */
142
-#if defined(USE_CRYPTO) && defined(USE_SSL)
143
-      ssl_thread_cleanup();
144
-#endif
145
-
146
-      /* destroy static mutexes */
147
-      for (i = 0; i < N_MUTEXES; i++)
148
-	ASSERT (!pthread_mutex_destroy (&mutex_array[i].mutex));
149
-
150
-      msg_thread_uninit ();
151
-    }
152
-}
153
-
154
-#else
155
-static void dummy(void) {}
156
-#endif
157 1
deleted file mode 100644
... ...
@@ -1,235 +0,0 @@
1
-/*
2
- *  OpenVPN -- An application to securely tunnel IP networks
3
- *             over a single UDP port, with support for SSL/TLS-based
4
- *             session authentication and key exchange,
5
- *             packet encryption, packet authentication, and
6
- *             packet compression.
7
- *
8
- *  Copyright (C) 2002-2009 OpenVPN Technologies, Inc. <sales@openvpn.net>
9
- *
10
- *  This program is free software; you can redistribute it and/or modify
11
- *  it under the terms of the GNU General Public License version 2
12
- *  as published by the Free Software Foundation.
13
- *
14
- *  This program is distributed in the hope that it will be useful,
15
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
- *  GNU General Public License for more details.
18
- *
19
- *  You should have received a copy of the GNU General Public License
20
- *  along with this program (see the file COPYING included with this
21
- *  distribution); if not, write to the Free Software Foundation, Inc.,
22
- *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
- */
24
-
25
-#ifndef THREAD_H
26
-#define THREAD_H
27
-
28
-#include "basic.h"
29
-#include "common.h"
30
-
31
-/*
32
- * OpenVPN static mutex locks, by mutex type
33
- */
34
-#define L_UNUSED       0
35
-#define L_CTIME        1
36
-#define L_INET_NTOA    2
37
-#define L_MSG          3
38
-#define L_STRERR       4
39
-#define L_PUTENV       5
40
-#define L_PRNG         6
41
-#define L_GETTIMEOFDAY 7
42
-#define L_ENV_SET      8
43
-#define L_SYSTEM       9
44
-#define L_CREATE_TEMP  10
45
-#define L_PLUGIN       11
46
-#define N_MUTEXES      12
47
-
48
-#ifdef USE_PTHREAD
49
-
50
-#define MAX_THREADS     50
51
-
52
-#define CACHE_LINE_SIZE 128
53
-
54
-/*
55
- * Improve SMP performance by making sure that each
56
- * mutex resides in its own cache line.
57
- */
58
-struct sparse_mutex
59
-{
60
-  pthread_mutex_t mutex;
61
-  uint8_t dummy [CACHE_LINE_SIZE - sizeof (pthread_mutex_t)];
62
-};
63
-
64
-typedef pthread_t openvpn_thread_t;
65
-
66
-extern bool pthread_initialized;
67
-
68
-extern struct sparse_mutex mutex_array[N_MUTEXES];
69
-
70
-#define MUTEX_DEFINE(lock) pthread_mutex_t lock
71
-#define MUTEX_PTR_DEFINE(lock) pthread_mutex_t *lock
72
-
73
-static inline bool
74
-openvpn_thread_enabled (void)
75
-{
76
-  return pthread_initialized;
77
-}
78
-
79
-static inline openvpn_thread_t
80
-openvpn_thread_self (void)
81
-{
82
-  return pthread_initialized ? pthread_self() : 0;
83
-}
84
-
85
-static inline void
86
-mutex_init (pthread_mutex_t *mutex)
87
-{
88
-  if (mutex)
89
-    pthread_mutex_init (mutex, NULL);
90
-}
91
-
92
-static inline void
93
-mutex_destroy (pthread_mutex_t *mutex)
94
-{
95
-  if (mutex)
96
-    pthread_mutex_destroy (mutex);
97
-}
98
-
99
-static inline void
100
-mutex_lock (pthread_mutex_t *mutex)
101
-{
102
-  if (pthread_initialized && mutex)
103
-    pthread_mutex_lock (mutex);
104
-}
105
-
106
-static inline bool
107
-mutex_trylock (pthread_mutex_t *mutex)
108
-{
109
-  if (pthread_initialized && mutex)
110
-    return pthread_mutex_trylock (mutex) == 0;
111
-  else
112
-    return true;
113
-}
114
-
115
-static inline void
116
-mutex_unlock (pthread_mutex_t *mutex)
117
-{
118
-  if (pthread_initialized && mutex)
119
-    {
120
-      pthread_mutex_unlock (mutex);
121
-#if 1 /* JYFIXME: if race conditions exist, make them more likely to occur */
122
-      sleep (0);
123
-#endif
124
-    }
125
-}
126
-
127
-static inline void
128
-mutex_cycle (pthread_mutex_t *mutex)
129
-{
130
-  if (pthread_initialized && mutex)
131
-    {
132
-      pthread_mutex_unlock (mutex);
133
-      sleep (0);
134
-      pthread_mutex_lock (mutex);
135
-    }
136
-}
137
-
138
-static inline void
139
-mutex_lock_static (int type)
140
-{
141
-  mutex_lock (&mutex_array[type].mutex);
142
-}
143
-
144
-static inline void
145
-mutex_unlock_static (int type)
146
-{
147
-  mutex_unlock (&mutex_array[type].mutex);
148
-}
149
-
150
-static inline void
151
-mutex_cycle_static (int type)
152
-{
153
-  mutex_cycle (&mutex_array[type].mutex);
154
-}
155
-
156
-void openvpn_thread_init (void);
157
-void openvpn_thread_cleanup (void);
158
-
159
-openvpn_thread_t openvpn_thread_create (void *(*start_routine) (void *), void* arg);
160
-void openvpn_thread_join (openvpn_thread_t id);
161
-
162
-#else /* USE_PTHREAD */
163
-
164
-typedef int openvpn_thread_t;
165
-
166
-#if defined(_MSC_VER) || PEDANTIC
167
-
168
-#define MUTEX_DEFINE(lock) int eat_semicolon
169
-#define MUTEX_PTR_DEFINE(lock) int eat_semicolon
170
-
171
-#else
172
-
173
-#define MUTEX_DEFINE(lock)
174
-#define MUTEX_PTR_DEFINE(lock)
175
-
176
-#endif
177
-
178
-#define mutex_init(m)
179
-#define mutex_destroy(m)
180
-#define mutex_lock(m)
181
-#define mutex_trylock(m) (true)
182
-#define mutex_unlock(m)
183
-#define mutex_cycle(m)
184
-
185
-static inline bool
186
-openvpn_thread_enabled (void)
187
-{
188
-  return false;
189
-}
190
-
191
-static inline openvpn_thread_t
192
-openvpn_thread_self (void)
193
-{
194
-  return 0;
195
-}
196
-
197
-static inline void
198
-openvpn_thread_init (void)
199
-{
200
-}
201
-
202
-static inline void
203
-openvpn_thread_cleanup (void)
204
-{
205
-}
206
-
207
-static inline openvpn_thread_t
208
-openvpn_thread_create (void *(*start_routine) (void *), void* arg)
209
-{
210
-  return 0;
211
-}
212
-
213
-static inline void
214
-work_thread_join (openvpn_thread_t id)
215
-{
216
-}
217
-
218
-static inline void
219
-mutex_lock_static (int type)
220
-{
221
-}
222
-
223
-static inline void
224
-mutex_unlock_static (int type)
225
-{
226
-}
227
-
228
-static inline void
229
-mutex_cycle_static (int type)
230
-{
231
-}
232
-
233
-#endif /* USE_PTHREAD */
234
-
235
-#endif /* THREAD_H */