Anonymous avatar Anonymous committed 8c6efb9 Draft

sweeping up

Comments (0)

Files changed (1)

 pyamt_image *current_pyamt_image;
 
 void sync_pyamt_image() {
-  printf("about to call image_sync\n");
   image_sync(current_image);
-  printf("did the world explode?\n");
   current_pyamt_image = (pyamt_image *) (current_image->contents);
   current_amt = (amt *) ((void *) current_image->contents + sizeof(pyamt_image));
 }
 }
 
 void switch_to_context(pyamt_context *z) {
-  printf("z->state is %d\n", z->state);
-  printf("z->img.status is %d\n", z->img.status);
-  printf("z->img.fd is %d\n", z->img.mmap_fd);
-  
-
   current_image = &z->img;
   sync_pyamt_image();
 }
 void ensure_valid_root(pyamt_context *z) {
   time_t now = time(0);
 
-  printf("entering the wheel of pain\n");
-
   /* assumption: time_t is expressed in seconds */
   while (z->expiration <= now+1) {
+    pq *old_root = current_pyamt_image->roots;
+    amtnode *amt_rt = marshal_fn(amt_root(current_amt));
+    pq *n = pq_new(now+31, amt_rt, 0, 0);
+    pq *m = meld(old_root, n);
+    pq *new_root = reference(m);
 
-    printf("now+1: %d\n", now+1);
-    printf("z->exp: %d\n", z->expiration);
-
-
-    printf("before constructing new and old\n");
-
-    pq *old_root = current_pyamt_image->roots;
-
-
-    printf("speak slowly.\n");
-    amtnode *amt_rt = amt_root(current_amt);
-    printf("got the root.\n");
-    pq *n = pq_new(now+31, amt_rt, 0, 0);
-    printf("prepared the child.\n");
-    pq *m = meld(old_root, n);
-    printf("melded the queues.\n");
-    pq *new_root = reference(m);
-    printf("referenced the fresh root\n");
-
-    
-
-    //pq *new_root = reference(meld(old_root, pq_new(now+31, amt_root(current_amt), 0, 0)));
-
-    printf("after:\n");
-    printf("the old_root is %p\n", old_root);
-    printf("the new_root is %p\n", new_root);
-    printf("the current image has a root of: %p\n", current_pyamt_image->roots);
-    
     if (__sync_bool_compare_and_swap(&current_pyamt_image->roots, old_root, new_root)) {
-
-      printf("about to enter the throes of victory, old boy\n");
-
       z->valid_root = PQ_NODE(n)->root;
       z->expiration = PQ_NODE(n)->expiry;
-
-      printf("blast and devilment\n");
-
       dereference(old_root); /* victory */
     } else
       dereference(new_root);
    
     now = time(0);
   }
-
-  printf("ensured a valid root, natch\n");
 }
 
 
   
   void *result;
   int size;
-  result = amt_find(z->valid_root, key, keylen);
+  result = amt_find(unmarshal_fn(z->valid_root), key, keylen);
   if (!result)
     Py_RETURN_NONE;
 
     return 0;
 
   z = PyCObject_AsVoidPtr(pamt);
-
-  printf("go back\n");
-
   switch_to_context(z);
 
-  printf("way back\n");
-
   switch (z->state) {
   case CONTEXT_CLOSED:
     PyErr_SetString(Error, "amt context is closed");
   const int maximum_attempts = 100;
 
   while (attempts < maximum_attempts) {
-    printf("attempt #%d\n", attempts);
     old_root = *amt_root_ref(current_amt); /* marshalled root */
-
-    printf("about to create a value\n");
-
-    void *v = amt_alloc_value(current_amt, vallen + sizeof(int));
-
-    printf("pointer for value: %p\n", v);
-    
+    void *v = amt_alloc_value(current_amt, vallen + sizeof(int));    
     *((int *) v) = vallen;
     memcpy(v + sizeof(int), val, vallen);
 
-    printf("copied value\n");
-
     sync_pyamt_image();
-
-    printf("syncing up current pointers before attempting insert\n");
-
     new_root = marshal_fn(amt_insert(current_amt, unmarshal_fn(old_root), key, keylen, v));
     if (__sync_bool_compare_and_swap(amt_root_ref(current_amt), old_root, new_root)) {
       /* great success */
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.