From 047bd22aaeefebd923ced04c4bf9284930eaaeee Mon Sep 17 00:00:00 2001 From: yuslepukhin Date: Fri, 20 Nov 2015 15:31:47 -0800 Subject: [PATCH] Build on Visual Studio 2015 Update 1 --- CMakeLists.txt | 1 + db/db_test.cc | 4 ++-- port/win/port_win.cc | 2 +- port/win/port_win.h | 46 +++++++++++++++++++++++++++++++++------ util/thread_local_test.cc | 16 ++++++++------ 5 files changed, 52 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c0742c929..997f57cc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ # 3. Run cmake to generate project files for Windows, add more options to enable required third-party libraries. # See thirdparty.inc for more information. # sample command: cmake -G "Visual Studio 12 Win64" -DGFLAGS=1 -DSNAPPY=1 -DJEMALLOC=1 .. +# OR for VS Studio 15 cmake -G "Visual Studio 12 Win64" -DGFLAGS=1 -DSNAPPY=1 -DJEMALLOC=1 .. # 4. Then build the project in debug mode (you may want to add /m[:] flag to run msbuild in parallel threads # or simply /m ot use all avail cores) # msbuild rocksdb.sln diff --git a/db/db_test.cc b/db/db_test.cc index 901a20102..965389289 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -8758,7 +8758,7 @@ TEST_F(DBTest, LargeBatchWithColumnFamilies) { for (int pass = 1; pass <= 3; pass++) { WriteBatch batch; size_t write_size = 1024 * 1024 * (5 + i); - fprintf(stderr, "prepare: %ld MB, pass:%d\n", (write_size / 1024 / 1024), + fprintf(stderr, "prepare: %" ROCKSDB_PRIszt " MB, pass:%d\n", (write_size / 1024 / 1024), pass); for (;;) { std::string data(3000, j++ % 127 + 20); @@ -8768,7 +8768,7 @@ TEST_F(DBTest, LargeBatchWithColumnFamilies) { break; } } - fprintf(stderr, "write: %ld MB\n", (batch.GetDataSize() / 1024 / 1024)); + fprintf(stderr, "write: %" ROCKSDB_PRIszt " MB\n", (batch.GetDataSize() / 1024 / 1024)); ASSERT_OK(dbfull()->Write(WriteOptions(), &batch)); fprintf(stderr, "done\n"); } diff --git a/port/win/port_win.cc b/port/win/port_win.cc index 35f53d675..99998b359 100644 --- a/port/win/port_win.cc +++ b/port/win/port_win.cc @@ -100,7 +100,7 @@ void CondVar::Signal() { cv_.notify_one(); } void CondVar::SignalAll() { cv_.notify_all(); } void InitOnce(OnceType* once, void (*initializer)()) { - std::call_once(*once, initializer); + std::call_once(once->flag_, initializer); } // Private structure, exposed only by pointer diff --git a/port/win/port_win.h b/port/win/port_win.h index 8f5d7e1e0..9d5be2c78 100644 --- a/port/win/port_win.h +++ b/port/win/port_win.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -58,8 +59,6 @@ typedef SSIZE_T ssize_t; #define ROCKSDB_PRIszt "Iu" #endif -#define ROCKSDB_NOEXCEPT - #define __attribute__(A) #ifdef ZLIB @@ -96,17 +95,35 @@ std::string GetWindowsErrSz(DWORD err); namespace port { +// VS 15 +#if (defined _MSC_VER) && (_MSC_VER >= 1900) + +#define ROCKSDB_NOEXCEPT noexcept + // For use at db/file_indexer.h kLevelMaxIndex -const int kMaxInt32 = INT32_MAX; -const uint64_t kMaxUint64 = UINT64_MAX; +const int kMaxInt32 = std::numeric_limits::max(); +const uint64_t kMaxUint64 = std::numeric_limits::max(); + +const size_t kMaxSizet = std::numeric_limits::max(); + +#else //_MSC_VER + +#define ROCKSDB_NOEXCEPT // std::numeric_limits::max() is not constexpr just yet // therefore, use the same limits + +// For use at db/file_indexer.h kLevelMaxIndex +const int kMaxInt32 = INT32_MAX; +const uint64_t kMaxUint64 = UINT64_MAX; + #ifdef _WIN64 const size_t kMaxSizet = UINT64_MAX; #else const size_t kMaxSizet = UINT_MAX; #endif +#endif //_MSC_VER + const bool kLittleEndian = true; class CondVar; @@ -207,8 +224,23 @@ class CondVar { Mutex* mu_; }; -typedef std::once_flag OnceType; -#define LEVELDB_ONCE_INIT std::once_flag::once_flag(); + +// OnceInit type helps emulate +// Posix semantics with initialization +// adopted in the project +struct OnceType { + + struct Init {}; + + OnceType() {} + OnceType(const Init&) {} + OnceType(const OnceType&) = delete; + OnceType& operator=(const OnceType&) = delete; + + std::once_flag flag_; +}; + +#define LEVELDB_ONCE_INIT port::OnceType::Init() extern void InitOnce(OnceType* once, void (*initializer)()); #define CACHE_LINE_SIZE 64U @@ -280,4 +312,4 @@ using port::truncate; } // namespace rocksdb -#endif // STORAGE_LEVELDB_PORT_PORT_POSIX_H_ +#endif // STORAGE_LEVELDB_PORT_PORT_WIN_H_ diff --git a/util/thread_local_test.cc b/util/thread_local_test.cc index a78a84997..368818669 100644 --- a/util/thread_local_test.cc +++ b/util/thread_local_test.cc @@ -165,7 +165,9 @@ TEST_F(ThreadLocalTest, ConcurrentReadWriteTest) { auto& p = *static_cast(ptr); p.mu->Lock(); - int own = ++(p.started); + // Size_T switches size along with the ptr size + // we want to cast to. + size_t own = ++(p.started); p.cv->SignalAll(); while (p.started != p.total) { p.cv->Wait(); @@ -183,16 +185,16 @@ TEST_F(ThreadLocalTest, ConcurrentReadWriteTest) { auto* env = Env::Default(); auto start = env->NowMicros(); - p.tls1.Reset(reinterpret_cast(own)); - p.tls2->Reset(reinterpret_cast(own + 1)); + p.tls1.Reset(reinterpret_cast(own)); + p.tls2->Reset(reinterpret_cast(own + 1)); // Loop for 1 second while (env->NowMicros() - start < 1000 * 1000) { for (int iter = 0; iter < 100000; ++iter) { - ASSERT_TRUE(p.tls1.Get() == reinterpret_cast(own)); - ASSERT_TRUE(p.tls2->Get() == reinterpret_cast(own + 1)); + ASSERT_TRUE(p.tls1.Get() == reinterpret_cast(own)); + ASSERT_TRUE(p.tls2->Get() == reinterpret_cast(own + 1)); if (p.doWrite) { - p.tls1.Reset(reinterpret_cast(own)); - p.tls2->Reset(reinterpret_cast(own + 1)); + p.tls1.Reset(reinterpret_cast(own)); + p.tls2->Reset(reinterpret_cast(own + 1)); } } }