aboutsummaryrefslogtreecommitdiffstats
path: root/src/gen-posix-lock-obj.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2015-06-15 08:32:11 +0000
committerWerner Koch <[email protected]>2015-06-15 08:32:11 +0000
commit13918d05a333255d22aa6718dd467fcb8eaf80c8 (patch)
tree8ae6fb48ee7e93bf12cc92b578abe6b36292fa10 /src/gen-posix-lock-obj.c
parentpo: Update Japanese translation. (diff)
downloadlibgpg-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]>
Diffstat (limited to 'src/gen-posix-lock-obj.c')
-rw-r--r--src/gen-posix-lock-obj.c60
1 files changed, 46 insertions, 14 deletions
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"