diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/background.cpp | 4 | ||||
-rw-r--r-- | util/background.h | 4 | ||||
-rw-r--r-- | util/builder.h | 4 | ||||
-rw-r--r-- | util/goodies.h | 30 | ||||
-rw-r--r-- | util/hashtab.h | 4 | ||||
-rw-r--r-- | util/log.h | 10 | ||||
-rw-r--r-- | util/lruishmap.h | 4 | ||||
-rw-r--r-- | util/md5.hpp | 4 | ||||
-rw-r--r-- | util/miniwebserver.cpp | 4 | ||||
-rw-r--r-- | util/miniwebserver.h | 4 | ||||
-rw-r--r-- | util/mmap.cpp | 12 | ||||
-rw-r--r-- | util/mmap.h | 4 | ||||
-rw-r--r-- | util/sock.cpp | 4 | ||||
-rw-r--r-- | util/sock.h | 10 | ||||
-rw-r--r-- | util/unittest.h | 4 | ||||
-rw-r--r-- | util/util.cpp | 4 |
16 files changed, 104 insertions, 6 deletions
diff --git a/util/background.cpp b/util/background.cpp index de1524afe9c..a1413d3a5bf 100644 --- a/util/background.cpp +++ b/util/background.cpp @@ -18,6 +18,8 @@ #include "goodies.h" #include "background.h" +namespace mongo { + BackgroundJob *BackgroundJob::grab = 0; boost::mutex BackgroundJob::mutex; @@ -57,3 +59,5 @@ bool BackgroundJob::wait(int msMax) { } return true; } + +} // namespace mongo diff --git a/util/background.h b/util/background.h index 09cd08bc9bd..d4b9830c40f 100644 --- a/util/background.h +++ b/util/background.h @@ -16,6 +16,8 @@ #pragma once +namespace mongo { + /* object-orienty background thread dispatching. subclass and define run() @@ -66,3 +68,5 @@ private: static void thr(); volatile State state; }; + +} // namespace mongo diff --git a/util/builder.h b/util/builder.h index 6b75a1c24a3..e883ea2f1f2 100644 --- a/util/builder.h +++ b/util/builder.h @@ -22,6 +22,8 @@ #include "../stdafx.h" +namespace mongo { + class BufBuilder { public: BufBuilder(int initsize = 512) : size(initsize) { @@ -106,3 +108,5 @@ private: int l; int size; }; + +} // namespace mongo diff --git a/util/goodies.h b/util/goodies.h index f5dc39a23d0..3a9479d4106 100644 --- a/util/goodies.h +++ b/util/goodies.h @@ -21,12 +21,26 @@ #include "../stdafx.h" +namespace mongo { + #if !defined(_WIN32) + +} // namespace mongo + #include <pthread.h> + +namespace mongo { + inline pthread_t GetCurrentThreadId() { return pthread_self(); } + +} // namespace mongo + #include <execinfo.h> + +namespace mongo { + /* use "addr2line -CFe <exe>" to parse. */ inline void printStackTrace() { void *b[12]; @@ -95,8 +109,14 @@ inline void dumpmemory(const char *data, int len) { } #undef yassert + +} // namespace mongo + #include <boost/thread/thread.hpp> #include <boost/thread/xtime.hpp> + +namespace mongo { + #undef assert #define assert xassert #define yassert 1 @@ -127,8 +147,12 @@ struct WrappingInt { } }; +} // namespace mongo + #include <ctime> +namespace mongo { + inline void time_t_to_String(time_t t, char *buf) { #if defined(_WIN32) ctime_s(buf, 64, &t); @@ -243,8 +267,12 @@ inline bool endsWith(const char *p, const char *suffix) { return strcmp(p + a - b, suffix) == 0; } +} // namespace mongo + #include "boost/detail/endian.hpp" +namespace mongo { + inline unsigned long swapEndian(unsigned long x) { return ((x & 0xff) << 24) | @@ -263,3 +291,5 @@ inline unsigned long fixEndian(unsigned long x) { } #endif + +} // namespace mongo diff --git a/util/hashtab.h b/util/hashtab.h index 88a799ca01a..80a6ded1030 100644 --- a/util/hashtab.h +++ b/util/hashtab.h @@ -26,6 +26,8 @@ #include "../stdafx.h" #include <map> +namespace mongo { + #pragma pack(push,1) /* you should define: @@ -129,3 +131,5 @@ public: }; #pragma pack(pop) + +} // namespace mongo diff --git a/util/log.h b/util/log.h index a5f10bce6e8..6bcca584184 100644 --- a/util/log.h +++ b/util/log.h @@ -18,6 +18,8 @@ #pragma once +namespace mongo { + class Nullstream { public: Nullstream& operator<<(const char *) { @@ -54,9 +56,6 @@ public: return *this; } }; -inline Nullstream& endl ( Nullstream& os ) { - return os; -} extern Nullstream nullstream; #define LOGIT { boostlock lk(mutex); cout << x; return *this; } @@ -99,9 +98,6 @@ public: return *this; } }; -inline Logstream& endl ( Logstream& os ) { - return os; -} extern Logstream logstream; inline Logstream& problem() { @@ -115,3 +111,5 @@ inline ostream& stdcout() { return cout; } #define cout logstream + +} // namespace mongo diff --git a/util/lruishmap.h b/util/lruishmap.h index 944c492a1dc..bc55702edd6 100644 --- a/util/lruishmap.h +++ b/util/lruishmap.h @@ -21,6 +21,8 @@ #include "../stdafx.h" #include "../util/goodies.h" +namespace mongo { + /* Your K object must define: int hash() - must always return > 0. operator== @@ -73,3 +75,5 @@ private: int *hashes; V *values; }; + +} // namespace mongo diff --git a/util/md5.hpp b/util/md5.hpp index f529147dda3..428036c8d6d 100644 --- a/util/md5.hpp +++ b/util/md5.hpp @@ -3,6 +3,8 @@ #pragma once
#include "md5.h"
+ +namespace mongo { typedef unsigned char md5digest[16];
@@ -16,3 +18,5 @@ inline void md5(const void *buf, int nbytes, md5digest digest) { inline void md5(const char *str, md5digest digest) {
md5(str, strlen(str), digest);
}
+ +} // namespace mongo diff --git a/util/miniwebserver.cpp b/util/miniwebserver.cpp index 91e4dd880c4..2c342aa7f11 100644 --- a/util/miniwebserver.cpp +++ b/util/miniwebserver.cpp @@ -20,6 +20,8 @@ #include "stdafx.h" #include "miniwebserver.h" +namespace mongo { + MiniWebServer::MiniWebServer() { sock = 0; } @@ -181,3 +183,5 @@ void MiniWebServer::run() { closesocket(s); } } + +} // namespace mongo diff --git a/util/miniwebserver.h b/util/miniwebserver.h index ecf6046f841..a101e63fa32 100644 --- a/util/miniwebserver.h +++ b/util/miniwebserver.h @@ -20,6 +20,8 @@ #include "../grid/message.h" +namespace mongo { + class MiniWebServer { public: MiniWebServer(); @@ -49,3 +51,5 @@ private: int sock; }; + +} // namespace mongo diff --git a/util/mmap.cpp b/util/mmap.cpp index 8d3d2447692..447775cb2ad 100644 --- a/util/mmap.cpp +++ b/util/mmap.cpp @@ -19,6 +19,8 @@ #include "stdafx.h" #include "mmap.h" +namespace mongo { + set<MemoryMappedFile*> mmfiles; MemoryMappedFile::~MemoryMappedFile() { @@ -49,8 +51,12 @@ void MemoryMappedFile::updateLength( const char *filename, int &length ) const { #if defined(_WIN32) +} // namespace mongo + #include "windows.h" +namespace mongo { + MemoryMappedFile::MemoryMappedFile() { fd = 0; maphandle = 0; @@ -120,12 +126,16 @@ void MemoryMappedFile::flush(bool) { #else +} // namespace mongo + #include <errno.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +namespace mongo { + MemoryMappedFile::MemoryMappedFile() { fd = 0; maphandle = 0; @@ -208,3 +218,5 @@ void MemoryMappedFile::flush(bool sync) { void* MemoryMappedFile::map(const char *filename) { return map( filename , file_size( filename ) ); // file_size is from boost } + +} // namespace mongo diff --git a/util/mmap.h b/util/mmap.h index ae79a58aad8..07cc885be2f 100644 --- a/util/mmap.h +++ b/util/mmap.h @@ -18,6 +18,8 @@ #pragma once +namespace mongo { + class MemoryMappedFile { public: static void closeAllFiles(); @@ -51,3 +53,5 @@ private: int len; }; + +} // namespace mongo diff --git a/util/sock.cpp b/util/sock.cpp index d89fdaac765..ec3a2c16fdf 100644 --- a/util/sock.cpp +++ b/util/sock.cpp @@ -19,6 +19,8 @@ #include "stdafx.h" #include "sock.h" +namespace mongo { + static boost::mutex sock_mutex; // .empty() if err string hostbyname(const char *hostname) { @@ -187,3 +189,5 @@ void xmain() { #endif + +} // namespace mongo diff --git a/util/sock.h b/util/sock.h index 89ac5ed8f44..d75095e28f0 100644 --- a/util/sock.h +++ b/util/sock.h @@ -22,6 +22,8 @@ #include <sstream> #include "goodies.h" +namespace mongo { + #if defined(_WIN32) //#include <winsock2.h> //#include <ws2tcpip.h> @@ -37,6 +39,9 @@ inline void disableNagle(int sock) { inline void prebindOptions( int sock ) { } #else + +} // namespace mongo + #include <sys/socket.h> #include <sys/types.h> #include <sys/socket.h> @@ -45,6 +50,9 @@ inline void prebindOptions( int sock ) { #include <arpa/inet.h> #include <errno.h> #include <netdb.h> + +namespace mongo { + inline void closesocket(int s) { close(s); } @@ -222,3 +230,5 @@ inline string getHostName() { } + +} // namespace mongo diff --git a/util/unittest.h b/util/unittest.h index df4fab6a2df..0bf2a46100a 100644 --- a/util/unittest.h +++ b/util/unittest.h @@ -18,6 +18,8 @@ #pragma once +namespace mongo { + /* The idea here is to let all initialization of global variables (classes inheriting from UnitTest) complete before we run the tests -- otherwise order of initilization being arbitrary may mess us up. The app's main() function should call runTests(). @@ -48,3 +50,5 @@ struct UnitTest { } }; + +} // namespace mongo diff --git a/util/util.cpp b/util/util.cpp index 2307e64ef84..4736ff86865 100644 --- a/util/util.cpp +++ b/util/util.cpp @@ -20,6 +20,8 @@ #include "goodies.h" #include "unittest.h" +namespace mongo { + vector<UnitTest*> *UnitTest::tests = 0; Nullstream nullstream; @@ -78,3 +80,5 @@ struct UtilTest : public UnitTest { } } utilTest; + +} // namespace mongo |