Commits

Armin Rigo  committed 5a97f72

"extra threshold" support in stmgc.

  • Participants
  • Parent commits a038aa8
  • Branches stm-thread-2

Comments (0)

Files changed (2)

File pypy/rpython/memory/gc/stmgc.py

         from pypy.rpython.memory.gc import stmshared
         self.stm_operations = stm_operations
         self.nursery_size = nursery_size
+        self.maximum_extra_threshold = 0
         self.sharedarea = stmshared.StmGCSharedArea(self)
         #
         def _stm_duplicate(obj):     # indirection to hide 'self'
         return localobj
 
     # ----------
+    # set_extra_threshold support
+
+    def set_extra_threshold(self, reserved_size):
+        if reserved_size > self.maximum_extra_threshold:
+            self.maximum_extra_threshold = reserved_size
+        stmtls = self.get_tls()
+        stmtls.set_extra_threshold(reserved_size)
+
+    # ----------
     # id() and identityhash() support
 
     def id(self, gcobj):

File pypy/rpython/memory/gc/stmtls.py

         #     never changes.
         self.nursery_size  = self.gc.nursery_size
         self.nursery_start = self._alloc_nursery(self.nursery_size)
+        self.extra_threshold = 0
+        self.set_extra_threshold(self.gc.maximum_extra_threshold)
         #
         # --- a thread-local allocator for the shared area
         from pypy.rpython.memory.gc.stmshared import StmGCThreadLocalAllocator
         self.nursery_free = NULL
         self.nursery_top  = NULL
 
+    # ----------
+    # set_extra_threshold support
+
+    def set_extra_threshold(self, reserved_size):
+        ll_assert(self.nursery_free != NULL,
+                  "set_extra_threshold: not in a transaction")
+        diff = reserved_size - self.extra_threshold
+        if diff > 0 and self.nursery_free + diff > self.nursery_top:
+            self.local_collection()
+        self.nursery_size -= diff
+        self.nursery_top -= diff
+        self.extra_threshold += diff
+
     # ------------------------------------------------------------
 
     def start_transaction(self):