When pthread_t was smaller, our calculated thread IDs would include
uninitialized RAM, and so our unit tests would fail because thread_ids
would never match one another.
When pthread_t was larger and alignment was big-endian, our calculated
thread IDs would only have the most significant bytes of the
pthread_t, when in practice all the entropy is in the low-order bytes.
Found with help from Dagobert Michelsen.
[Define if we have pthreads on this system])
have_pthreads=yes])
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+ AC_CHECK_SIZEOF(pthread_t, ,
+ [AC_INCLUDES_DEFAULT()
+ #include <pthread.h> ]
+ )
fi
AM_CONDITIONAL(PTHREADS, [test "$have_pthreads" != "no" && test "$enable_thread_support" != "no"])
#include <event2/thread.h>
#include <stdlib.h>
+#include <string.h>
#include "mm-internal.h"
#include "evthread-internal.h"
{
union {
pthread_t thr;
+#if _EVENT_SIZEOF_PTHREAD_T > _EVENT_SIZEOF_LONG
+ ev_uint64_t id;
+#else
unsigned long id;
+#endif
} r;
+#if _EVENT_SIZEOF_PTHREAD_T < _EVENT_SIZEOF_LONG
+ memset(&r, 0, sizeof(r));
+#endif
r.thr = pthread_self();
- return r.id;
+ return (unsigned long)r.id;
}
static void *