This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: include/bits/concurrence.h breaks MinGW bootstrap
- From: Mohan Embar <gnustuff at thisiscool dot com>
- To: Benjamin Kosnik <bkoz at redhat dot com>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org, aaronavay62 at aaronwl dot com
- Date: Wed, 30 Jun 2004 10:21:03 -0500
- Subject: Re: include/bits/concurrence.h breaks MinGW bootstrap
- Reply-to: gnustuff at thisiscool dot com
Hi All,
>>This is in reference to this post:
>>
>>http://gcc.gnu.org/ml/libstdc++/2004-06/msg00351.html
>
>This is now libstdc++/16248.
>
>>I was able to unbreak the MinGW bootstrap with the
>>attached patch, but I haven't tested it at all. (Just
>>take it as a suggestion....) If someone wants me to follow
>>up on this, let me know.
>
>Can somebody test and report back please?
FYI: This is the current variant of my patch which builds
against both i686-pc-linux-gnu and i686-pc-mingw32
with yesterday's CVS sources.
This should be considered a springboard for discussion
only. More background information is in the Bugzilla report.
I am sending this out now in a rushed manner (without a ChangeLog
or testing) only because I see uses of the new lock class becoming
more rampant and this won't work unchanged under MinGW.
If no one has a heart attack about this approach, I'll
submit a formal patch with a ChangeLog. I don't know how
to test libstdc++, but can run a "make check" or something
like that against i686-pc-linux-gnu if someone tells me how.
-- Mohan
http://www.thisiscool.com/
http://www.animalsong.org/
Index: include/bits/concurrence.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/concurrence.h,v
retrieving revision 1.5
diff -u -2 -r1.5 concurrence.h
--- include/bits/concurrence.h 25 Jun 2004 16:36:13 -0000 1.5
+++ include/bits/concurrence.h 30 Jun 2004 14:20:00 -0000
@@ -51,4 +51,10 @@
__gthread_once(&NAME ## _once, NAME ## _init); \
__gthread_mutex_lock(&NAME)
+
+// Needed for __gnu_cxx::mutex_wrapper class
+# define __gnucxx_mutex(NAME) NAME, NAME ## _once, NAME ## _init
+# define __gnucxx_mutex_parms(NAME) __gthread_mutex_t& NAME, \
+ __gthread_once_t& NAME ## _once, void (* NAME ## _init) ()
+
# endif
@@ -63,19 +69,57 @@
#endif
+// Default declarations for __gnu_cxx::mutex_wrapper class.
+// These are defaulted here if not previously defined.
+#ifndef __gnucxx_mutex
+# define __gnucxx_mutex(NAME) NAME
+# define __gnucxx_mutex_parms(NAME) __gthread_mutex_t& NAME
+
+#endif
+
namespace __gnu_cxx
{
+// An object-oriented mutex wrapper
+ class mutex_wrapper
+ {
+ __gthread_mutex_t& device;
+
+#if __GTHREADS && !defined(__GTHREAD_MUTEX_INIT)
+ __gthread_once_t& device_once;
+ void (*device_init)();
+#endif
+
+ public:
+ explicit mutex_wrapper(__gnucxx_mutex_parms(name)) :
+ device(name)
+#if __GTHREADS && !defined(__GTHREAD_MUTEX_INIT)
+ , device_once(name_once)
+ , device_init(name_init)
+#endif
+ {}
+
+ void lock()
+ { __glibcxx_mutex_lock(device); }
+
+ void unlock()
+ { __glibcxx_mutex_unlock(device); }
+
+ private:
+ mutex_wrapper(const mutex_wrapper&);
+ mutex_wrapper& operator=(const mutex_wrapper&);
+ };
+
class lock
{
// Externally defined and initialized.
- __gthread_mutex_t* device;
+ mutex_wrapper& device;
public:
// Acquire the mutex here with a constructor call. This ensures
// that it is released in exit or during stack unwinding.
- explicit lock(__gthread_mutex_t& name) : device(&name)
- { __glibcxx_mutex_lock(*device); }
+ explicit lock(mutex_wrapper& name) : device(name)
+ { device.lock(); }
~lock() throw()
- { __glibcxx_mutex_unlock(*device); }
+ { device.unlock(); }
private:
Index: include/ext/pool_allocator.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/ext/pool_allocator.h,v
retrieving revision 1.14
diff -u -2 -r1.14 pool_allocator.h
--- include/ext/pool_allocator.h 25 Jun 2004 06:10:43 -0000 1.14
+++ include/ext/pool_allocator.h 30 Jun 2004 14:20:01 -0000
@@ -101,5 +101,5 @@
_M_get_free_list(size_t __bytes);
- __gthread_mutex_t&
+ mutex_wrapper&
_M_get_mutex();
Index: src/allocator.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/allocator.cc,v
retrieving revision 1.8
diff -u -2 -r1.8 allocator.cc
--- src/allocator.cc 25 Jun 2004 06:10:44 -0000 1.8
+++ src/allocator.cc 30 Jun 2004 14:20:02 -0000
@@ -52,7 +52,11 @@
}
- __gthread_mutex_t&
+ mutex_wrapper&
__pool_base::_M_get_mutex()
- { return __gnu_internal::palloc_init_mutex; }
+ {
+ static mutex_wrapper
+ mutex(__gnucxx_mutex(__gnu_internal::palloc_init_mutex));
+ return mutex;
+ }
// Allocate memory in large chunks in order to avoid fragmenting the
Index: src/locale_init.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/locale_init.cc,v
retrieving revision 1.14
diff -u -2 -r1.14 locale_init.cc
--- src/locale_init.cc 25 Jun 2004 06:10:44 -0000 1.14
+++ src/locale_init.cc 30 Jun 2004 14:20:03 -0000
@@ -102,5 +102,6 @@
{
_S_initialize();
- __gnu_cxx::lock sentry(__gnu_internal::locale_cons_mutex);
+ __gnu_cxx::mutex_wrapper mutex(__gnucxx_mutex(locale_cons_mutex));
+ __gnu_cxx::lock sentry(mutex);
_S_global->_M_add_reference();
_M_impl = _S_global;
@@ -113,5 +114,6 @@
_Impl* __old;
{
- __gnu_cxx::lock sentry(__gnu_internal::locale_global_mutex);
+ __gnu_cxx::mutex_wrapper mutex(__gnucxx_mutex(locale_global_mutex));
+ __gnu_cxx::lock sentry(mutex);
__old = _S_global;
__other._M_impl->_M_add_reference();