Commits

Armin Rigo  committed 9b9cc68

Refactor the Du_AME_READ macro to insist on the fact that we should
only have actual reads in the middle.

  • Participants
  • Parent commits e3b9ec2

Comments (0)

Files changed (3)

File containerobject.c

     DuObject *result;
     DuContainer_Ensure("DuContainer_GetRef", ob);
 
-    Du_AME_READ_START(ob)
-    result = ((DuContainerObject *)ob)->ob_reference;
-    Du_AME_READ_STOP
+    Du_AME_READ(ob, (result = ((DuContainerObject *)ob)->ob_reference));
 
     Du_INCREF(result);
     return result;

File listobject.c

 int list_length(DuListObject *ob)
 {
     int length;
-    Du_AME_READ_START(ob)
-    length = ob->ob_count;
-    Du_AME_READ_STOP
+    Du_AME_READ(ob, (length = ob->ob_count));
     return length;
 }
 
 DuObject *_list_getitem(DuListObject *ob, int index)
 {
     DuObject *result;
-
-    Du_AME_READ_START(ob)
-    if (index < 0 || index >= ob->ob_count)
+    int length;
+    DuObject **items;
+    Du_AME_READ(ob, (length = ob->ob_count, items = ob->ob_items));
+    if (index < 0 || index >= length)
         Du_FatalError("list_get: index out of range");
-    result = ob->ob_items[index];
-    Du_AME_READ_STOP
-
+    result = items[index];
     Du_INCREF(result);
     return result;
 }
 void Du_AME_TryInevitable(void);
 
 
-#define Du_AME_READ_START(ob)                                           \
-while (1) {                                                             \
-    DuObject *__du_ame_ob = (DuObject *)(ob);                           \
-    owner_version_t __du_ame_version;                                   \
-    if (Du_AME_GLOBAL(__du_ame_ob)) {                                   \
-        __du_ame_ob = _Du_AME_read_from_global(__du_ame_ob,             \
-                                                &__du_ame_version);     \
-        (ob) = (typeof(ob))__du_ame_ob;                                 \
-        CFENCE;                                                         \
+#define Du_AME_READ(ob, READ_OPERATIONS)                                \
+    while (1) {                                                         \
+        DuObject *__du_ame_ob = (DuObject *)(ob);                       \
+        if (Du_AME_GLOBAL(__du_ame_ob)) {                               \
+            owner_version_t __du_ame_version;                           \
+            __du_ame_ob = _Du_AME_read_from_global(__du_ame_ob,         \
+                                                   &__du_ame_version);  \
+            (ob) = (typeof(ob))__du_ame_ob;                             \
+            if (Du_AME_GLOBAL(__du_ame_ob)) {                           \
+                CFENCE;                                                 \
+                READ_OPERATIONS;                                        \
+                CFENCE;                                                 \
+                __du_ame_ob = (DuObject *)(ob);                         \
+                if (__du_ame_ob->ob_version != __du_ame_version)        \
+                    continue;                                           \
+                _Du_AME_oreclist_insert(__du_ame_ob);                   \
+                break;                                                  \
+            }                                                           \
+        }                                                               \
+        READ_OPERATIONS;                                                \
+        break;                                                          \
     }
 
-#define Du_AME_READ_STOP                                                \
-    __du_ame_ob = (DuObject *)(ob);                                     \
-    if (Du_AME_GLOBAL(__du_ame_ob)) {                                   \
-        CFENCE;                                                         \
-        if (__du_ame_ob->ob_version != __du_ame_version)                \
-            continue;                                                   \
-        _Du_AME_oreclist_insert(__du_ame_ob);                           \
-    }                                                                   \
-    break;                                                              \
-}
-
 
 #define Du_AME_WRITE(ob)                                                \
     do {                                                                \