ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject [06/10] ignite git commit: IGNITE-2159: CPP: Fixed compilation for interlocked operations on Windows.
Date Wed, 16 Dec 2015 10:28:46 GMT
IGNITE-2159: CPP: Fixed compilation for interlocked operations on Windows.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/65b17666
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/65b17666
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/65b17666

Branch: refs/heads/ignite-843-rc2
Commit: 65b176665e97e753f263231700b6907e51e94b00
Parents: 1acbce1
Author: isapego <isapego@gridgain.com>
Authored: Wed Dec 16 11:32:11 2015 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Wed Dec 16 11:32:11 2015 +0300

----------------------------------------------------------------------
 .../cpp/common/os/win/src/concurrent_os.cpp     | 26 +++++++++++++++++++-
 .../platforms/cpp/core-test/src/cache_test.cpp  |  4 +--
 2 files changed, 27 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/65b17666/modules/platforms/cpp/common/os/win/src/concurrent_os.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/common/os/win/src/concurrent_os.cpp b/modules/platforms/cpp/common/os/win/src/concurrent_os.cpp
index a21f7ec..676d8b6 100644
--- a/modules/platforms/cpp/common/os/win/src/concurrent_os.cpp
+++ b/modules/platforms/cpp/common/os/win/src/concurrent_os.cpp
@@ -17,6 +17,8 @@
 
 #include "ignite/common/concurrent_os.h"
 
+#pragma intrinsic(_InterlockedCompareExchange64)
+
 namespace ignite
 {
     namespace common
@@ -103,17 +105,39 @@ namespace ignite
 
             int64_t Atomics::CompareAndSet64Val(int64_t* ptr, int64_t expVal, int64_t newVal)
             {
-                return InterlockedCompareExchange64(reinterpret_cast<LONG64*>(ptr),
newVal, expVal);
+                return _InterlockedCompareExchange64(reinterpret_cast<LONG64*>(ptr),
newVal, expVal);
             }
 
             int64_t Atomics::IncrementAndGet64(int64_t* ptr)
             {
+#ifdef _WIN64
                 return InterlockedIncrement64(reinterpret_cast<LONG64*>(ptr));
+#else 
+                while (true)
+                {
+                    int64_t expVal = *ptr;
+                    int64_t newVal = expVal + 1;
+
+                    if (CompareAndSet64(ptr, expVal, newVal))
+                        return newVal;
+                }
+#endif
             }
 
             int64_t Atomics::DecrementAndGet64(int64_t* ptr)
             {
+#ifdef _WIN64
                 return InterlockedDecrement64(reinterpret_cast<LONG64*>(ptr));
+#else 
+                while (true)
+                {
+                    int64_t expVal = *ptr;
+                    int64_t newVal = expVal - 1;
+
+                    if (CompareAndSet64(ptr, expVal, newVal))
+                        return newVal;
+                }
+#endif
             }
             
             bool ThreadLocal::OnProcessAttach()

http://git-wip-us.apache.org/repos/asf/ignite/blob/65b17666/modules/platforms/cpp/core-test/src/cache_test.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/core-test/src/cache_test.cpp b/modules/platforms/cpp/core-test/src/cache_test.cpp
index c56054f..32c5bd6 100644
--- a/modules/platforms/cpp/core-test/src/cache_test.cpp
+++ b/modules/platforms/cpp/core-test/src/cache_test.cpp
@@ -234,12 +234,12 @@ BOOST_AUTO_TEST_CASE(TestGetAll)
     
     std::set<int> keySet (keys, keys + 5);
 
-    for (int i = 0; i < keySet.size(); i++)
+    for (int i = 0; i < static_cast<int>(keySet.size()); i++)
         cache.Put(i + 1, i + 1);
 
     std::map<int, int> map = cache.GetAll(keySet);
 
-    for (int i = 0; i < keySet.size(); i++)
+    for (int i = 0; i < static_cast<int>(keySet.size()); i++)
         BOOST_REQUIRE(i + 1 == map[i + 1]);
 }
 


Mime
View raw message