summaryrefslogtreecommitdiff
path: root/src/mongo/db/globals.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/globals.h')
-rw-r--r--src/mongo/db/globals.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/mongo/db/globals.h b/src/mongo/db/globals.h
new file mode 100644
index 00000000000..093bec76a0e
--- /dev/null
+++ b/src/mongo/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;
+ }
+ };
+
+}