[pypy-commit] pypy stm: (bivab, romain, arigo)
arigo
noreply at buildbot.pypy.org
Fri Jan 20 14:25:07 CET 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r51520:3b0b849eed24
Date: 2012-01-20 14:24 +0100
http://bitbucket.org/pypy/pypy/changeset/3b0b849eed24/
Log: (bivab, romain, arigo)
Found out that a "volatile struct { int x; }" is not the same thing
as a "struct { volatile int x; }". In fact the "volatile" in the
first example seems to have no effect. Bah. Fixed by removing the
struct completely, as nowadays it contains only one field.
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
@@ -34,9 +34,7 @@
(((unsigned long)(num)) > ((unsigned long)(max_age)))
typedef long owner_version_t;
-typedef struct {
- owner_version_t v; // the current version number
-} orec_t;
+typedef volatile owner_version_t orec_t;
/*** Specify the number of orecs in the global array. */
#define NUM_STRIPES 1048576
@@ -45,14 +43,14 @@
static char orecs[NUM_STRIPES * sizeof(orec_t)];
/*** map addresses to orec table entries */
-inline static volatile orec_t* get_orec(void* addr)
+inline static orec_t *get_orec(void* addr)
{
unsigned long index = (unsigned long)addr;
#ifdef RPY_STM_ASSERT
assert(!(index & (sizeof(orec_t)-1)));
#endif
char *p = orecs + (index & ((NUM_STRIPES-1) * sizeof(orec_t)));
- return (volatile orec_t *)p;
+ return (orec_t *)p;
}
#include "src_stm/lists.c"
@@ -158,9 +156,9 @@
appears in the redolog list. If it's not, then p == -1. */
if (item->p != -1)
{
- volatile orec_t* o = get_orec(item->addr);
+ orec_t* o = get_orec(item->addr);
CFENCE;
- o->v = newver;
+ *o = newver;
}
} REDOLOG_LOOP_END;
}
@@ -173,8 +171,8 @@
{
if (item->p != -1)
{
- volatile orec_t* o = get_orec(item->addr);
- o->v = item->p;
+ orec_t* o = get_orec(item->addr);
+ *o = item->p;
}
} REDOLOG_LOOP_END;
}
@@ -187,8 +185,8 @@
{
if (item->p != -1)
{
- volatile orec_t* o = get_orec(item->addr);
- o->v = item->p;
+ orec_t* o = get_orec(item->addr);
+ *o = item->p;
item->p = -1;
}
} REDOLOG_LOOP_END;
@@ -202,11 +200,11 @@
REDOLOG_LOOP_BACKWARD(d->redolog, item)
{
// get orec, read its version#
- volatile orec_t* o = get_orec(item->addr);
+ orec_t* o = get_orec(item->addr);
owner_version_t ovt;
retry:
- ovt = o->v;
+ ovt = *o;
// if orec not locked, lock it
//
@@ -214,7 +212,7 @@
// reads. Since most writes are also reads, we'll just abort under this
// condition. This can introduce false conflicts
if (!IS_LOCKED_OR_NEWER(ovt, d->start_time)) {
- if (!bool_cas(&o->v, ovt, d->my_lock_word))
+ if (!bool_cas(o, ovt, d->my_lock_word))
goto retry;
// save old version to item->p. Now we hold the lock.
// in case of duplicate orecs, only the last one has p != -1.
@@ -291,7 +289,7 @@
for (i=0; i<d->reads.size; i++)
{
retry:
- ovt = d->reads.items[i]->v;
+ ovt = *(d->reads.items[i]);
if (IS_LOCKED_OR_NEWER(ovt, d->start_time))
{
// If locked, we wait until it becomes unlocked. The chances are
@@ -321,7 +319,7 @@
assert(!is_inevitable(d));
for (i=0; i<d->reads.size; i++)
{
- ovt = d->reads.items[i]->v; // read this orec
+ ovt = *(d->reads.items[i]); // read this orec
if (IS_LOCKED_OR_NEWER(ovt, d->start_time))
{
if (!IS_LOCKED(ovt))
@@ -433,12 +431,12 @@
not_found:;
// get the orec addr
- volatile orec_t* o = get_orec((void*)addr);
+ orec_t* o = get_orec((void*)addr);
owner_version_t ovt;
retry:
// read the orec BEFORE we read anything else
- ovt = o->v;
+ ovt = *o;
CFENCE;
// this tx doesn't hold any locks, so if the lock for this addr is held,
@@ -461,10 +459,10 @@
// postvalidate AFTER reading addr:
CFENCE;
- if (o->v != ovt)
+ if (*o != ovt)
goto retry; /* oups, try again */
- oreclist_insert(&d->reads, (orec_t*)o);
+ oreclist_insert(&d->reads, o);
return tmp;
}
More information about the pypy-commit
mailing list