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

ruby-changes:40918

From: nobu <ko1@a...>
Date: Wed, 9 Dec 2015 16:31:04 +0900 (JST)
Subject: [ruby-changes:40918] nobu:r52997 (trunk): Revert r52995

nobu	2015-12-09 16:30:44 +0900 (Wed, 09 Dec 2015)

  New Revision: 52997

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

  Log:
    Revert r52995
    
    revert slow atomic operations.

  Modified files:
    trunk/ChangeLog
    trunk/common.mk
    trunk/regcomp.c
    trunk/regint.h
    trunk/regparse.c
    trunk/ruby_atomic.h
Index: regparse.c
===================================================================
--- regparse.c	(revision 52996)
+++ regparse.c	(revision 52997)
@@ -1031,44 +1031,8 @@ typedef struct _FreeNode { https://github.com/ruby/ruby/blob/trunk/regparse.c#L1031
 } FreeNode;
 
 static FreeNode* FreeNodeList = (FreeNode* )NULL;
-
-#define PopFreeNode(n, popped) \
-  do { \
-    FreeNode* n = FreeNodeList; \
-    while (IS_NOT_NULL(n)) { \
-      FreeNode* next = n->next; \
-      FreeNode *head = ATOMIC_PTR_CAS(FreeNodeList, n, next); \
-      if (head == n) { \
-	popped; \
-	n = next; \
-      } \
-      else { \
-	n = head; /* modified, retry */ \
-      } \
-    } \
-  } while (0)
-
 #endif
 
-static void
-node_recycle(Node* node)
-{
-#ifdef USE_PARSE_TREE_NODE_RECYCLE
-  FreeNode* n = (FreeNode* )node;
-  FreeNode* list = FreeNodeList;
-  FreeNode* l;
-
-  /* THREAD_ATOMIC_START; */
-  do {
-    n->next = l = list;
-    list = ATOMIC_PTR_CAS(FreeNodeList, list, n);
-  } while (list != l);
-  /* THREAD_ATOMIC_END; */
-#else
-  xfree(node);
-#endif
-}
-
 extern void
 onig_node_free(Node* node)
 {
@@ -1089,7 +1053,18 @@ onig_node_free(Node* node) https://github.com/ruby/ruby/blob/trunk/regparse.c#L1053
     {
       Node* next_node = NCDR(node);
 
-      node_recycle(node);
+#ifdef USE_PARSE_TREE_NODE_RECYCLE
+      {
+	FreeNode* n = (FreeNode* )node;
+
+        THREAD_ATOMIC_START;
+	n->next = FreeNodeList;
+	FreeNodeList = n;
+        THREAD_ATOMIC_END;
+      }
+#else
+      xfree(node);
+#endif
       node = next_node;
       goto start;
     }
@@ -1126,15 +1101,32 @@ onig_node_free(Node* node) https://github.com/ruby/ruby/blob/trunk/regparse.c#L1101
     break;
   }
 
-  node_recycle(node);
+#ifdef USE_PARSE_TREE_NODE_RECYCLE
+  {
+    FreeNode* n = (FreeNode* )node;
+
+    THREAD_ATOMIC_START;
+    n->next = FreeNodeList;
+    FreeNodeList = n;
+    THREAD_ATOMIC_END;
+  }
+#else
+  xfree(node);
+#endif
 }
 
 #ifdef USE_PARSE_TREE_NODE_RECYCLE
 extern int
 onig_free_node_list(void)
 {
+  FreeNode* n;
+
   /* THREAD_ATOMIC_START; */
-  PopFreeNode(n, xfree(n));
+  while (IS_NOT_NULL(FreeNodeList)) {
+    n = FreeNodeList;
+    FreeNodeList = FreeNodeList->next;
+    xfree(n);
+  }
   /* THREAD_ATOMIC_END; */
   return 0;
 }
@@ -1146,9 +1138,14 @@ node_new(void) https://github.com/ruby/ruby/blob/trunk/regparse.c#L1138
   Node* node;
 
 #ifdef USE_PARSE_TREE_NODE_RECYCLE
-  /* THREAD_ATOMIC_START; */
-  PopFreeNode(n, return (Node* )n);
-  /* THREAD_ATOMIC_END; */
+  THREAD_ATOMIC_START;
+  if (IS_NOT_NULL(FreeNodeList)) {
+    node = (Node* )FreeNodeList;
+    FreeNodeList = FreeNodeList->next;
+    THREAD_ATOMIC_END;
+    return node;
+  }
+  THREAD_ATOMIC_END;
 #endif
 
   node = (Node* )xmalloc(sizeof(Node));
@@ -1158,14 +1155,17 @@ node_new(void) https://github.com/ruby/ruby/blob/trunk/regparse.c#L1155
 
 #if defined(USE_MULTI_THREAD_SYSTEM) && \
     defined(USE_SHARED_CCLASS_TABLE) && \
-    defined(USE_PARSE_TREE_NODE_RECYCLE) && \
-    0
+    defined(USE_PARSE_TREE_NODE_RECYCLE)
 static Node*
 node_new_locked(void)
 {
   Node* node;
 
-  PopFreeNode(n, return (Node* )n);
+  if (IS_NOT_NULL(FreeNodeList)) {
+    node = (Node* )FreeNodeList;
+    FreeNodeList = FreeNodeList->next;
+    return node;
+  }
 
   node = (Node* )xmalloc(sizeof(Node));
   /* xmemset(node, 0, sizeof(Node)); */
@@ -1195,8 +1195,7 @@ node_new_cclass(void) https://github.com/ruby/ruby/blob/trunk/regparse.c#L1195
 
 #if defined(USE_MULTI_THREAD_SYSTEM) && \
     defined(USE_SHARED_CCLASS_TABLE) && \
-    defined(USE_PARSE_TREE_NODE_RECYCLE) && \
-    0
+    defined(USE_PARSE_TREE_NODE_RECYCLE)
 static Node*
 node_new_cclass_locked(void)
 {
Index: regcomp.c
===================================================================
--- regcomp.c	(revision 52996)
+++ regcomp.c	(revision 52997)
@@ -5663,11 +5663,10 @@ onig_transfer(regex_t* to, regex_t* from https://github.com/ruby/ruby/blob/trunk/regcomp.c#L5663
 extern void
 onig_chain_link_add(regex_t* to, regex_t* add)
 {
-  /* THREAD_ATOMIC_START; */
-  do {
-    REGEX_CHAIN_HEAD(to);
-  } while (IS_NOT_NULL(ATOMIC_PTR_CAS(to->chain, (regex_t* )NULL, add)));
-  /* THREAD_ATOMIC_END; */
+  THREAD_ATOMIC_START;
+  REGEX_CHAIN_HEAD(to);
+  to->chain = add;
+  THREAD_ATOMIC_END;
 }
 
 extern void
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52996)
+++ ChangeLog	(revision 52997)
@@ -6,15 +6,6 @@ Wed Dec  9 16:10:37 2015  Koichi Sasada https://github.com/ruby/ruby/blob/trunk/ChangeLog#L6
 
 	* test/ruby/test_method.rb: add a test.
 
-Wed Dec  9 15:48:12 2015  Nobuyoshi Nakada  <nobu@r...>
-
-	* regcomp.c (onig_chain_link_add): use atomic operation instead of
-	  mutex.
-
-	* regint.h (ONIG_STATE_{INC,DEC}_THREAD): ditto.
-
-	* regparse.c (PopFreeNode, node_recycle): ditto.
-
 Wed Dec  9 14:45:27 2015  Koichi Sasada  <ko1@a...>
 
 	* gc.c (gc_mark_stacked_objects): fix typo.
Index: ruby_atomic.h
===================================================================
--- ruby_atomic.h	(revision 52996)
+++ ruby_atomic.h	(revision 52997)
@@ -42,7 +42,6 @@ typedef unsigned int rb_atomic_t; /* Any https://github.com/ruby/ruby/blob/trunk/ruby_atomic.h#L42
 #pragma intrinsic(_InterlockedOr)
 #endif
 typedef LONG rb_atomic_t;
-#define SIZEOF_ATOMIC_T SIZEOF_LONG
 
 # define ATOMIC_SET(var, val) InterlockedExchange(&(var), (val))
 # define ATOMIC_INC(var) InterlockedIncrement(&(var))
@@ -144,10 +143,6 @@ ruby_atomic_size_exchange(size_t *ptr, s https://github.com/ruby/ruby/blob/trunk/ruby_atomic.h#L143
 }
 #endif
 
-#ifndef SIZEOF_ATOMIC_T
-#define SIZEOF_ATOMIC_T SIZEOF_INT
-#endif
-
 #ifndef ATOMIC_SIZE_INC
 # define ATOMIC_SIZE_INC(var) ATOMIC_INC(var)
 #endif
Index: common.mk
===================================================================
--- common.mk	(revision 52996)
+++ common.mk	(revision 52997)
@@ -1345,7 +1345,6 @@ enc/unicode.$(OBJEXT): {$(VPATH)}missing https://github.com/ruby/ruby/blob/trunk/common.mk#L1345
 enc/unicode.$(OBJEXT): {$(VPATH)}oniguruma.h
 enc/unicode.$(OBJEXT): {$(VPATH)}regenc.h
 enc/unicode.$(OBJEXT): {$(VPATH)}regint.h
-enc/unicode.$(OBJEXT): {$(VPATH)}ruby_atomic.h
 enc/unicode.$(OBJEXT): {$(VPATH)}st.h
 enc/unicode.$(OBJEXT): {$(VPATH)}subst.h
 enc/us_ascii.$(OBJEXT): {$(VPATH)}config.h
@@ -1988,7 +1987,6 @@ re.$(OBJEXT): {$(VPATH)}re.h https://github.com/ruby/ruby/blob/trunk/common.mk#L1987
 re.$(OBJEXT): {$(VPATH)}regenc.h
 re.$(OBJEXT): {$(VPATH)}regex.h
 re.$(OBJEXT): {$(VPATH)}regint.h
-re.$(OBJEXT): {$(VPATH)}ruby_atomic.h
 re.$(OBJEXT): {$(VPATH)}st.h
 re.$(OBJEXT): {$(VPATH)}subst.h
 re.$(OBJEXT): {$(VPATH)}util.h
@@ -2001,7 +1999,6 @@ regcomp.$(OBJEXT): {$(VPATH)}oniguruma.h https://github.com/ruby/ruby/blob/trunk/common.mk#L1999
 regcomp.$(OBJEXT): {$(VPATH)}regcomp.c
 regcomp.$(OBJEXT): {$(VPATH)}regenc.h
 regcomp.$(OBJEXT): {$(VPATH)}regint.h
-regcomp.$(OBJEXT): {$(VPATH)}ruby_atomic.h
 regcomp.$(OBJEXT): {$(VPATH)}regparse.h
 regcomp.$(OBJEXT): {$(VPATH)}st.h
 regcomp.$(OBJEXT): {$(VPATH)}subst.h
@@ -2014,7 +2011,6 @@ regenc.$(OBJEXT): {$(VPATH)}oniguruma.h https://github.com/ruby/ruby/blob/trunk/common.mk#L2011
 regenc.$(OBJEXT): {$(VPATH)}regenc.c
 regenc.$(OBJEXT): {$(VPATH)}regenc.h
 regenc.$(OBJEXT): {$(VPATH)}regint.h
-regenc.$(OBJEXT): {$(VPATH)}ruby_atomic.h
 regenc.$(OBJEXT): {$(VPATH)}st.h
 regenc.$(OBJEXT): {$(VPATH)}subst.h
 regerror.$(OBJEXT): $(hdrdir)/ruby/ruby.h
@@ -2026,7 +2022,6 @@ regerror.$(OBJEXT): {$(VPATH)}oniguruma. https://github.com/ruby/ruby/blob/trunk/common.mk#L2022
 regerror.$(OBJEXT): {$(VPATH)}regenc.h
 regerror.$(OBJEXT): {$(VPATH)}regerror.c
 regerror.$(OBJEXT): {$(VPATH)}regint.h
-regerror.$(OBJEXT): {$(VPATH)}ruby_atomic.h
 regerror.$(OBJEXT): {$(VPATH)}st.h
 regerror.$(OBJEXT): {$(VPATH)}subst.h
 regexec.$(OBJEXT): $(hdrdir)/ruby/ruby.h
@@ -2038,7 +2033,6 @@ regexec.$(OBJEXT): {$(VPATH)}oniguruma.h https://github.com/ruby/ruby/blob/trunk/common.mk#L2033
 regexec.$(OBJEXT): {$(VPATH)}regenc.h
 regexec.$(OBJEXT): {$(VPATH)}regexec.c
 regexec.$(OBJEXT): {$(VPATH)}regint.h
-regexec.$(OBJEXT): {$(VPATH)}ruby_atomic.h
 regexec.$(OBJEXT): {$(VPATH)}st.h
 regexec.$(OBJEXT): {$(VPATH)}subst.h
 regparse.$(OBJEXT): $(hdrdir)/ruby/ruby.h
@@ -2051,7 +2045,6 @@ regparse.$(OBJEXT): {$(VPATH)}regenc.h https://github.com/ruby/ruby/blob/trunk/common.mk#L2045
 regparse.$(OBJEXT): {$(VPATH)}regint.h
 regparse.$(OBJEXT): {$(VPATH)}regparse.c
 regparse.$(OBJEXT): {$(VPATH)}regparse.h
-regparse.$(OBJEXT): {$(VPATH)}ruby_atomic.h
 regparse.$(OBJEXT): {$(VPATH)}st.h
 regparse.$(OBJEXT): {$(VPATH)}subst.h
 regsyntax.$(OBJEXT): $(hdrdir)/ruby/ruby.h
@@ -2063,7 +2056,6 @@ regsyntax.$(OBJEXT): {$(VPATH)}oniguruma https://github.com/ruby/ruby/blob/trunk/common.mk#L2056
 regsyntax.$(OBJEXT): {$(VPATH)}regenc.h
 regsyntax.$(OBJEXT): {$(VPATH)}regint.h
 regsyntax.$(OBJEXT): {$(VPATH)}regsyntax.c
-regsyntax.$(OBJEXT): {$(VPATH)}ruby_atomic.h
 regsyntax.$(OBJEXT): {$(VPATH)}st.h
 regsyntax.$(OBJEXT): {$(VPATH)}subst.h
 ruby.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h
Index: regint.h
===================================================================
--- regint.h	(revision 52996)
+++ regint.h	(revision 52997)
@@ -95,7 +95,6 @@ https://github.com/ruby/ruby/blob/trunk/regint.h#L95
 
 #ifndef RUBY_DEFINES_H
 #include "ruby/ruby.h"
-#include "ruby_atomic.h"
 #undef xmalloc
 #undef xrealloc
 #undef xcalloc
@@ -239,10 +238,6 @@ extern pthread_mutex_t gOnigMutex; https://github.com/ruby/ruby/blob/trunk/regint.h#L238
 #define ONIG_STATE_INC(reg) (reg)->state++
 #define ONIG_STATE_DEC(reg) (reg)->state--
 
-#if SIZEOF_ATOMIC_T == SIZEOF_INT
-#define ONIG_STATE_INC_THREAD(reg) (ATOMIC_INC((reg)->state))
-#define ONIG_STATE_DEC_THREAD(reg) (ATOMIC_DEC((reg)->state))
-#else
 #define ONIG_STATE_INC_THREAD(reg) do {\
   THREAD_ATOMIC_START;\
   (reg)->state++;\
@@ -253,7 +248,6 @@ extern pthread_mutex_t gOnigMutex; https://github.com/ruby/ruby/blob/trunk/regint.h#L248
   (reg)->state--;\
   THREAD_ATOMIC_END;\
 } while(0)
-#endif
 #else
 #define ONIG_STATE_INC(reg)         /* Nothing */
 #define ONIG_STATE_DEC(reg)         /* Nothing */

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

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