|
From: <sv...@va...> - 2009-06-02 15:03:50
|
Author: bart
Date: 2009-06-02 16:03:44 +0100 (Tue, 02 Jun 2009)
New Revision: 10213
Log:
- Portability improvement: switched from __gnu_cxx::hash_map<> (a gcc
extension) to std::map<> (standard C++).
- Replaced tempnam() by mkdtemp() / mkstemp() because gcc emits a warning
about the former.
Modified:
trunk/drd/tests/Makefile.am
trunk/drd/tests/tsan_unittest.cpp
Modified: trunk/drd/tests/Makefile.am
===================================================================
--- trunk/drd/tests/Makefile.am 2009-06-02 11:20:06 UTC (rev 10212)
+++ trunk/drd/tests/Makefile.am 2009-06-02 15:03:44 UTC (rev 10213)
@@ -287,7 +287,7 @@
new_delete_SOURCES = new_delete.cpp
tsan_unittest_SOURCES = tsan_unittest.cpp
-tsan_unittest_CXXFLAGS = $(AM_CXXFLAGS) -Wno-deprecated -Wno-sign-compare\
+tsan_unittest_CXXFLAGS = $(AM_CXXFLAGS) -Wno-sign-compare\
-Wno-shadow @FLAG_W_NO_EMPTY_BODY@
if HAVE_BOOST_1_35
Modified: trunk/drd/tests/tsan_unittest.cpp
===================================================================
--- trunk/drd/tests/tsan_unittest.cpp 2009-06-02 11:20:06 UTC (rev 10212)
+++ trunk/drd/tests/tsan_unittest.cpp 2009-06-02 15:03:44 UTC (rev 10213)
@@ -73,7 +73,6 @@
#include <vector>
#include <string>
#include <map>
-#include <ext/hash_map>
#include <algorithm>
#include <cstring> // strlen(), index(), rindex()
#include <ctime>
@@ -3817,15 +3816,20 @@
// test79 TN. Swap. {{{1
namespace test79 {
-__gnu_cxx::hash_map<int, int> MAP;
+#if 0
+typedef __gnu_cxx::hash_map<int, int> map_t;
+#else
+typedef std::map<int, int> map_t;
+#endif
+map_t MAP;
Mutex MU;
-// Here we use swap to pass hash_map between threads.
+// Here we use swap to pass MAP between threads.
// The synchronization is correct, but w/o ANNOTATE_MUTEX_IS_USED_AS_CONDVAR
// Helgrind will complain.
void Worker1() {
- __gnu_cxx::hash_map<int, int> tmp;
+ map_t tmp;
MU.Lock();
// We swap the new empty map 'tmp' with 'MAP'.
MAP.swap(tmp);
@@ -6229,9 +6233,14 @@
// test134 TN. Swap. Variant of test79. {{{1
namespace test134 {
-__gnu_cxx::hash_map<int, int> map;
+#if 0
+typedef __gnu_cxx::hash_map<int, int> map_t;
+#else
+typedef std::map<int, int> map_t;
+#endif
+map_t map;
Mutex mu;
-// Here we use swap to pass hash_map between threads.
+// Here we use swap to pass map between threads.
// The synchronization is correct, but w/o the annotation
// any hybrid detector will complain.
@@ -6243,7 +6252,7 @@
// These arcs can be created by HAPPENS_{BEFORE,AFTER} annotations, but it is
// much simpler to apply pure-happens-before mode to the mutex mu.
void Swapper() {
- __gnu_cxx::hash_map<int, int> tmp;
+ map_t tmp;
MutexLock lock(&mu);
ANNOTATE_HAPPENS_AFTER(&map);
// We swap the new empty map 'tmp' with 'map'.
@@ -6411,8 +6420,11 @@
// test140 TN. Swap. Variant of test79 and test134. {{{1
namespace test140 {
-//typedef std::map<int,int> Container;
- typedef __gnu_cxx::hash_map<int, int> Container;
+#if 0
+typedef __gnu_cxx::hash_map<int, int> Container;
+#else
+typedef std::map<int,int> Container;
+#endif
Mutex mu;
static Container container;
@@ -6519,13 +6531,13 @@
FAST_MODE_INIT(&GLOB2);
printf("test141: FP. unlink/fopen, rmdir/opendir.\n");
- dir_name = tempnam("/tmp", NULL);
- mkdir(dir_name, 0700);
+ dir_name = strdup("/tmp/tsan-XXXXXX");
+ mkdtemp(dir_name);
- filename = tempnam(dir_name, NULL);
- FILE *fp = fopen(filename, "w");
- CHECK(fp);
- fclose(fp);
+ filename = strdup((std::string() + dir_name + "/XXXXXX").c_str());
+ const int fd = mkstemp(filename);
+ CHECK(fd >= 0);
+ close(fd);
MyThreadArray mta1(Waker1, Waiter1);
mta1.Start();
|