Author: Armin Rigo <[email protected]>
Branch:
Changeset: r1617:6d9efeaf307b
Date: 2015-02-13 16:06 +0100
http://bitbucket.org/pypy/stmgc/changeset/6d9efeaf307b/
Log: Officialize the hack done by hashtable.c to invent "pre-existing"
objects.
diff --git a/c7/stm/gcpage.c b/c7/stm/gcpage.c
--- a/c7/stm/gcpage.c
+++ b/c7/stm/gcpage.c
@@ -127,6 +127,27 @@
return o;
}
+object_t *stm_allocate_preexisting(ssize_t size_rounded_up,
+ struct object_s *initial_data)
+{
+ initial_data->stm_flags = GCFLAG_WRITE_BARRIER;
+
+ acquire_privatization_lock();
+
+ char *p = allocate_outside_nursery_large(size_rounded_up);
+ uintptr_t nobj = p - stm_object_pages;
+ long j;
+ for (j = 0; j <= NB_SEGMENTS; j++) {
+ char *dest = get_segment_base(j) + nobj;
+ memcpy(dest, initial_data, size_rounded_up);
+ }
+
+ release_privatization_lock();
+
+ write_fence(); /* make sure 'nobj' is fully initialized from
+ all threads here */
+ return (object_t *)nobj;
+}
/************************************************************/
diff --git a/c7/stm/hashtable.c b/c7/stm/hashtable.c
--- a/c7/stm/hashtable.c
+++ b/c7/stm/hashtable.c
@@ -297,25 +297,16 @@
synchronization with other pieces of the code that may
change.
*/
- acquire_privatization_lock();
- 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;
- 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;
- }
+ struct stm_hashtable_entry_s initial = {
+ .userdata = stm_hashtable_entry_userdata,
+ .index = index,
+ .object = NULL
+ };
+ entry = (stm_hashtable_entry_t *)
+ stm_allocate_preexisting(sizeof(stm_hashtable_entry_t),
+ &initial.header);
hashtable->additions += 0x100;
- release_privatization_lock();
}
- write_fence(); /* make sure 'entry' is fully initialized here */
table->items[i] = entry;
write_fence(); /* make sure 'table->items' is written here */
VOLATILE_TABLE(table)->resize_counter = rc - 6; /* unlock */
diff --git a/c7/stmgc.h b/c7/stmgc.h
--- a/c7/stmgc.h
+++ b/c7/stmgc.h
@@ -562,6 +562,16 @@
object_t *object;
};
+/* Make an object "that always existed". Can be used for cases where
+ the object pointer could also be seen by other running transactions
+ even if the current one did not commit yet (by means outside the
+ normal scope of stmgc). Must provide the initial content of the
+ object seen in all threads; afterwards, the running transaction can
+ use stm_write() and make local changes.
+*/
+object_t *stm_allocate_preexisting(ssize_t size_rounded_up,
+ struct object_s *initial_data);
+
/* ==================== END ==================== */
#endif
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit