summaryrefslogtreecommitdiff
path: root/util/concurrency/race.h
diff options
context:
space:
mode:
Diffstat (limited to 'util/concurrency/race.h')
-rw-r--r--util/concurrency/race.h49
1 files changed, 46 insertions, 3 deletions
diff --git a/util/concurrency/race.h b/util/concurrency/race.h
index 0b8338c..4644e37 100644
--- a/util/concurrency/race.h
+++ b/util/concurrency/race.h
@@ -19,15 +19,56 @@ namespace mongo {
the same time. Also detects and disallows recursion.
*/
+#ifdef _WIN32
+ typedef unsigned threadId_t;
+#else
+ typedef pthread_t threadId_t;
+#endif
+
+
#if defined(_DEBUG)
+ namespace race {
+
+ class CodePoint {
+ public:
+ string lastName;
+ threadId_t lastTid;
+ string file;
+ CodePoint(string f) : lastTid(0), file(f) { }
+ };
+ class Check {
+ public:
+ Check(CodePoint& p) {
+ threadId_t t = GetCurrentThreadId();
+ if( p.lastTid == 0 ) {
+ p.lastTid = t;
+ p.lastName = getThreadName();
+ }
+ else if( t != p.lastTid ) {
+ log() << "\n\n\n\n\nRACE? error assert\n " << p.file << '\n'
+ << " " << p.lastName
+ << " " << getThreadName() << "\n\n" << endl;
+ mongoAbort("racecheck");
+ }
+ };
+ };
+
+ }
+
+#define RACECHECK
+ // dm TODO - the right code for this file is in a different branch at the moment (merge)
+ //#define RACECHECK
+ //static race::CodePoint __cp(__FILE__);
+ //race::Check __ck(__cp);
+
class CodeBlock {
volatile int n;
- unsigned tid;
+ threadId_t tid;
void fail() {
log() << "synchronization (race condition) failure" << endl;
printStackTrace();
- abort();
+ ::abort();
}
void enter() {
if( ++n != 1 ) fail();
@@ -58,6 +99,8 @@ namespace mongo {
#else
+#define RACECHECK
+
class CodeBlock{
public:
class Within {
@@ -69,4 +112,4 @@ namespace mongo {
#endif
-}
+} // namespace