[pypy-commit] pypy stm: Allow (and ignore) nested descriptor_init()s.
arigo
noreply at buildbot.pypy.org
Fri Sep 30 22:42:35 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r47730:95f9547d2668
Date: 2011-09-27 22:30 +0200
http://bitbucket.org/pypy/pypy/changeset/95f9547d2668/
Log: Allow (and ignore) nested descriptor_init()s.
diff --git a/pypy/translator/stm/src_stm/et.c b/pypy/translator/stm/src_stm/et.c
--- a/pypy/translator/stm/src_stm/et.c
+++ b/pypy/translator/stm/src_stm/et.c
@@ -72,13 +72,14 @@
#endif
unsigned int spinloop_counter;
owner_version_t my_lock_word;
+ unsigned init_counter;
struct RedoLog redolog; /* last item, because it's the biggest one */
};
/* global_timestamp contains in its lowest bit a flag equal to 1
if there is an inevitable transaction running */
static volatile unsigned long global_timestamp = 2;
-static __thread struct tx_descriptor *thread_descriptor;
+static __thread struct tx_descriptor *thread_descriptor = NULL;
#ifdef COMMIT_OTHER_INEV
static struct tx_descriptor *volatile thread_descriptor_inev;
static volatile unsigned long d_inev_checking = 0;
@@ -526,22 +527,32 @@
void stm_descriptor_init(void)
{
- struct tx_descriptor *d = malloc(sizeof(struct tx_descriptor));
- memset(d, 0, sizeof(struct tx_descriptor));
+ if (thread_descriptor != NULL)
+ thread_descriptor->init_counter++;
+ else
+ {
+ struct tx_descriptor *d = malloc(sizeof(struct tx_descriptor));
+ memset(d, 0, sizeof(struct tx_descriptor));
- /* initialize 'my_lock_word' to be a unique negative number */
- d->my_lock_word = (owner_version_t)d;
- if (!IS_LOCKED(d->my_lock_word))
- d->my_lock_word = ~d->my_lock_word;
- assert(IS_LOCKED(d->my_lock_word));
- d->spinloop_counter = (unsigned int)(d->my_lock_word | 1);
+ /* initialize 'my_lock_word' to be a unique negative number */
+ d->my_lock_word = (owner_version_t)d;
+ if (!IS_LOCKED(d->my_lock_word))
+ d->my_lock_word = ~d->my_lock_word;
+ assert(IS_LOCKED(d->my_lock_word));
+ d->spinloop_counter = (unsigned int)(d->my_lock_word | 1);
+ d->init_counter = 1;
- thread_descriptor = d;
+ thread_descriptor = d;
+ }
}
void stm_descriptor_done(void)
{
struct tx_descriptor *d = thread_descriptor;
+ d->init_counter--;
+ if (d->init_counter > 0)
+ return;
+
thread_descriptor = NULL;
int num_aborts = 0, num_spinloops = 0;
More information about the pypy-commit
mailing list