Bladeren bron

Use GCC atomic operations in more cases

The atomic operations provided by gcc are not specific to linux, and should
be used wherever they are available rather than falling back to the (very
slow) alternative implementations in jiface.cpp.

The alternative implementations in jiface.cpp are also faulty, with the
decrement and increment reversed. This commit fixes that typo.

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 13 jaren geleden
bovenliggende
commit
493652d833
2 gewijzigde bestanden met toevoegingen van 4 en 4 verwijderingen
  1. 1 1
      system/jlib/jatomic.hpp
  2. 3 3
      system/jlib/jiface.cpp

+ 1 - 1
system/jlib/jatomic.hpp

@@ -58,7 +58,7 @@ typedef volatile long atomic_t;
 #endif      
 
 
-#elif defined(__linux__) 
+#elif defined(__GNUC__)
 
 typedef struct { volatile int counter; } atomic_t;
 #define ATOMIC_INIT(i)          { (i) }

+ 3 - 3
system/jlib/jiface.cpp

@@ -30,7 +30,7 @@ void CInterface::beforeDispose()
 
 //===========================================================================
 
-#if !defined(_WIN32) && !defined(__linux__)
+#if !defined(_WIN32) && !defined(__GNUC__)
 
 static CriticalSection *ICrit;
 
@@ -47,7 +47,7 @@ MODULE_EXIT()
 bool poor_atomic_dec_and_test(atomic_t * v)
 {
     ICrit->enter();
-    bool ret = (++(*v) == 0);
+    bool ret = (--(*v) == 0);
     ICrit->leave();
     return ret;
 }
@@ -55,7 +55,7 @@ bool poor_atomic_dec_and_test(atomic_t * v)
 bool poor_atomic_inc_and_test(atomic_t * v)
 {
     ICrit->enter();
-    bool ret = (--(*v) == 0);
+    bool ret = (++(*v) == 0);
     ICrit->leave();
     return ret;
 }