summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-10-25 07:46:53 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-10-25 07:46:53 +0000
commit2c770d676c4089d7f57abb9ed885d3e458ba6b39 (patch)
tree8378938525da5ffd76dacec719822994b2d78673
parent0d78d991caa9aed8ff3db19586dcf2ac6c3a7fe6 (diff)
* signal.c (rb_atomic_t): GCC (of at least recent versions)
has ubiquitos support for atomic operations. On that compiler a C program can isse a memory barrier using these dedicated instructions. According to the GCC manual they cargo culted this feature form the Itanium ABI so chances are that other compilers could also support this feature. But so far GCC is the only compiler that I know to have it. Also note that this works on non-Itanium machines. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29589 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog11
-rw-r--r--signal.c11
2 files changed, 22 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index a0cf409a37..bc193350e4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Mon Oct 25 16:38:07 2010 URABE Shyouhei <shyouhei@ruby-lang.org>
+
+ * signal.c (rb_atomic_t): GCC (of at least recent versions)
+ has ubiquitos support for atomic operations. On that
+ compiler a C program can isse a memory barrier using these
+ dedicated instructions. According to the GCC manual they
+ cargo culted this feature form the Itanium ABI so chances
+ are that other compilers could also support this feature.
+ But so far GCC is the only compiler that I know to have it.
+ Also note that this works on non-Itanium machines.
+
Mon Oct 25 06:21:35 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vsnprintf.c (BSD_vfprintf): prec digits fractal part should be
diff --git a/signal.c b/signal.c
index 4906e9162a..e2d9d84e4d 100644
--- a/signal.c
+++ b/signal.c
@@ -25,6 +25,17 @@ typedef LONG rb_atomic_t;
# define ATOMIC_INC(var) InterlockedIncrement(&(var))
# define ATOMIC_DEC(var) InterlockedDecrement(&(var))
+#elsif __GNUC__ >= 4
+/* @shyouhei hack to support atomic operations in case of gcc. Gcc
+ * has its own pseudo-insns to support them. See info, or
+ * http://gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html */
+
+typedef unsigned char rb_atomic_t; /* Anything OK */
+# define ATOMIC_TEST(var) __sync_lock_test_and_set(&(var), 0)
+# define ATOMIC_SET(var, val) __sync_lock_test_and_set(&(var), (val))
+# define ATOMIC_INC(var) __sync_fetch_and_add(&(var), 1)
+# define ATOMIC_DEC(var) __sync_fetch_and_sub(&(var), 1)
+
#else
typedef int rb_atomic_t;