[前][次][番号順一覧][スレッド一覧]

ruby-changes:32871

From: usa <ko1@a...>
Date: Fri, 14 Feb 2014 16:22:29 +0900 (JST)
Subject: [ruby-changes:32871] usa:r44950 (ruby_1_9_3): * ruby_atomic.h (ATOMIC_CAS): added.

usa	2014-02-14 16:22:21 +0900 (Fri, 14 Feb 2014)

  New Revision: 44950

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44950

  Log:
    * ruby_atomic.h (ATOMIC_CAS): added.
    
    * signal.c (ruby_atomic_compare_and_swap): ATOMIC_CAS implementation
      for non-VC/gcc platform.

  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/ruby_atomic.h
    branches/ruby_1_9_3/signal.c
    branches/ruby_1_9_3/version.h
Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 44949)
+++ ruby_1_9_3/ChangeLog	(revision 44950)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ChangeLog#L1
+Fri Feb 14 16:21:28 2014  NAKAMURA Usaku  <usa@r...>
+
+	* ruby_atomic.h (ATOMIC_CAS): added.
+
+	* signal.c (ruby_atomic_compare_and_swap): ATOMIC_CAS implementation
+	  for non-VC/gcc platform.
+
 Fri Feb 14 15:56:27 2014  Tanaka Akira  <akr@f...>
 
 	* lib/resolv.rb: Ignore name servers which cause EAFNOSUPPORT on
Index: ruby_1_9_3/ruby_atomic.h
===================================================================
--- ruby_1_9_3/ruby_atomic.h	(revision 44949)
+++ ruby_1_9_3/ruby_atomic.h	(revision 44950)
@@ -13,6 +13,7 @@ typedef unsigned int rb_atomic_t; /* Any https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ruby_atomic.h#L13
 # define ATOMIC_DEC(var) __sync_fetch_and_sub(&(var), 1)
 # define ATOMIC_OR(var, val) __sync_or_and_fetch(&(var), (val))
 # define ATOMIC_EXCHANGE(var, val) __sync_lock_test_and_set(&(var), (val))
+# define ATOMIC_CAS(var, oldval, newval) __sync_val_compare_and_swap(&(var), (oldval), (newval))
 
 # define ATOMIC_SIZE_ADD(var, val) __sync_fetch_and_add(&(var), (val))
 # define ATOMIC_SIZE_SUB(var, val) __sync_fetch_and_sub(&(var), (val))
@@ -49,7 +50,17 @@ rb_w32_atomic_or(volatile rb_atomic_t *v https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ruby_atomic.h#L50
 # define ATOMIC_OR(var, val) _InterlockedOr(&(var), (val))
 #endif
 # define ATOMIC_EXCHANGE(var, val) InterlockedExchange(&(var), (val))
+# define ATOMIC_CAS(var, oldval, newval) InterlockedCompareExchange(&(var), (newval), (oldval))
 
+# if defined _MSC_VER && _MSC_VER <= 1200
+static inline rb_atomic_t
+rb_w32_atomic_cas(volatile rb_atomic_t *var, rb_atomic_t oldval, rb_atomic_t newval)
+{
+    return (rb_atomic_t)InterlockedCompareExchange((PVOID *)var, (PVOID)newval, (PVOID)oldval);
+}
+#   undef ATOMIC_CAS
+#   define ATOMIC_CAS(var, oldval, newval) rb_w32_atomic_cas(&(var), (oldval), (newval))
+# endif
 # ifdef _M_AMD64
 #  define ATOMIC_SIZE_ADD(var, val) InterlockedExchangeAdd64(&(var), (val))
 #  define ATOMIC_SIZE_SUB(var, val) InterlockedExchangeAdd64(&(var), -(val))
@@ -74,6 +85,7 @@ typedef unsigned int rb_atomic_t; https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ruby_atomic.h#L85
 # define ATOMIC_DEC(var) atomic_dec_uint(&(var))
 # define ATOMIC_OR(var, val) atomic_or_uint(&(var), (val))
 # define ATOMIC_EXCHANGE(var, val) atomic_swap_uint(&(var), (val))
+# define ATOMIC_CAS(var, oldval, newval) atomic_cas_uint(&(var), (oldval), (newval))
 
 # if SIZEOF_SIZE_T == SIZEOF_LONG
 #  define ATOMIC_SIZE_ADD(var, val) atomic_add_long(&(var), (val))
@@ -93,12 +105,16 @@ typedef unsigned int rb_atomic_t; https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ruby_atomic.h#L105
 typedef int rb_atomic_t;
 #define NEED_RUBY_ATOMIC_EXCHANGE
 extern rb_atomic_t ruby_atomic_exchange(rb_atomic_t *ptr, rb_atomic_t val);
+extern rb_atomic_t ruby_atomic_compare_and_swap(rb_atomic_t *ptr,
+						rb_atomic_t cmp,
+						rb_atomic_t newval);
 
 # define ATOMIC_SET(var, val) (void)((var) = (val))
 # define ATOMIC_INC(var) ((var)++)
 # define ATOMIC_DEC(var) ((var)--)
 # define ATOMIC_OR(var, val) ((var) |= (val))
 # define ATOMIC_EXCHANGE(var, val) ruby_atomic_exchange(&(var), (val))
+# define ATOMIC_CAS(var, oldval, newval) ruby_atomic_compare_and_swap(&(var), (oldval), (newval))
 
 # define ATOMIC_SIZE_ADD(var, val) (void)((var) += (val))
 # define ATOMIC_SIZE_SUB(var, val) (void)((var) -= (val))
Index: ruby_1_9_3/version.h
===================================================================
--- ruby_1_9_3/version.h	(revision 44949)
+++ ruby_1_9_3/version.h	(revision 44950)
@@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/version.h#L1
 #define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 530
+#define RUBY_PATCHLEVEL 531
 
 #define RUBY_RELEASE_DATE "2014-02-14"
 #define RUBY_RELEASE_YEAR 2014
Index: ruby_1_9_3/signal.c
===================================================================
--- ruby_1_9_3/signal.c	(revision 44949)
+++ ruby_1_9_3/signal.c	(revision 44950)
@@ -29,6 +29,17 @@ ruby_atomic_exchange(rb_atomic_t *ptr, r https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/signal.c#L29
     *ptr = val;
     return old;
 }
+
+rb_atomic_t
+ruby_atomic_compare_and_swap(rb_atomic_t *ptr, rb_atomic_t cmp,
+			     rb_atomic_t newval)
+{
+    rb_atomic_t old = *ptr;
+    if (old == cmp) {
+	*ptr = newval;
+    }
+    return old;
+}
 #endif
 
 #if defined(__BEOS__) || defined(__HAIKU__)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]