[mingw/cygwin]: gthr-win32.h: remove pollution of STL namespace by win32api

Danny Smith danny_r_smith_2001@yahoo.co.nz
Mon May 27 15:30:00 GMT 2002


The inline functions in gthr-win32.h pollute the STL namespace with
names from the win32 API.  This has raised several bug reports on the
mingw user list. Introducing win32api names into the namespace is
especially bad for code which makes no other use of the win32 api.

The following patch allows users to hide the win32api by calling 
functions defined in an extern file.  The patch puts the file in
libgcc.a, using the LIB2FUNCS_EXTRA machinery.

I have named the new function by simply replacing the __gthread prefix
with __gthr_win32.

I realize that this patch creates a  backward compatability issue:
libs built with new GCC would contain references to functions that
are not available in libgcc.a in  GCC 3.0  or 3.1.  However, the
new functions are referenced only if the user defines
__GTHREAD_HIDE_WIN32API, so the default behaviour is to _not_
introduce new dependencies.

I have another patch that I will submit independently to provide Dwarf2
EH for mingw.  This will break backwards compatability even more, since
3.0.x and 3.1 releases only worked on mingw with sjlj exceptions. So
if that patch is acceptable, the backwards compatability issue introduced
here may be moot. 

Chris, I have put the LIB2FUNCS_EXTRA definition in t-cygwin, because
the default thread model for cygwin is still win32.  It could just as
well go into t-mingw32 if cygwin changes to pthread model as default.


This has been bootstrapped and tested on:

Reading specs from D:/MINGW/BIN/../lib/gcc-lib/mingw32/3.2/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as
--host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls
--enable-languages=c,c++,f77,objc --disable-win32-registry --disable-shared
Thread model: win32
gcc version 3.2 20020526 (experimental)

I have also tested on 3.1 branch on mingw32 by rebuilding libgcc.a and
libstdc++.a

ChangeLog

2002-05-28  Danny Smith  <dannysmith@users.sourforge.net>

	* gthr-win32.h: Wrap all functions in extern "C".
	(__gthread_key_t): Typedef as unsigned long,
	not win32 DWORD.
	(__GTHREAD_ONCE_INIT): Use 0, not win32 FALSE.
	(__gthread_mutex_t): Typedef as void*, not win32 HANDLE.
	(__gthr_win32_once, __gthr_win32_key_create,
	__gthr_win32_key_delete, __gthr_win32_getspecific,
	__gthr_win32_setspecific, __gthr_win32_mutex_init_function,
	__gthr_win32_mutex_lock,__gthr_win32_mutex_trylock,
	__gthr_win32_mutex_unlock): Declare, if #defined
	__GTHREAD_HIDE_WIN32API.
	(__gthread_once,__gthread_key_create,
	__gthread_key_delete, __gthread_getspecific,
	__gthread_setspecific, __gthread_mutex_init_function,
	__gthread_mutex_lock,__gthread_mutex_trylock,
	__gthread_mutex_unlock): Call corresponding
	__gthr_win32_* extern implementations if #defined
	__GTHREAD_HIDE_WIN32API.
	* config/i386/t-cygwin (LIB2FUNCS_EXTRA): Set to
	$(srcdir)/config/i386/gthr-win32.c 
	* config/i386/gthr-win32.c: New implementation file.
	(__gthr_win32_once, __gthr_win32_key_create,
	__gthr_win32_key_delete, __gthr_win32_getspecific,
	__gthr_win32_setspecific, __gthr_win32_mutex_init_function,
	__gthr_win32_mutex_lock,__gthr_win32_mutex_trylock,
	__gthr_win32_mutex_unlock): New functions, based on
	static inlines in gthr-win32.h.

Patch attached:



http://travel.yahoo.com.au - Yahoo! Travel
- Plan and book your dream holiday online!
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: gthr-win32-1.diff
URL: <http://sourceware.org/pipermail/pthreads-win32/attachments/20020527/71baa462/attachment.ksh>


More information about the Pthreads-win32 mailing list