Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

concurrency

beginnings of a bit of framework to help with correctness. tbd if helpful will iterate.
  • Loading branch information...
commit 3844dd29f85f57ef4e757db0b7ce22920bafa76e 1 parent dfaf90e
@dwight dwight authored
View
5 db/client.cpp
@@ -79,9 +79,14 @@ namespace mongo {
/* each thread which does db operations has a Client object in TLS.
call this when your thread starts.
*/
+ static unsigned long long nThreads = 0;
+ void assertStartingUp() {
+ dassert( nThreads <= 1 );
+ }
Client& Client::initThread(const char *desc, AbstractMessagingPort *mp) {
#if defined(_DEBUG)
{
+ nThreads++; // never decremented. this is for casi class asserts
if( sizeof(void*) == 8 ) {
StackChecker sc;
sc.init();
View
17 db/cmdline.cpp
@@ -23,13 +23,13 @@
#include "../util/processinfo.h"
#include "../util/net/listen.h"
#include "security_common.h"
-
#ifdef _WIN32
#include <direct.h>
#else
#include <sys/types.h>
#include <sys/wait.h>
#endif
+#include "globals.h"
#define MAX_LINE_LENGTH 256
@@ -486,18 +486,19 @@ namespace mongo {
return s.str();
}
+ casi< map<string,ParameterValidator*> * > pv_all = 0;
+
ParameterValidator::ParameterValidator( const string& name ) : _name( name ) {
- if ( ! _all )
- _all = new map<string,ParameterValidator*>();
- (*_all)[_name] = this;
+ if ( ! pv_all)
+ pv_all.ref() = new map<string,ParameterValidator*>();
+ (*pv_all.ref())[_name] = this;
}
-
+
ParameterValidator * ParameterValidator::get( const string& name ) {
- map<string,ParameterValidator*>::iterator i = _all->find( name );
- if ( i == _all->end() )
+ map<string,ParameterValidator*>::const_iterator i = pv_all.get()->find( name );
+ if ( i == pv_all.get()->end() )
return NULL;
return i->second;
}
- map<string,ParameterValidator*> * ParameterValidator::_all = 0;
}
View
8 db/cmdline.h
@@ -25,8 +25,6 @@ namespace mongo {
class SSLManager;
#endif
-
-
/* command line options
*/
/* concurrency: OK/READ */
@@ -197,10 +195,8 @@ namespace mongo {
static ParameterValidator * get( const string& name );
private:
- string _name;
-
- // don't need to lock since this is all done in static init
- static map<string,ParameterValidator*> * _all;
+ const string _name;
};
}
+
View
1  db/db.vcxproj
@@ -703,6 +703,7 @@
<ClInclude Include="dur_journalimpl.h" />
<ClInclude Include="dur_stats.h" />
<ClInclude Include="geo\core.h" />
+ <ClInclude Include="globals.h" />
<ClInclude Include="helpers\dblogger.h" />
<ClInclude Include="instance.h" />
<ClInclude Include="mongommf.h" />
View
1  db/db.vcxproj.filters
@@ -330,6 +330,7 @@
</ClInclude>
<ClInclude Include="..\third_party\pcre-7.4\config.h" />
<ClInclude Include="..\third_party\pcre-7.4\pcre.h" />
+ <ClInclude Include="globals.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="db.rc" />
View
54 db/globals.h
@@ -0,0 +1,54 @@
+// @file globals.h
+// grouping of global variables to make concurrency work clearer
+
+#pragma once
+
+namespace mongo {
+
+ void assertStartingUp();
+
+ // this is prototype for now, we'll see if it is helpful
+
+ /** "value is Const After Server Init" helper
+ *
+ * Example:
+ *
+ * casi<int> foo = 3;
+ * foo.ref() = 4; // asserts if not still in server init
+ * int x = foo+1; // ok anytime
+ *
+ */
+ template< class T >
+ class casi : boost::noncopyable {
+ T val;
+ public:
+ casi(const T& t) : val(t) {
+ DEV assertStartingUp();
+ }
+ operator const T& () { return val; }
+ T& ref() {
+ DEV assertStartingUp();
+ return val;
+ }
+ };
+
+ /** partially specialized for cases where out global variable is a pointer -- we want the value
+ * pointed at to be constant, not just the pointer itself
+ */
+ template< typename T >
+ class casi<T*> : boost::noncopyable {
+ T * val;
+ void operator=(T*);
+ public:
+ casi(T* t) : val(t) {
+ DEV assertStartingUp();
+ }
+ operator const T* () { return val; }
+ const T* get() { return val; }
+ T*& ref() {
+ DEV assertStartingUp();
+ return val;
+ }
+ };
+
+}
View
1  pch.cpp
@@ -21,6 +21,7 @@
#define JSTIME_VIRTUAL_SKEW
namespace mongo {
+ // jsTime_virtual_skew is just for testing. a test command manipulates it.
long long jsTime_virtual_skew = 0;
boost::thread_specific_ptr<long long> jsTime_virtual_thread_skew;
}
View
5 s/s_only.cpp
@@ -42,7 +42,12 @@ namespace mongo {
Client::~Client() {}
bool Client::shutdown() { return true; }
+ static unsigned long long nThreads = 0;
+ void assertStartingUp() {
+ dassert( nThreads <= 1 );
+ }
Client& Client::initThread(const char *desc, AbstractMessagingPort *mp) {
+ DEV nThreads++; // never decremented. this is for casi class asserts
setThreadName(desc);
assert( currentClient.get() == 0 );
Client *c = new Client(desc, mp);
Please sign in to comment.
Something went wrong with that request. Please try again.