Explorar o código

HPCC-14410 switch to use std::atomic

Jake Smith %!s(int64=9) %!d(string=hai) anos
pai
achega
0eaf9aa8e2
Modificáronse 2 ficheiros con 10 adicións e 9 borrados
  1. 3 3
      thorlcr/thorutil/thmem.cpp
  2. 7 6
      thorlcr/thorutil/thmem.hpp

+ 3 - 3
thorlcr/thorutil/thmem.cpp

@@ -1254,7 +1254,7 @@ void CThorSpillableRowArray::initCommon()
 {
     commitRows = 0;
     firstRow = 0;
-    atomic_set(&resizing, 0);
+    resizing = resize_nop;
 }
 
 void CThorSpillableRowArray::clearRows()
@@ -1403,7 +1403,7 @@ bool CThorSpillableRowArray::_flush(bool force)
 {
     dbgassertex(numRows >= commitRows);
     // if firstRow over 50% of commitRows, meaning over half of row array is empty, then reduce
-    if (needFlush(force))
+    if (needToMoveRows(force))
     {
         doFlush();
         return true;
@@ -1514,7 +1514,7 @@ bool CThorSpillableRowArray::resize(rowidx_t requiredRows, unsigned maxSpillCost
         shrinkingCrit.enter(); // will block if shrinking
         shrinkingCrit.leave();
     }
-    if (needFlush(false))
+    if (needToMoveRows(false))
     {
         CThorArrayLockBlock block(*this);
         doFlush();

+ 7 - 6
thorlcr/thorutil/thmem.hpp

@@ -415,26 +415,27 @@ class graph_decl CThorSpillableRowArray : private CThorExpandingRowArray, implem
     mutable CriticalSection cs;
     ICopyArrayOf<IWritePosCallback> writeCallbacks;
     CriticalSection shrinkingCrit;
-    atomic_t resizing;
     enum ResizeState { resize_nop, resize_shrinking, resize_resizing };
+    std::atomic<ResizeState> resizing;
 
     class CToggleResizingState
     {
         ResizeState state;
-        atomic_t &resizing;
+        std::atomic<ResizeState> &resizing;
     public:
-        CToggleResizingState(atomic_t &_resizing) : resizing(_resizing)
+        CToggleResizingState(std::atomic<ResizeState> &_resizing) : resizing(_resizing)
         {
             state = resize_nop;
         }
         ~CToggleResizingState()
         {
             if (state != resize_nop)
-                verify(atomic_cas(&resizing, resize_nop, state));
+                verify(resizing.compare_exchange_strong(state, resize_nop));
         }
         bool tryState(ResizeState newState)
         {
-            if (!atomic_cas(&resizing, newState, resize_nop))
+            ResizeState expected = resize_nop;
+            if (!resizing.compare_exchange_strong(expected, newState))
                 return false;
             state = newState;
             return true;
@@ -443,7 +444,7 @@ class graph_decl CThorSpillableRowArray : private CThorExpandingRowArray, implem
     void initCommon();
     bool _flush(bool force);
     void doFlush();
-    inline bool needFlush(bool force) { return (firstRow != 0 && (force || (firstRow >= commitRows/2))); }
+    inline bool needToMoveRows(bool force) { return (firstRow != 0 && (force || (firstRow >= commitRows/2))); }
 
 public: