This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: libstdc++ and race detectors


> Can the macros be put directly here?
Yes. http://codereview.appspot.com/download/issue1800042_12001.diff

> Is a new function needed?
Only if it will be used on other cases, which doesn't seem to be the case.

--kcc


Index: include/bits/basic_string.h
===================================================================
--- include/bits/basic_string.h	(revision 162071)
+++ include/bits/basic_string.h	(working copy)
@@ -232,9 +232,12 @@
 #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
 	  if (__builtin_expect(this != &_S_empty_rep(), false))
 #endif
+            _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount);
 	    if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
-						       -1) <= 0)
+						       -1) <= 0) {
+              _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount);
 	      _M_destroy(__a);
+            }
 	}  // XXX MT

 	void
Index: include/ext/atomicity.h
===================================================================
--- include/ext/atomicity.h	(revision 162071)
+++ include/ext/atomicity.h	(working copy)
@@ -34,6 +34,28 @@
 #include <bits/gthr.h>
 #include <bits/atomic_word.h>

+// These two macros are required to make libstdc++ race-detector-friendly.
+// By using these macros we are letting a race detector know that
+// all events that occurred before _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(x)
+// happen-before (precede) all events that occurred after the following
+// _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(x).
+// See basic_string::_Rep::_M_dispose for an example.
+// By default, these two macros are defined empty -- anyone who wants
+// to use a race detector will need to redefine these macros to call
+// appropriate race detector API.
+//
+// In order to work properly w/o rebuilding libstdc++.so these macros should
+// be used together with -D_GLIBCXX_EXTERN_TEMPLATE=-1.
+//
+// TODO(kcc): do we need to add a link to some external documentation
+// or mention the race detection tools by name?
+#ifndef _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE
+# define  _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(a)
+#endif
+#ifndef _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER
+# define  _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(a)
+#endif
+
 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)

   // Functions for portable atomic access.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]