Re: [evolution-patches] e-d-s: pthread_t opaqueness patch



I'll change it to return
just a long, which on sane platforms would be the pthread_t itself. On
Win32 I can use the part of the internals of pthread_t that is unique.
On other random platforms where pthread_t is a struct, a hash of the
contents.

How about this:

gulong
e_pthread_id(pthread_t t)
{
#ifdef HAVE_ULONG_CASTABLE_PTHREAD_T
	/* We know that pthread_t is an unsigned long, or at least
	 * castable to such without loss of precision.
	 */
	return (gulong) t;
#elif defined (PTW32_VERSION)
	/* pthreads-win32 implementation on Win32: Return the pointer
	 * to the "actual object" (see pthread.h)
	 */
	return (gulong) t.p;
#else
	/* Just return a checksum of the contents of the pthred_t */
	{
		gulong retval = 0;
		guchar *const tend = (guchar *) ((&t)+1);
		guchar *tp = (guchar *) &t;

		while (tp < tend)
			retval = (retval << 5) - retval * tp++;

		return retval;
	}
#endif
}

OK, I'll write the required configure.in snippet to find out whether a
pthread_t is something that can be printed with %lu. Hmm, I guess just
an AC_TRY_COMPILE() will do.

Yup:

	AC_TRY_COMPILE([#include <pthread.h>],
		[char a[(sizeof(unsigned long)>=sizeof(pthread_t))?1:-1];],
		[# We now know that sizeof(pthread_t) <= sizeof(unsigned long)
		 # Check that it is an integral type.
		 AC_TRY_COMPILE([#include <pthread.h>],
			[unsigned long l;
			 pthread_t t;	
			 l = (unsigned long) t;],
			[AC_DEFINE(HAVE_ULONG_CASTABLE_PTHREAD_T,1,[Define to 1 if pthread_t can be cast to an unsigned long])]
		)]
	)

--tml

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]