From 13918d05a333255d22aa6718dd467fcb8eaf80c8 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 15 Jun 2015 10:32:11 +0200 Subject: Allow building with --disable-threads. * src/posix-lock-obj.h (LOCK_ABI_NOT_AVAILABLE): New. (LOCK_ABI_VERSION): Define depending on USE_POSIX_THREADS. (_gpgrt_lock_t) [!USE_POSIX_THREADS]: Do not define the union. * src/gen-posix-lock-obj.c: Take care of USE_POSIX_THREADS. * src/posix-lock.c (_gpgrt_lock_init, _gpgrt_lock_lock) (_gpgrt_lock_trylock, _gpgrt_lock_unlock) (_gpgrt_lock_destroy): Return success for a no-threads version. * tests/t-lock.c: Disable tests if threads are not available. * src/mkheader.c (main): Add NO-THREADS to the printed comment. * configure.ac: Show NO-TRHEADS in the final summary. -- Warning: Using --disable-threads creates a different ABI which we can't encode in the the cpu-vendor-os triplet. The run time checks should detect this and abort the process. Signed-off-by: Werner Koch --- configure.ac | 8 ++++++- src/gen-posix-lock-obj.c | 60 +++++++++++++++++++++++++++++++++++++----------- src/mkheader.c | 5 ++++ src/posix-lock-obj.h | 9 +++++++- src/posix-lock.c | 10 ++++---- tests/t-lock.c | 11 +++++++-- 6 files changed, 80 insertions(+), 23 deletions(-) diff --git a/configure.ac b/configure.ac index b6ca5fb..2f49bd1 100644 --- a/configure.ac +++ b/configure.ac @@ -532,11 +532,17 @@ AC_CONFIG_FILES([src/gpg-error-config], [chmod +x src/gpg-error-config]) AC_OUTPUT +tmp= +if test "$have_w32_system" != yes; then + if test x"$gl_use_threads" = xno; then + tmp=" NO-THREADS" + fi +fi echo " $PACKAGE_NAME-$PACKAGE_VERSION prepared for make Revision: mym4_revision (mym4_revision_dec) - Platform: $host + Platform: $host$tmp " if test "$gcry_cv_gcc_attribute_aligned" != "yes" ; then cat <vers == LOCK_ABI_NOT_AVAILABLE? 0 : GPG_ERR_NOT_IMPLEMENTED; #endif /* Unknown thread system. */ return rc; @@ -178,7 +178,7 @@ _gpgrt_lock_lock (gpgrt_lock_t *lockhd) else rc = 0; /* Threads are not used. */ #else /* Unknown thread system. */ - rc = GPG_ERR_NOT_IMPLEMENTED; + rc = lock->vers == LOCK_ABI_NOT_AVAILABLE? 0 : GPG_ERR_NOT_IMPLEMENTED; #endif /* Unknown thread system. */ return rc; @@ -201,7 +201,7 @@ _gpgrt_lock_trylock (gpgrt_lock_t *lockhd) else rc = 0; /* Threads are not used. */ #else /* Unknown thread system. */ - rc = GPG_ERR_NOT_IMPLEMENTED; + rc = lock->vers == LOCK_ABI_NOT_AVAILABLE? 0 : GPG_ERR_NOT_IMPLEMENTED; #endif /* Unknown thread system. */ return rc; @@ -224,7 +224,7 @@ _gpgrt_lock_unlock (gpgrt_lock_t *lockhd) else rc = 0; /* Threads are not used. */ #else /* Unknown thread system. */ - rc = GPG_ERR_NOT_IMPLEMENTED; + rc = lock->vers == LOCK_ABI_NOT_AVAILABLE? 0 : GPG_ERR_NOT_IMPLEMENTED; #endif /* Unknown thread system. */ return rc; @@ -255,7 +255,7 @@ _gpgrt_lock_destroy (gpgrt_lock_t *lockhd) else rc = 0; /* Threads are not used. */ #else /* Unknown thread system. */ - rc = GPG_ERR_NOT_IMPLEMENTED; + rc = lock->vers == LOCK_ABI_NOT_AVAILABLE? 0 : GPG_ERR_NOT_IMPLEMENTED; #endif /* Unknown thread system. */ return rc; diff --git a/tests/t-lock.c b/tests/t-lock.c index fd645eb..831e224 100644 --- a/tests/t-lock.c +++ b/tests/t-lock.c @@ -1,5 +1,5 @@ /* t-lock.c - Check the lock functions - * Copyright (C) 2013 g10 Code GmbH + * Copyright (C) 2013, 2015 g10 Code GmbH * * This file is part of libgpg-error. * @@ -105,6 +105,7 @@ print_accounts (void) } +#if defined(_WIN32) || defined(USE_POSIX_THREADS) /* Get a a random integer value in the range 0 to HIGH. */ static unsigned int get_rand (int high) @@ -190,6 +191,7 @@ accountant_thread (void *arg) } return THREAD_RET_VALUE; } +#endif /*_WIN32||USE_POSIX_THREADS*/ static void @@ -234,6 +236,7 @@ run_test (void) CloseHandle (rthread); #else /*!_WIN32*/ +# ifdef USE_POSIX_THREADS pthread_t rthread; pthread_t athreads[N_ACCOUNTANTS]; int i; @@ -253,7 +256,11 @@ run_test (void) stop_revision_thread = 1; pthread_join (rthread, NULL); show ("revision thread has terminated"); - +# else /*!USE_POSIX_THREADS*/ + verbose++; + show ("no thread support - skipping test\n", PGM); + verbose--; +# endif /*!USE_POSIX_THREADS*/ #endif /*!_WIN32*/ gpgrt_lock_destroy (&accounts_lock); -- cgit v1.2.3