Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r304:d91b7aa21484
Date: 2013-06-27 14:59 +0200
http://bitbucket.org/pypy/stmgc/changeset/d91b7aa21484/

Log:    Redo the thread-local object.

diff --git a/c4/et.c b/c4/et.c
--- a/c4/et.c
+++ b/c4/et.c
@@ -1467,6 +1467,8 @@
   return pd;
 }
 
+__thread gcptr stm_thread_local_obj;
+
 int DescriptorInit(void)
 {
   if (GCFLAG_PREBUILT != PREBUILT_FLAGS)
@@ -1517,6 +1519,8 @@
       stm_private_rev_num = -d->my_lock;
       d->private_revision_ref = &stm_private_rev_num;
       d->read_barrier_cache_ref = &stm_read_barrier_cache;
+      stm_thread_local_obj = NULL;
+      d->thread_local_obj_ref = &stm_thread_local_obj;
       d->max_aborts = -1;
       d->tx_prev = NULL;
       d->tx_next = stm_tx_head;
@@ -1563,6 +1567,8 @@
 
     thread_descriptor = NULL;
 
+    stm_thread_local_obj = (gcptr)0xBB;   /* to detect misuses */
+
     g2l_delete(&d->public_to_private);
     assert(d->private_from_protected.size == 0);
     gcptrlist_delete(&d->private_from_protected);
diff --git a/c4/et.h b/c4/et.h
--- a/c4/et.h
+++ b/c4/et.h
@@ -135,6 +135,7 @@
   revision_t my_lock;
   gcptr *shadowstack;
   gcptr **shadowstack_end_ref;
+  gcptr *thread_local_obj_ref;
 
   NURSERY_FIELDS_DECL
 
diff --git a/c4/gcpage.c b/c4/gcpage.c
--- a/c4/gcpage.c
+++ b/c4/gcpage.c
@@ -339,10 +339,8 @@
         /* the roots pushed on the shadowstack */
         mark_roots(d->shadowstack, *d->shadowstack_end_ref);
 
-#if 0
         /* the thread-local object */
         visit(d->thread_local_obj_ref);
-#endif
 
         /* the current transaction's private copies of public objects */
         wlog_t *item;
diff --git a/c4/nursery.c b/c4/nursery.c
--- a/c4/nursery.c
+++ b/c4/nursery.c
@@ -521,6 +521,8 @@
 
     mark_young_roots(d);
 
+    visit_if_young(d->thread_local_obj_ref);
+
     mark_stolen_young_stubs(d);
 
     mark_private_from_protected(d);
diff --git a/c4/test/support.py b/c4/test/support.py
--- a/c4/test/support.py
+++ b/c4/test/support.py
@@ -103,6 +103,7 @@
     revision_t get_private_rev_num(void);
     revision_t get_start_time(void);
     void *my_stub_thread(void);
+    gcptr *addr_of_thread_local(void);
 
     int _stm_can_access_memory(char *);
     void stm_initialize_and_set_max_abort(int max_aborts);
@@ -245,6 +246,11 @@
         return (void *)thread_descriptor->public_descriptor;
     }
 
+    gcptr *addr_of_thread_local(void)
+    {
+        return &stm_thread_local_obj;
+    }
+
     void stm_initialize_and_set_max_abort(int max_aborts)
     {
         stm_initialize();
diff --git a/c3/test/test_threadlocal.py b/c4/test/test_threadlocal.py
copy from c3/test/test_threadlocal.py
copy to c4/test/test_threadlocal.py
--- a/c3/test/test_threadlocal.py
+++ b/c4/test/test_threadlocal.py
@@ -14,6 +14,18 @@
     lib.addr_of_thread_local()[0] = p
     major_collect()
     check_not_free(p)
+    assert lib.addr_of_thread_local()[0] == p
+
+def test_threadlocal_nursery():
+    p = nalloc(HDR + WORD)
+    lib.rawsetlong(p, 0, 654321)
+    lib.addr_of_thread_local()[0] = p
+    minor_collect()
+    check_nursery_free(p)
+    p1 = lib.addr_of_thread_local()[0]
+    assert p1 != ffi.NULL
+    check_not_free(p1)
+    assert lib.rawgetlong(p1, 0) == 654321
 
 def test_reset():
     p = oalloc(HDR + 1)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to