[pypy-commit] stmgc default: Readd logic for a thread-local object.

arigo noreply at buildbot.pypy.org
Wed Feb 26 23:51:23 CET 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r886:f78b189223c1
Date: 2014-02-26 23:51 +0100
http://bitbucket.org/pypy/stmgc/changeset/f78b189223c1/

Log:	Readd logic for a thread-local object.

	Helps "duhton demo/list_transaction.duh", but it still seems to be
	caught sometimes in infnite loops.

diff --git a/c7/stm/core.c b/c7/stm/core.c
--- a/c7/stm/core.c
+++ b/c7/stm/core.c
@@ -170,6 +170,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;
     STM_SEGMENT->nursery_end = NURSERY_END;
 
     dprintf(("start_transaction\n"));
@@ -469,6 +470,7 @@
     stm_jmpbuf_t *jmpbuf_ptr = STM_SEGMENT->jmpbuf_ptr;
     stm_thread_local_t *tl = STM_SEGMENT->running_thread;
     tl->shadowstack = STM_PSEGMENT->shadowstack_at_start_of_transaction;
+    tl->thread_local_obj = STM_PSEGMENT->threadlocal_at_start_of_transaction;
 
     _finish_transaction();
 
diff --git a/c7/stm/core.h b/c7/stm/core.h
--- a/c7/stm/core.h
+++ b/c7/stm/core.h
@@ -117,8 +117,10 @@
     /* Temp for minor collection */
     bool minor_collect_will_commit_now;
 
-    /* In case of abort, we restore the 'shadowstack' field. */
+    /* In case of abort, we restore the 'shadowstack' field and the
+       'thread_local_obj' field. */
     object_t **shadowstack_at_start_of_transaction;
+    object_t *threadlocal_at_start_of_transaction;
 
     /* For debugging */
 #ifndef NDEBUG
diff --git a/c7/stm/nursery.c b/c7/stm/nursery.c
--- a/c7/stm/nursery.c
+++ b/c7/stm/nursery.c
@@ -145,6 +145,7 @@
         assert(*current != (object_t *)-1);
         minor_trace_if_young(current);
     }
+    minor_trace_if_young(&tl->thread_local_obj);
 }
 
 static inline void _collect_now(object_t *obj)
diff --git a/c7/stm/setup.c b/c7/stm/setup.c
--- a/c7/stm/setup.c
+++ b/c7/stm/setup.c
@@ -133,6 +133,7 @@
         stm_all_thread_locals->prev = tl;
         num = tl->prev->associated_segment_num + 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/c7/stmgc.h b/c7/stmgc.h
--- a/c7/stmgc.h
+++ b/c7/stmgc.h
@@ -52,6 +52,8 @@
 typedef struct stm_thread_local_s {
     /* every thread should handle the shadow stack itself */
     object_t **shadowstack, **shadowstack_base;
+    /* a generic optional thread-local object */
+    object_t *thread_local_obj;
     /* the next fields are handled automatically by the library */
     int associated_segment_num;
     struct stm_thread_local_s *prev, *next;
diff --git a/duhton/duhton.c b/duhton/duhton.c
--- a/duhton/duhton.c
+++ b/duhton/duhton.c
@@ -54,9 +54,9 @@
             Du_Print(res, 1);
         }
 
-        _du_save1(stm_thread_local_obj);
-        stm_collect(0);   /* hack... */
-        _du_restore1(stm_thread_local_obj);
+        //_du_save1(stm_thread_local_obj);
+        //stm_collect(0);   /* hack... */
+        //_du_restore1(stm_thread_local_obj);
 
         stm_commit_transaction();
 
diff --git a/duhton/duhton.h b/duhton/duhton.h
--- a/duhton/duhton.h
+++ b/duhton/duhton.h
@@ -216,5 +216,5 @@
 extern pthread_t *all_threads;
 extern int all_threads_count;
 
-extern __thread DuObject *stm_thread_local_obj;  /* XXX temp */
+//extern __thread DuObject *stm_thread_local_obj;  /* XXX temp */
 #endif  /* _DUHTON_H_ */
diff --git a/duhton/glob.c b/duhton/glob.c
--- a/duhton/glob.c
+++ b/duhton/glob.c
@@ -685,9 +685,9 @@
     if (cons != Du_None)
         Du_FatalError("run-transactions: expected no argument");
 
-    _du_save1(stm_thread_local_obj);
-    stm_collect(0);       /* hack... */
-    _du_restore1(stm_thread_local_obj);
+    //_du_save1(stm_thread_local_obj);
+    //stm_collect(0);       /* hack... */
+    //_du_restore1(stm_thread_local_obj);
 
     stm_commit_transaction();
 
diff --git a/duhton/transaction.c b/duhton/transaction.c
--- a/duhton/transaction.c
+++ b/duhton/transaction.c
@@ -43,35 +43,34 @@
 
 /************************************************************/
 
-__thread DuObject *stm_thread_local_obj = NULL;  /* XXX temp */
-
+#define TLOBJ   (*((DuObject **)(&stm_thread_local.thread_local_obj)))
 
 void Du_TransactionAdd(DuObject *code, DuObject *frame)
 {
     DuObject *cell = DuCons_New(code, frame);
-    DuObject *pending = stm_thread_local_obj;
+    DuObject *pending = TLOBJ;
 
     if (pending == NULL) {
         pending = Du_None;
     }
     pending = DuCons_New(cell, pending);
-    stm_thread_local_obj = pending;
+    TLOBJ = pending;
 }
 
 void Du_TransactionRun(void)
 {
-    if (stm_thread_local_obj == NULL)
+    if (TLOBJ == NULL)
         return;
 
     stm_start_inevitable_transaction(&stm_thread_local);
 
     DuConsObject *root = du_pending_transactions;
     _du_write1(root);
-    root->cdr = stm_thread_local_obj;
+    root->cdr = TLOBJ;
 
     stm_commit_transaction();
 
-    stm_thread_local_obj = NULL;
+    TLOBJ = NULL;
 
     run_all_threads();
 }
@@ -80,7 +79,7 @@
 
 static DuObject *next_cell(void)
 {
-    DuObject *pending = stm_thread_local_obj;
+    DuObject *pending = TLOBJ;
 
     if (pending == NULL) {
         /* fish from the global list of pending transactions */
@@ -131,7 +130,7 @@
     }
 
     /* we have at least one thread-local transaction pending */
-    stm_thread_local_obj = NULL;
+    TLOBJ = NULL;
 
     stm_start_inevitable_transaction(&stm_thread_local);
 
@@ -175,22 +174,18 @@
     stm_jmpbuf_t here;
     stm_register_thread_local(&stm_thread_local);
 
-    stm_thread_local_obj = NULL;
+    TLOBJ = NULL;
 
     while (1) {
         DuObject *cell = next_cell();
         if (cell == NULL)
             break;
-        assert(stm_thread_local_obj == NULL);
+        assert(TLOBJ == NULL);
 
         STM_START_TRANSACTION(&stm_thread_local, here);
 
         run_transaction(cell);
 
-        _du_save1(stm_thread_local_obj);
-        stm_collect(0);   /* hack.. */
-        _du_restore1(stm_thread_local_obj);
-
         stm_commit_transaction();
 
     }


More information about the pypy-commit mailing list