Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r31:fc3ea5414a31
Date: 2013-05-26 20:52 +0200
http://bitbucket.org/pypy/stmgc/changeset/fc3ea5414a31/

Log:    Redo _stm_nonrecord_barrier(), which lets test_random start, at
        least.

diff --git a/c3/et.c b/c3/et.c
--- a/c3/et.c
+++ b/c3/et.c
@@ -171,7 +171,6 @@
   return R;
 }
 
-#if 0
 static gcptr _latest_gcptr(gcptr R)
 {
   /* don't use, for tests only */
@@ -183,40 +182,46 @@
       if (v & 2)
         {
           v &= ~2;
-          if (!is_young((gcptr)v))
-            {
-              stmgc_follow_foreign(R);
-              goto retry;
-            }
+          if (!stmgc_is_young_in(thread_descriptor, (gcptr)v))
+            return NULL;   /* can't access */
         }
       R = (gcptr)v;
       goto retry;
     }
   return R;
 }
-#endif
 
 gcptr _stm_nonrecord_barrier(gcptr obj, int *result)
 {
-  abort();//XXX
-#if 0
   /* warning, this is for tests only, and it is not thread-safe! */
-  if (obj->h_revision == stm_local_revision)
+  enum protection_class_t e = stmgc_classify(obj);
+  if (e == K_PRIVATE)
     {
-      *result = 2;   /* 'obj' a local object to start with */
+      *result = 2;   /* 'obj' a private object to start with */
       return obj;
     }
   obj = _latest_gcptr(obj);
+  if (obj == NULL)
+    {
+      assert(e == K_PUBLIC);
+      *result = 3;   /* can't check anything: we'd need foreign access */
+      return NULL;
+    }
+  if (stmgc_classify(obj) == K_PRIVATE)
+    {
+      *result = 1;
+      return obj;
+    }
 
   struct tx_descriptor *d = thread_descriptor;
   wlog_t *item;
-  G2L_LOOP_FORWARD(d->global_to_local, item)
+  G2L_LOOP_FORWARD(d->public_to_private, item)
     {
       gcptr R = item->addr;
       gcptr L = item->val;
       if (_latest_gcptr(R) == obj)
         {
-          /* 'obj' has a local version.  The way we detect this lets us
+          /* 'obj' has a private version.  The way we detect this lets us
              find it even if we already have a committed version that
              will cause conflict. */
           *result = 1;
@@ -226,17 +231,16 @@
 
   if (obj->h_revision > d->start_time)
     {
-      /* 'obj' has no local version, and the global version was modified */
+      /* 'obj' has no private version, and the public version was modified */
       *result = -1;
       return NULL;
     }
   else
     {
-      /* 'obj' has only an up-to-date global version */
+      /* 'obj' has only an up-to-date public version */
       *result = 0;
       return obj;
     }
-#endif
 }
 
 #if 0
diff --git a/c3/test/test_random.py b/c3/test/test_random.py
--- a/c3/test/test_random.py
+++ b/c3/test/test_random.py
@@ -99,7 +99,7 @@
             self.check(p)
             try:
                 self.current_rev.write(r.obj, index, p.obj)
-                if not self.is_local(r.ptr):
+                if not self.is_private(r.ptr):
                     self.current_rev.check_not_outdated(r.obj)
             except (model.Deleted, model.Conflict):
                 # abort! try to reproduce with C code
@@ -117,7 +117,7 @@
             return emptypair
         try:
             pobj = self.current_rev.read(r.obj, index)
-            if not self.is_local(r.ptr):
+            if not self.is_private(r.ptr):
                 self.current_rev.check_not_outdated(r.obj)
         except (model.Deleted, model.Conflict):
             # abort! try to reproduce with C code
@@ -140,7 +140,7 @@
             self.check(p)
             try:
                 self.current_rev.read_barrier(p.obj)
-                if not self.is_local(p.ptr):
+                if not self.is_private(p.ptr):
                     self.current_rev.check_not_outdated(p.obj)
             except (model.Deleted, model.Conflict):
                 # abort! try to reproduce with C code
@@ -159,7 +159,7 @@
             self.check(p)
             try:
                 self.current_rev.write_barrier(p.obj)
-                if not self.is_local(p.ptr):
+                if not self.is_private(p.ptr):
                     self.current_rev.check_not_outdated(p.obj)
             except (model.Deleted, model.Conflict):
                 # abort! try to reproduce with C code
@@ -195,7 +195,7 @@
         ptr = lib._stm_nonrecord_barrier(ptr, result)
         return ptr, result[0]
 
-    def is_local(self, ptr):
+    def is_private(self, ptr):
         return ptr.h_revision == lib.get_local_revision()
 
     def check_valid(self, lst):
@@ -208,9 +208,11 @@
             self.check(p)
 
             ptr, result = self.nonrecord_barrier(p.ptr)
-            has_local_copy = p.obj in self.current_rev.content
-            assert has_local_copy == (result >= 1)
-            if has_local_copy:
+            if ptr == ffi.NULL and result == 3:
+                continue    # can't check anything: we'd need foreign access
+            has_private_copy = p.obj in self.current_rev.content
+            assert has_private_copy == (result >= 1)
+            if has_private_copy:
                 content = self.current_rev.content[p.obj]
             else:
                 try:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to