Commits

Armin Rigo committed 22fb368

The basic test_start_thread works

Comments (0)

Files changed (7)

rpython/rlib/rstm.py

 def after_external_call():
     if we_are_translated():
         # starts a new transaction if we are not atomic already
-        llop.stm_begin_inevitable_transaction(lltype.Void)
+        llop.stm_start_inevitable_transaction(lltype.Void)
 after_external_call._dont_reach_me_in_del_ = True
 after_external_call._transaction_break_ = True
 

rpython/rtyper/lltypesystem/lloperation.py

     'stm_become_inevitable':  LLOp(canmallocgc=True),
     'stm_push_root':          LLOp(),
     'stm_pop_root_into':      LLOp(),
+    'stm_commit_transaction': LLOp(canmallocgc=True),
+    'stm_start_inevitable_transaction': LLOp(canmallocgc=True),
+    'stm_enter_callback_call':LLOp(canmallocgc=True),
+    'stm_leave_callback_call':LLOp(),
 
 ##    'stm_allocate_nonmovable_int_adr': LLOp(sideeffects=False, canmallocgc=True),
 ##    'stm_become_inevitable':  LLOp(canmallocgc=True),
 ##    'stm_major_collect':      LLOp(canmallocgc=True),
 ##    'stm_get_tid':            LLOp(canfold=True),
 ##    'stm_ptr_eq':             LLOp(canfold=True),
-##    'stm_id':                 LLOp(sideeffects=False),
-##    'stm_hash':               LLOp(sideeffects=False),
-##    'stm_commit_transaction': LLOp(canmallocgc=True),
-##    'stm_begin_inevitable_transaction': LLOp(canmallocgc=True),
 ##    'stm_should_break_transaction': LLOp(sideeffects=False),
 ##    'stm_set_transaction_length': LLOp(canmallocgc=True),
 ##    'stm_change_atomic':      LLOp(),
 ##    'stm_get_atomic':         LLOp(sideeffects=False),
 ##    'stm_perform_transaction':LLOp(canmallocgc=True),
-##    'stm_enter_callback_call':LLOp(canmallocgc=True),
-##    'stm_leave_callback_call':LLOp(canmallocgc=True),
 ##    'stm_abort_and_retry':    LLOp(canmallocgc=True),
 
 ##    'stm_weakref_allocate':   LLOp(sideeffects=False, canmallocgc=True),

rpython/translator/c/genc.py

         *pp = stm_setup_prebuilt(*pp);
         stm_set_prebuilt_identityhash(*pp, *ph);
     }
-    stm_commit_transaction();
 }
 '''
 

rpython/translator/stm/funcgen.py

         return '/* %s = */ STM_POP_ROOT_RET(stm_thread_local);' % (arg0,)
     return 'STM_POP_ROOT(stm_thread_local, %s);' % (arg0,)
 
+def stm_commit_transaction(funcgen, op):
+   return '{ int e = errno; stm_commit_transaction(); errno = e; }'
+
+def stm_start_inevitable_transaction(funcgen, op):
+    return ('{ int e = errno; '
+            'stm_start_inevitable_transaction(&stm_thread_local); '
+            'errno = e; }')
+
+def stm_enter_callback_call(funcgen, op):
+    result = funcgen.expr(op.result)
+    return '%s = pypy_stm_enter_callback_call();' % (result,)
+
+def stm_leave_callback_call(funcgen, op):
+    arg0 = funcgen.expr(op.args[0])
+    return 'pypy_stm_leave_callback_call(%s);' % (arg0,)
+
 
 ##def stm_initialize(funcgen, op):
 ##    return '''stm_initialize();
 ##    result = funcgen.expr(op.result)
 ##    return '%s = stm_id((gcptr)%s);' % (result, arg0)
 
-##def stm_commit_transaction(funcgen, op):
-##    return '{ int e = errno; stm_commit_transaction(); errno = e; }'
-
-##def stm_begin_inevitable_transaction(funcgen, op):
-##    return '{ int e = errno; stm_begin_inevitable_transaction(); errno = e; }'
-
 ##def stm_should_break_transaction(funcgen, op):
 ##    result = funcgen.expr(op.result)
 ##    return '%s = stm_should_break_transaction();' % (result,)

rpython/translator/stm/src_stm/stmgcintf.c

 #include "src_stm/stmgc.c"
 
 /************************************************************/
+
+
+long pypy_stm_enter_callback_call(void)
+{
+    long token = 0;
+
+    if (stm_thread_local.shadowstack == NULL) {
+        /* first time we see this thread */
+        token = 1;
+        stm_register_thread_local(&stm_thread_local);
+    }
+    stm_start_inevitable_transaction(&stm_thread_local);
+    return token;
+}
+
+void pypy_stm_leave_callback_call(long token)
+{
+    stm_commit_transaction();
+    if (token == 1) {
+        stm_unregister_thread_local(&stm_thread_local);
+        assert(stm_thread_local.shadowstack == NULL);
+    }
+}

rpython/translator/stm/src_stm/stmgcintf.h

 extern __thread struct stm_thread_local_s stm_thread_local;
 
 void pypy_stm_setup(void);   /* generated into stm_prebuilt.c */
+long pypy_stm_enter_callback_call(void);
+void pypy_stm_leave_callback_call(long);
 
 
 #if 0    /* fprinting versions */

rpython/translator/stm/test/test_ztranslated.py

             rthread.start_new_thread(threadfn, ())
             while glob.seen is None:
                 llop.stm_commit_transaction(lltype.Void)
-                llop.stm_begin_inevitable_transaction(lltype.Void)
+                llop.stm_start_inevitable_transaction(lltype.Void)
             return glob.seen.value
         #
         t, cbuilder = self.compile(entry_point)