Commits

Armin Rigo committed 88c8647 Merge

hg merge stm-thread-2

Comments (0)

Files changed (3)

lib_pypy/pypy_test/test_transaction.py

         assert num_foos == 1, lsts
 
 
+def test_number_of_transactions_reported():
+    transaction.add(lambda: None)
+    transaction.run()
+    assert transaction.number_of_transactions_in_last_run() == 1
+
+    def add_transactions(l):
+        if l:
+            for x in range(l[0]):
+                transaction.add(add_transactions, l[1:])
+
+    transaction.add(add_transactions, [10, 10, 10])
+    transaction.run()
+    assert transaction.number_of_transactions_in_last_run() == 1111
+
+
 def run_tests():
     for name in sorted(globals().keys()):
         if name.startswith('test_'):

lib_pypy/transaction.py

         tpool.teardown()
     tpool.reraise()
 
+def number_of_transactions_in_last_run():
+    return _thread_pool.transactions_run
+
 # ____________________________________________________________
 
 
     def __init__(self):
         self.num_threads = 4    # XXX default value, tweak
         self.in_transaction = False
+        self.transactions_run = None
 
     def setup(self):
         # a mutex to protect parts of _grab_next_thing_to_do()
         _thread_local.pending = None
         #
         self.num_waiting_threads = 0
+        self.transactions_run = 0
         self.finished = False
         self.got_exception = []
         self.in_transaction = True
 
     def run(self):
         # start the N threads
-        for i in range(self.num_threads):
-            thread.start_new_thread(self._run_thread, ())
+        task_counters = [[0] for i in range(self.num_threads)]
+        for counter in task_counters:
+            thread.start_new_thread(self._run_thread, (counter,))
         # now wait.  When we manage to acquire the following lock, then
         # we are finished.
         self.lock_if_released_then_finished.acquire()
+        self.transactions_run = sum(x[0] for x in task_counters)
 
     def teardown(self):
         self.in_transaction = False
         if exc:
             raise exc[0], exc[1], exc[2]    # exception, value, traceback
 
-    def _run_thread(self):
+    def _run_thread(self, counter):
         tloc_pending = _thread_local.pending
         got_exception = self.got_exception
         try:
             while True:
                 self._do_it(self._grab_next_thing_to_do(tloc_pending),
                             got_exception)
+                counter[0] += 1
         except _Done:
             pass
 
     header = info[0]
     f = cStringIO.StringIO()
     if len(info) > 1:
-        print >> f, 'Traceback from detected conflict:'
+        print >> f, 'Detected conflict:'
         for tb in info[1:]:
             filename = tb[0]
             coname = tb[1]

rpython/translator/stm/src_stm/et.h

 
 //gcptr Allocate(size_t size, int gctid);
 _Bool stm_PtrEq(gcptr P1, gcptr P2);
-gcptr stm_HashObject(gcptr P);
 
 void *stm_DirectReadBarrier(void *);
 void *stm_DirectReadBarrierFromR(void *, void *, size_t);