Author: Remi Meier <[email protected]>
Branch: c8-private-pages
Changeset: r1548:86a5eee853db
Date: 2015-01-19 16:03 +0100
http://bitbucket.org/pypy/stmgc/changeset/86a5eee853db/

Log:    add thread_local_obj support

diff --git a/c8/stm/core.c b/c8/stm/core.c
--- a/c8/stm/core.c
+++ b/c8/stm/core.c
@@ -650,6 +650,7 @@
     STM_PSEGMENT->running_pthread = pthread_self();
 #endif
     STM_PSEGMENT->shadowstack_at_start_of_transaction = tl->shadowstack;
+    STM_PSEGMENT->threadlocal_at_start_of_transaction = tl->thread_local_obj;
 
     enter_safe_point_if_requested();
     dprintf(("> start_transaction\n"));
@@ -849,6 +850,7 @@
         stm_rewind_jmp_restore_shadowstack(tl);
     assert(tl->shadowstack == pseg->shadowstack_at_start_of_transaction);
 #endif
+    tl->thread_local_obj = pseg->threadlocal_at_start_of_transaction;
     tl->last_abort__bytes_in_nursery = bytes_in_nursery;
 
     list_clear(pseg->objects_pointing_to_nursery);
diff --git a/c8/stm/core.h b/c8/stm/core.h
--- a/c8/stm/core.h
+++ b/c8/stm/core.h
@@ -84,6 +84,7 @@
     struct stm_commit_log_entry_s *last_commit_log_entry;
 
     struct stm_shadowentry_s *shadowstack_at_start_of_transaction;
+    object_t *threadlocal_at_start_of_transaction;
 
     /* For debugging */
 #ifndef NDEBUG
diff --git a/c8/stm/gcpage.c b/c8/stm/gcpage.c
--- a/c8/stm/gcpage.c
+++ b/c8/stm/gcpage.c
@@ -326,6 +326,7 @@
             if ((((uintptr_t)current->ss) & 3) == 0)
                 mark_visit_object(current->ss, stm_object_pages);
         }
+        mark_visit_object(tl->thread_local_obj, stm_object_pages);
 
         tl = tl->next;
     } while (tl != stm_all_thread_locals);
@@ -334,6 +335,9 @@
     long i;
     for (i = 1; i < NB_SEGMENTS; i++) {
         if (get_priv_segment(i)->transaction_state != TS_NONE) {
+            mark_visit_object(
+                get_priv_segment(i)->threadlocal_at_start_of_transaction,
+                stm_object_pages);
             stm_rewind_jmp_enum_shadowstack(
                 get_segment(i)->running_thread,
                 mark_visit_objects_from_ss);
diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c
--- a/c8/stm/nursery.c
+++ b/c8/stm/nursery.c
@@ -156,6 +156,8 @@
             /* it is an odd-valued marker, ignore */
         }
     }
+
+    minor_trace_if_young(&tl->thread_local_obj);
 }
 
 
diff --git a/c8/stm/setup.c b/c8/stm/setup.c
--- a/c8/stm/setup.c
+++ b/c8/stm/setup.c
@@ -210,6 +210,7 @@
         stm_all_thread_locals->prev = tl;
         num = (tl->prev->associated_segment_num) % (NB_SEGMENTS-1);
     }
+    tl->thread_local_obj = NULL;
 
     /* 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
diff --git a/c8/stmgc.h b/c8/stmgc.h
--- a/c8/stmgc.h
+++ b/c8/stmgc.h
@@ -48,6 +48,9 @@
     rewind_jmp_thread rjthread;
     struct stm_shadowentry_s *shadowstack, *shadowstack_base;
 
+    /* a generic optional thread-local object */
+    object_t *thread_local_obj;
+
     char *mem_clear_on_abort;
     size_t mem_bytes_to_clear_on_abort;
     long last_abort__bytes_in_nursery;
diff --git a/c8/test/support.py b/c8/test/support.py
--- a/c8/test/support.py
+++ b/c8/test/support.py
@@ -23,6 +23,7 @@
 typedef struct {
     rewind_jmp_thread rjthread;
     struct stm_shadowentry_s *shadowstack, *shadowstack_base;
+    object_t *thread_local_obj;
     char *mem_clear_on_abort;
     size_t mem_bytes_to_clear_on_abort;
     long last_abort__bytes_in_nursery;
diff --git a/c8/test/test_gcpage.py b/c8/test/test_gcpage.py
--- a/c8/test/test_gcpage.py
+++ b/c8/test/test_gcpage.py
@@ -241,7 +241,6 @@
         self.test_reshare_if_no_longer_modified_0(invert=1)
 
     def test_threadlocal_at_start_of_transaction(self):
-        py.test.skip("no threadlocal right now")
         self.start_transaction()
         x = stm_allocate(16)
         stm_set_char(x, 'L')
@@ -262,6 +261,7 @@
 
         self.start_transaction()
         assert stm_get_char(self.get_thread_local_obj()) == 'L'
+        self.commit_transaction()
 
     def test_marker_1(self):
         self.start_transaction()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to