diff options
author | Werner Koch <[email protected]> | 2015-06-15 08:32:11 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2015-06-15 08:32:11 +0000 |
commit | 13918d05a333255d22aa6718dd467fcb8eaf80c8 (patch) | |
tree | 8ae6fb48ee7e93bf12cc92b578abe6b36292fa10 | |
parent | po: Update Japanese translation. (diff) | |
download | libgpg-error-13918d05a333255d22aa6718dd467fcb8eaf80c8.tar.gz libgpg-error-13918d05a333255d22aa6718dd467fcb8eaf80c8.zip |
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 <[email protected]>
-rw-r--r-- | configure.ac | 8 | ||||
-rw-r--r-- | src/gen-posix-lock-obj.c | 60 | ||||
-rw-r--r-- | src/mkheader.c | 5 | ||||
-rw-r--r-- | src/posix-lock-obj.h | 9 | ||||
-rw-r--r-- | src/posix-lock.c | 10 | ||||
-rw-r--r-- | 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 <<G10EOF diff --git a/src/gen-posix-lock-obj.c b/src/gen-posix-lock-obj.c index d2bc645..595d379 100644 --- a/src/gen-posix-lock-obj.c +++ b/src/gen-posix-lock-obj.c @@ -36,9 +36,11 @@ #define PGM "gen-posix-lock-obj" /* Check that configure did its job. */ +#ifdef USE_POSIX_THREADS #if SIZEOF_PTHREAD_MUTEX_T < 4 # error sizeof pthread_mutex_t is not known. #endif +#endif /* Special requirements for certain platforms. */ #if defined(__hppa__) && defined(__linux__) @@ -52,25 +54,32 @@ # error compiler is not able to enforce a 16 byte alignment #endif - +#ifdef USE_POSIX_THREADS static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; - +#endif int main (void) { +#ifdef USE_POSIX_THREADS unsigned char *p; int i; +#endif struct { - pthread_mutex_t mtx; long vers; +#ifdef USE_POSIX_THREADS + pthread_mutex_t mtx; +#endif } dummyobj; + +#ifdef USE_POSIX_THREADS if (sizeof mtx != SIZEOF_PTHREAD_MUTEX_T) { fprintf (stderr, PGM ": pthread_mutex_t mismatch\n"); exit (1); } +#endif /*USE_POSIX_THREADS*/ if (sizeof (dummyobj) != sizeof (_gpgrt_lock_t)) { @@ -78,13 +87,23 @@ main (void) exit (1); } - /* To force a probably suitable alignment of the structure we use a - union and include a long and a pointer to a long. */ - printf ("## lock-obj-pub.%s.h\n" + printf ("## lock-obj-pub.%s.h%s\n" "## File created by " PGM " - DO NOT EDIT\n" "## To be included by mkheader into gpg-error.h\n" - "\n" - "typedef struct\n" + "\n", + HOST_TRIPLET_STRING, +#ifdef USE_POSIX_THREADS + "" +#else + " - NO LOCK SUPPORT" +#endif + ); + +#ifdef USE_POSIX_THREADS + + /* To force a probably suitable alignment of the structure we use a + union and include a long and a pointer to a long. */ + printf ("typedef struct\n" "{\n" " long _vers;\n" " union {\n" @@ -96,13 +115,12 @@ main (void) "} gpgrt_lock_t;\n" "\n" "#define GPGRT_LOCK_INITIALIZER {%d,{{", - HOST_TRIPLET_STRING, SIZEOF_PTHREAD_MUTEX_T, -#if USE_16BYTE_ALIGNMENT +# if USE_16BYTE_ALIGNMENT " int _x16_align __attribute__ ((aligned (16)));\n", -#else +# else "", -#endif +# endif LOCK_ABI_VERSION); p = (unsigned char *)&mtx; for (i=0; i < sizeof mtx; i++) @@ -113,8 +131,22 @@ main (void) if (i < sizeof mtx - 1) putchar (','); } - fputs ("}}}\n" - "##\n" + fputs ("}}}\n", stdout); + +#else /*!USE_POSIX_THREADS*/ + + printf ("/* Dummy object - no locking available. */\n" + "typedef struct\n" + "{\n" + " long _vers;\n" + "} gpgrt_lock_t;\n" + "\n" + "#define GPGRT_LOCK_INITIALIZER {%d}\n", + LOCK_ABI_VERSION); + +#endif /*!USE_POSIX_THREADS*/ + + fputs ("##\n" "## Loc" "al Variables:\n" "## mode: c\n" "## buffer-read-only: t\n" diff --git a/src/mkheader.c b/src/mkheader.c index 380c7e3..b8fd783 100644 --- a/src/mkheader.c +++ b/src/mkheader.c @@ -33,6 +33,7 @@ static int have_stdint_h; static int have_w32_system; static int have_w64_system; static char *replacement_for_off_type; +static int use_posix_threads; /* Various state flags. */ static int stdint_h_included; @@ -148,6 +149,8 @@ parse_config_h (const char *fname) xfree (replacement_for_off_type); replacement_for_off_type = xstrdup (p1); } + else if (!strcmp (p1, "USE_POSIX_THREADS")) + use_posix_threads = 1; } if (ferror (fp)) @@ -597,6 +600,8 @@ main (int argc, char **argv) printf ("%s", host_triplet); else printf ("%s (%s)", host_triplet, host_triplet_raw); + if (!use_posix_threads && !have_w32_system && !have_w64_system) + fputs (" NO-THREADS", stdout); fputs (p2, stdout); } else if (!write_special (fname, lnr, p1)) diff --git a/src/posix-lock-obj.h b/src/posix-lock-obj.h index 7714d3c..872e55a 100644 --- a/src/posix-lock-obj.h +++ b/src/posix-lock-obj.h @@ -20,15 +20,22 @@ #ifndef POSIX_LOCK_OBJ_H #define POSIX_LOCK_OBJ_H -#define LOCK_ABI_VERSION 1 +#define LOCK_ABI_NOT_AVAILABLE (-1) +#if USE_POSIX_THREADS +# define LOCK_ABI_VERSION 1 +#else +# define LOCK_ABI_VERSION LOCK_ABI_NOT_AVAILABLE +#endif typedef struct { long vers; +#if USE_POSIX_THREADS union { pthread_mutex_t mtx; long *dummy; } u; +#endif } _gpgrt_lock_t; diff --git a/src/posix-lock.c b/src/posix-lock.c index 89be944..d8f5465 100644 --- a/src/posix-lock.c +++ b/src/posix-lock.c @@ -155,7 +155,7 @@ _gpgrt_lock_init (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; @@ -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); |