[pypy-commit] stmgc c7-refactor: Fix things until test_commit_fresh_objects3 fails, as it was supposed to.
arigo
noreply at buildbot.pypy.org
Mon Feb 17 16:50:50 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch: c7-refactor
Changeset: r760:2e2461812c80
Date: 2014-02-17 16:50 +0100
http://bitbucket.org/pypy/stmgc/changeset/2e2461812c80/
Log: Fix things until test_commit_fresh_objects3 fails, as it was
supposed to.
diff --git a/c7/stm/setup.c b/c7/stm/setup.c
--- a/c7/stm/setup.c
+++ b/c7/stm/setup.c
@@ -110,16 +110,25 @@
void stm_register_thread_local(stm_thread_local_t *tl)
{
+ int num;
if (stm_thread_locals == NULL) {
stm_thread_locals = tl->next = tl->prev = tl;
+ num = 0;
}
else {
tl->next = stm_thread_locals;
tl->prev = stm_thread_locals->prev;
stm_thread_locals->prev->next = tl;
stm_thread_locals->prev = tl;
+ num = tl->prev->associated_segment_num + 1;
}
- tl->associated_segment_num = NB_SEGMENTS;
+
+ /* assign numbers consecutively, but that's for tests; we could also
+ assign the same number to all of them and they would get their own
+ numbers automatically. */
+ num = num % NB_SEGMENTS;
+ tl->associated_segment_num = num;
+ set_gs_register(get_segment_base(num));
}
void stm_unregister_thread_local(stm_thread_local_t *tl)
diff --git a/c7/stm/sync.c b/c7/stm/sync.c
--- a/c7/stm/sync.c
+++ b/c7/stm/sync.c
@@ -22,7 +22,7 @@
pthread_mutex_t global_mutex;
pthread_cond_t global_cond;
/* some additional pieces of global state follow */
- uint8_t in_use[NB_SEGMENTS + 1]; /* 1 if running a pthread */
+ uint8_t in_use[NB_SEGMENTS]; /* 1 if running a pthread */
uint64_t global_time;
};
char reserved[128];
@@ -36,7 +36,6 @@
perror("mutex/cond initialization");
abort();
}
- sync_ctl.in_use[NB_SEGMENTS] = 0xff;
}
static void teardown_sync(void)
@@ -118,6 +117,11 @@
if (sync_ctl.in_use[num] == 0) {
/* fast-path: we can get the same segment number than the one
we had before. The value stored in GS is still valid. */
+#ifdef STM_TESTS
+ /* that can be optimized away, except during tests, because
+ they use only one thread */
+ set_gs_register(get_segment_base(num));
+#endif
goto got_num;
}
/* Look for the next free segment. If there is none, wait for
@@ -138,6 +142,7 @@
got_num:
sync_ctl.in_use[num] = 1;
+ assert(STM_SEGMENT->segment_num == num);
assert(STM_SEGMENT->running_thread == NULL);
STM_SEGMENT->running_thread = tl;
STM_PSEGMENT->start_time = ++sync_ctl.global_time;
@@ -162,10 +167,8 @@
bool _stm_in_transaction(stm_thread_local_t *tl)
{
int num = tl->associated_segment_num;
- if (num < NB_SEGMENTS)
- return get_segment(num)->running_thread == tl;
- else
- return false;
+ assert(num < NB_SEGMENTS);
+ return get_segment(num)->running_thread == tl;
}
void _stm_test_switch(stm_thread_local_t *tl)
diff --git a/c7/test/test_basic.py b/c7/test/test_basic.py
--- a/c7/test/test_basic.py
+++ b/c7/test/test_basic.py
@@ -110,7 +110,8 @@
self.start_transaction()
stm_write(lp) # privatize page
p2 = stm_get_real_address(lp)
- assert p1 == p2 # no collection occurred
+ assert p1 != p2 # we see the other segment, but same object
+ assert (p2 - p1) % 4096 == 0
assert stm_get_char(lp) == 'u'
self.commit_transaction()
@@ -151,12 +152,13 @@
assert stm_get_char(lp2) == 'y'
self.commit_transaction()
- def test_commit_fresh_object3(self):
+ def test_commit_fresh_objects3(self):
# make objects lpx; then privatize the page by committing changes
# to it; then create lpy in the same page. Check that lpy is
# visible from the other thread.
self.start_transaction()
lpx = stm_allocate(16)
+ print lpx
stm_set_char(lpx, '.')
self.commit_transaction()
@@ -166,7 +168,9 @@
self.start_transaction()
lpy = stm_allocate(16)
+ print lpy
stm_set_char(lpy, 'y')
+ print "LAST COMMIT"
self.commit_transaction()
self.switch(1)
More information about the pypy-commit
mailing list