[Xcb] Adding pthread stubs into libxcb

Josh Triplett josh at freedesktop.org
Tue Nov 7 17:41:48 PST 2006


Diego 'Flameeyes' Pettenò wrote:
> I'm trying to get libxcb to behave on FreeBSD by adding the (in)famous pthread 
> stubs as weak symbols. I've taken most of the code from libX11 stubs, but 
> cleaned it up not to have the strange conditionals for now, and added an 
> autoconf check to see if the compiler supports __attribute__(weak, alias) so 
> that it should be mostly fine.

Awesome.

> --- a/acinclude.m4
> +++ b/acinclude.m4
> @@ -1,3 +1,31 @@
> +dnl Detection code for compilers supporting the __attribute__((weak, alias))
> +dnl feature. Original code present in unieject's repository
> +dnl Diego Pettenò <flameeyes at gentoo.org>

unieject appears to use the GPL; can we use this code under XCB's MIT license?
(It looks like you wrote the original code in the unieject project; if so, we
just need your permission.)

> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -99,7 +99,7 @@ libxcb_la_LIBADD = $(XCBPROTO_LIBS) $(XA
>  libxcb_la_SOURCES = \
>  		xcb_conn.c xcb_out.c xcb_in.c xcb_ext.c xcb_xid.c \
>  		xcb_list.c xcb_util.c xcb_auth.c c-client.xsl \
> -		xproto.c bigreq.c xc_misc.c
> +		xproto.c bigreq.c xc_misc.c thread_stubs.c

So, regarding conditional inclusion of the thread stubs, I think we could do
something like the following:

In configure.ac:
AC_TRY_LINK_FUNC([pthread_mutex_init], [AC_DEFINE(HAVE_PTHREAD_MUTEX_INIT, 1, [Define if the target platform has a pthread_mutex_init() stub.])],)
... repeat for each pthread function XCB uses ...

In thread_stubs.c:
#ifndef HAVE_PTHREAD_MUTEX_INIT
int pthread_mutex_init()    __attribute__ ((weak, alias ("__pthread_zero_stub")));
#endif
... repeat for each pthread function XCB uses ...

That way, we define only the stubs the target platform doesn't already provide.


Also, we need to add a configure check for #pragma weak, and if we lack any
stubs and neither __attribute((weak, alias(...))) nor #pragma weak work, we
need to either fail noisily or just force linking with pthreads.  (By "work",
I mean that you can compile a program containing both a weak definition by one
or the other mechanism and a call to that function.)

> +/* These are added for libGL */
> +#pragma weak pthread_key_create = __pthread_zero_stub
> +#pragma weak pthread_getspecific = __pthread_zero_stub
> +#pragma weak pthread_setspecific = __pthread_zero_stub

Why would libGL care about libxcb's pthread stubs?  Shouldn't it handle its
own pthread support?

(If not, then should we split out this work into a separate xorg project?)

- Josh Triplett

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
Url : http://lists.freedesktop.org/archives/xcb/attachments/20061107/d6913a59/signature.pgp


More information about the Xcb mailing list