summaryrefslogtreecommitdiff
path: root/regparse.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-09 07:30:44 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-09 07:30:44 (GMT)
commitb3377eaa1360a89db3adb655c1412b80ae5bc2e4 (patch)
tree1a3bba51379b3c81dfa382dacf64853f27ab7633 /regparse.c
parent303cd88d408b7f8b79b0580cf3d552d6e291f5df (diff)
Revert r52995
revert slow atomic operations. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'regparse.c')
-rw-r--r--regparse.c93
1 files changed, 46 insertions, 47 deletions
diff --git a/regparse.c b/regparse.c
index 0baf02c..094332f 100644
--- a/regparse.c
+++ b/regparse.c
@@ -1031,43 +1031,7 @@ typedef struct _FreeNode {
} 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)
{
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)
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)
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)
#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)
#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)
{