mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-30 15:43:32 +01:00
Merge branch 'bug26779_033' into bug26779_035
This commit is contained in:
commit
26f1167e71
4
changes/bug26779
Normal file
4
changes/bug26779
Normal file
@ -0,0 +1,4 @@
|
||||
o Minor features (bug workaround):
|
||||
- Compile correctly on systems that provide the C11 stdatomic.h header,
|
||||
but where C11 atomic functions don't actually compile.
|
||||
Closes ticket 26779; workaround for Debian issue 903709.
|
20
configure.ac
20
configure.ac
@ -1658,6 +1658,26 @@ AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
|
||||
|
||||
AC_CHECK_SIZEOF(cell_t)
|
||||
|
||||
# Let's see if stdatomic works. (There are some debian clangs that screw it
|
||||
# up; see Tor bug #26779 and debian bug 903709.)
|
||||
AC_CACHE_CHECK([whether C11 stdatomic.h actually works],
|
||||
tor_cv_stdatomic_works,
|
||||
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
|
||||
#include <stdatomic.h>
|
||||
struct x { atomic_size_t y; };
|
||||
void try_atomic_init(struct x *xx)
|
||||
{
|
||||
atomic_init(&xx->y, 99);
|
||||
atomic_fetch_add(&xx->y, 1);
|
||||
}
|
||||
]])], [tor_cv_stdatomic_works=yes], [tor_cv_stdatomic_works=no])])
|
||||
|
||||
if test "$tor_cv_stdatomic_works" = "yes"; then
|
||||
AC_DEFINE(STDATOMIC_WORKS, 1, [Set to 1 if we can compile a simple stdatomic example.])
|
||||
elif test "$ac_cv_header_stdatomic_h" = "yes"; then
|
||||
AC_MSG_WARN([Your compiler provides the stdatomic.h header, but it doesn't seem to work. I'll pretend it isn't there. If you are using Clang on Debian, maybe this is because of https://bugs.debian.org/903709 ])
|
||||
fi
|
||||
|
||||
# Now make sure that NULL can be represented as zero bytes.
|
||||
AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
|
||||
[AC_RUN_IFELSE([AC_LANG_SOURCE(
|
||||
|
@ -57,7 +57,7 @@ in_main_thread(void)
|
||||
return main_thread_id == tor_get_thread_id();
|
||||
}
|
||||
|
||||
#ifndef HAVE_STDATOMIC_H
|
||||
#ifndef HAVE_WORKING_STDATOMIC
|
||||
/** Initialize a new atomic counter with the value 0 */
|
||||
void
|
||||
atomic_counter_init(atomic_counter_t *counter)
|
||||
@ -108,4 +108,4 @@ atomic_counter_exchange(atomic_counter_t *counter, size_t newval)
|
||||
tor_mutex_release(&counter->mutex);
|
||||
return oldval;
|
||||
}
|
||||
#endif /* !defined(HAVE_STDATOMIC_H) */
|
||||
#endif /* !defined(HAVE_WORKING_STDATOMIC) */
|
||||
|
@ -16,7 +16,11 @@
|
||||
#include "lib/testsupport/testsupport.h"
|
||||
#include "lib/lock/compat_mutex.h"
|
||||
|
||||
#ifdef HAVE_STDATOMIC_H
|
||||
#if defined(HAVE_STDATOMIC_H) && defined(STDATOMIC_WORKS)
|
||||
#define HAVE_WORKING_STDATOMIC
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WORKING_STDATOMIC
|
||||
#include <stdatomic.h>
|
||||
#endif
|
||||
|
||||
@ -98,18 +102,18 @@ void tor_threadlocal_set(tor_threadlocal_t *threadlocal, void *value);
|
||||
/**
|
||||
* Atomic counter type; holds a size_t value.
|
||||
*/
|
||||
#ifdef HAVE_STDATOMIC_H
|
||||
#ifdef HAVE_WORKING_STDATOMIC
|
||||
typedef struct atomic_counter_t {
|
||||
atomic_size_t val;
|
||||
} atomic_counter_t;
|
||||
#define ATOMIC_LINKAGE static
|
||||
#else /* !(defined(HAVE_STDATOMIC_H)) */
|
||||
#else /* !(defined(HAVE_WORKING_STDATOMIC)) */
|
||||
typedef struct atomic_counter_t {
|
||||
tor_mutex_t mutex;
|
||||
size_t val;
|
||||
} atomic_counter_t;
|
||||
#define ATOMIC_LINKAGE
|
||||
#endif /* defined(HAVE_STDATOMIC_H) */
|
||||
#endif /* defined(HAVE_WORKING_STDATOMIC) */
|
||||
|
||||
ATOMIC_LINKAGE void atomic_counter_init(atomic_counter_t *counter);
|
||||
ATOMIC_LINKAGE void atomic_counter_destroy(atomic_counter_t *counter);
|
||||
@ -120,7 +124,7 @@ ATOMIC_LINKAGE size_t atomic_counter_exchange(atomic_counter_t *counter,
|
||||
size_t newval);
|
||||
#undef ATOMIC_LINKAGE
|
||||
|
||||
#ifdef HAVE_STDATOMIC_H
|
||||
#ifdef HAVE_WORKING_STDATOMIC
|
||||
/** Initialize a new atomic counter with the value 0 */
|
||||
static inline void
|
||||
atomic_counter_init(atomic_counter_t *counter)
|
||||
@ -158,7 +162,7 @@ atomic_counter_exchange(atomic_counter_t *counter, size_t newval)
|
||||
return atomic_exchange(&counter->val, newval);
|
||||
}
|
||||
|
||||
#else /* !(defined(HAVE_STDATOMIC_H)) */
|
||||
#endif /* defined(HAVE_STDATOMIC_H) */
|
||||
#else /* !(defined(HAVE_WORKING_STDATOMIC)) */
|
||||
#endif /* defined(HAVE_WORKING_STDATOMIC) */
|
||||
|
||||
#endif /* !defined(TOR_COMPAT_THREADS_H) */
|
||||
|
Loading…
Reference in New Issue
Block a user