зеркало из https://github.com/github/ruby.git
use atomic operations
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
e48adae2b3
Коммит
0599d7de58
|
@ -1,3 +1,12 @@
|
|||
Wed Dec 9 15:48:12 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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@atdot.net>
|
||||
|
||||
* gc.c (gc_mark_stacked_objects): fix typo.
|
||||
|
|
|
@ -1345,6 +1345,7 @@ enc/unicode.$(OBJEXT): {$(VPATH)}missing.h
|
|||
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
|
||||
|
@ -1987,6 +1988,7 @@ re.$(OBJEXT): {$(VPATH)}re.h
|
|||
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
|
||||
|
@ -1999,6 +2001,7 @@ regcomp.$(OBJEXT): {$(VPATH)}oniguruma.h
|
|||
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
|
||||
|
@ -2011,6 +2014,7 @@ regenc.$(OBJEXT): {$(VPATH)}oniguruma.h
|
|||
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
|
||||
|
@ -2022,6 +2026,7 @@ regerror.$(OBJEXT): {$(VPATH)}oniguruma.h
|
|||
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
|
||||
|
@ -2033,6 +2038,7 @@ regexec.$(OBJEXT): {$(VPATH)}oniguruma.h
|
|||
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
|
||||
|
@ -2045,6 +2051,7 @@ regparse.$(OBJEXT): {$(VPATH)}regenc.h
|
|||
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
|
||||
|
@ -2056,6 +2063,7 @@ regsyntax.$(OBJEXT): {$(VPATH)}oniguruma.h
|
|||
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
|
||||
|
|
|
@ -5663,10 +5663,11 @@ onig_transfer(regex_t* to, regex_t* from)
|
|||
extern void
|
||||
onig_chain_link_add(regex_t* to, regex_t* add)
|
||||
{
|
||||
THREAD_ATOMIC_START;
|
||||
REGEX_CHAIN_HEAD(to);
|
||||
to->chain = add;
|
||||
THREAD_ATOMIC_END;
|
||||
/* THREAD_ATOMIC_START; */
|
||||
do {
|
||||
REGEX_CHAIN_HEAD(to);
|
||||
} while (IS_NOT_NULL(ATOMIC_PTR_CAS(to->chain, (regex_t* )NULL, add)));
|
||||
/* THREAD_ATOMIC_END; */
|
||||
}
|
||||
|
||||
extern void
|
||||
|
|
6
regint.h
6
regint.h
|
@ -95,6 +95,7 @@
|
|||
|
||||
#ifndef RUBY_DEFINES_H
|
||||
#include "ruby/ruby.h"
|
||||
#include "ruby_atomic.h"
|
||||
#undef xmalloc
|
||||
#undef xrealloc
|
||||
#undef xcalloc
|
||||
|
@ -238,6 +239,10 @@ extern pthread_mutex_t gOnigMutex;
|
|||
#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++;\
|
||||
|
@ -248,6 +253,7 @@ extern pthread_mutex_t gOnigMutex;
|
|||
(reg)->state--;\
|
||||
THREAD_ATOMIC_END;\
|
||||
} while(0)
|
||||
#endif
|
||||
#else
|
||||
#define ONIG_STATE_INC(reg) /* Nothing */
|
||||
#define ONIG_STATE_DEC(reg) /* Nothing */
|
||||
|
|
93
regparse.c
93
regparse.c
|
@ -1031,8 +1031,44 @@ 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)
|
||||
{
|
||||
|
@ -1053,18 +1089,7 @@ onig_node_free(Node* node)
|
|||
{
|
||||
Node* next_node = NCDR(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_recycle(node);
|
||||
node = next_node;
|
||||
goto start;
|
||||
}
|
||||
|
@ -1101,32 +1126,15 @@ onig_node_free(Node* node)
|
|||
break;
|
||||
}
|
||||
|
||||
#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_recycle(node);
|
||||
}
|
||||
|
||||
#ifdef USE_PARSE_TREE_NODE_RECYCLE
|
||||
extern int
|
||||
onig_free_node_list(void)
|
||||
{
|
||||
FreeNode* n;
|
||||
|
||||
/* THREAD_ATOMIC_START; */
|
||||
while (IS_NOT_NULL(FreeNodeList)) {
|
||||
n = FreeNodeList;
|
||||
FreeNodeList = FreeNodeList->next;
|
||||
xfree(n);
|
||||
}
|
||||
PopFreeNode(n, xfree(n));
|
||||
/* THREAD_ATOMIC_END; */
|
||||
return 0;
|
||||
}
|
||||
|
@ -1138,14 +1146,9 @@ node_new(void)
|
|||
Node* node;
|
||||
|
||||
#ifdef USE_PARSE_TREE_NODE_RECYCLE
|
||||
THREAD_ATOMIC_START;
|
||||
if (IS_NOT_NULL(FreeNodeList)) {
|
||||
node = (Node* )FreeNodeList;
|
||||
FreeNodeList = FreeNodeList->next;
|
||||
THREAD_ATOMIC_END;
|
||||
return node;
|
||||
}
|
||||
THREAD_ATOMIC_END;
|
||||
/* THREAD_ATOMIC_START; */
|
||||
PopFreeNode(n, return (Node* )n);
|
||||
/* THREAD_ATOMIC_END; */
|
||||
#endif
|
||||
|
||||
node = (Node* )xmalloc(sizeof(Node));
|
||||
|
@ -1155,17 +1158,14 @@ node_new(void)
|
|||
|
||||
#if defined(USE_MULTI_THREAD_SYSTEM) && \
|
||||
defined(USE_SHARED_CCLASS_TABLE) && \
|
||||
defined(USE_PARSE_TREE_NODE_RECYCLE)
|
||||
defined(USE_PARSE_TREE_NODE_RECYCLE) && \
|
||||
0
|
||||
static Node*
|
||||
node_new_locked(void)
|
||||
{
|
||||
Node* node;
|
||||
|
||||
if (IS_NOT_NULL(FreeNodeList)) {
|
||||
node = (Node* )FreeNodeList;
|
||||
FreeNodeList = FreeNodeList->next;
|
||||
return node;
|
||||
}
|
||||
PopFreeNode(n, return (Node* )n);
|
||||
|
||||
node = (Node* )xmalloc(sizeof(Node));
|
||||
/* xmemset(node, 0, sizeof(Node)); */
|
||||
|
@ -1195,7 +1195,8 @@ node_new_cclass(void)
|
|||
|
||||
#if defined(USE_MULTI_THREAD_SYSTEM) && \
|
||||
defined(USE_SHARED_CCLASS_TABLE) && \
|
||||
defined(USE_PARSE_TREE_NODE_RECYCLE)
|
||||
defined(USE_PARSE_TREE_NODE_RECYCLE) && \
|
||||
0
|
||||
static Node*
|
||||
node_new_cclass_locked(void)
|
||||
{
|
||||
|
|
|
@ -42,6 +42,7 @@ typedef unsigned int rb_atomic_t; /* Anything OK */
|
|||
#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))
|
||||
|
@ -143,6 +144,10 @@ ruby_atomic_size_exchange(size_t *ptr, size_t val)
|
|||
}
|
||||
#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
|
||||
|
|
Загрузка…
Ссылка в новой задаче