Author: Armin Rigo <[email protected]>
Branch: hashtable
Changeset: r1481:34dc63f8a1d1
Date: 2014-10-18 17:47 +0200
http://bitbucket.org/pypy/stmgc/changeset/34dc63f8a1d1/
Log: test and fix
diff --git a/c7/stm/hashtable.c b/c7/stm/hashtable.c
--- a/c7/stm/hashtable.c
+++ b/c7/stm/hashtable.c
@@ -220,11 +220,19 @@
item in the current table.
*/
if (rc > 6) {
- entry = (stm_hashtable_entry_t *)
- _stm_allocate_old(sizeof(stm_hashtable_entry_t));
- entry->userdata = stm_hashtable_entry_userdata;
- entry->index = index;
- entry->object = NULL;
+ char *p =
allocate_outside_nursery_large(sizeof(stm_hashtable_entry_t));
+ entry = (stm_hashtable_entry_t *)(p - stm_object_pages);
+
+ long j;
+ for (j = 0; j <= NB_SEGMENTS; j++) {
+ struct stm_hashtable_entry_s *e = (struct stm_hashtable_entry_s *)
+ REAL_ADDRESS(get_segment_base(j), entry);
+ e->header.stm_flags = GCFLAG_WRITE_BARRIER;
+ e->userdata = stm_hashtable_entry_userdata;
+ e->index = index;
+ e->object = NULL;
+ }
+
write_fence(); /* make sure 'entry' is fully initialized here */
table->items[i] = entry;
write_fence(); /* make sure 'table->items' is written here */
diff --git a/c7/test/test_hashtable.py b/c7/test/test_hashtable.py
--- a/c7/test/test_hashtable.py
+++ b/c7/test/test_hashtable.py
@@ -24,3 +24,31 @@
assert lib.stm_hashtable_read(h, index) == ffi.NULL
assert lib.stm_hashtable_read(h, 12345678901) == lp1
lib.stm_hashtable_free(h)
+
+ def test_no_conflict(self):
+ h = lib.stm_hashtable_create()
+ lp1 = stm_allocate_old(16)
+ lp2 = stm_allocate_old(16)
+ #
+ self.start_transaction()
+ stm_set_char(lp1, 'A')
+ lib.stm_hashtable_write(h, 1234, lp1)
+ self.commit_transaction()
+ #
+ self.start_transaction()
+ stm_set_char(lp2, 'B')
+ lib.stm_hashtable_write(h, 9991234, lp2)
+ #
+ self.switch(1)
+ self.start_transaction()
+ lp1b = lib.stm_hashtable_read(h, 1234)
+ assert stm_get_char(lp1b) == 'A'
+ assert lp1b == lp1
+ self.commit_transaction()
+ #
+ self.switch(0)
+ assert lib.stm_hashtable_read(h, 9991234) == lp2
+ assert stm_get_char(lp2) == 'B'
+ assert lib.stm_hashtable_read(h, 1234) == lp1
+ lib.stm_hashtable_write(h, 1234, ffi.NULL)
+ self.commit_transaction()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit