瀏覽代碼

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 年之前
父節點
當前提交
493652d833
共有 2 個文件被更改,包括 4 次插入4 次删除
  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;
 }