Commits

Anonymous committed 41f09e1 Draft

must be able to write, even when an image is opened for 'reading' (because the priority queue involves mutating the shared memory image, duh)

  • Participants
  • Parent commits 804c7de

Comments (0)

Files changed (1)

   unsigned int new_length;
 
  sync_alloc:
-  alloc = __sync_fetch_and_add(&i->header->alloc, 0);
+  alloc = __sync_fetch_and_add(&i->header->alloc, 0);  
   old_length = __sync_fetch_and_add(&i->header->length, 0);
 
   if (alloc + nbytes > old_length)
   pq *next;
   int i;
 
+  printf("pq_alloc\n");
+
  sync_alloc:
-  oldroot = __sync_fetch_and_add(&current_pyamt_image->pq_free, 0);
+  printf("sync_alloc\n");
+
+  printf("current_pyamt_image : %p\n", current_pyamt_image);
+
+  printf("%p biot90ch\n", current_pyamt_image->roots);
+
+  //oldroot = __sync_synchronize(current_pyamt_image->pq_free);
+  oldroot = current_pyamt_image->pq_free;
+
+  printf("old root is %p. sync image\n", oldroot);
+
   sync_pyamt_image();
+
+  printf("ok.\n");
+
   allocated = unmarshal_fn(oldroot);
-  
+ 
+
   if (!allocated)
     goto sync_alloc_nodes;
 
   } goto sync_alloc;
 
  sync_alloc_nodes:
+  printf("sync_alloc_nodes\n");
+
   new = marshal_fn(allocator(sizeof(pq) * SLAB_SIZE));
+
+  printf("new: %p\n", new);
+
   sync_pyamt_image();
+  
+  printf("post sync:\n");
+
   init = unmarshal_fn(new);
   i = 0;
+
+  printf("new %p unmarshals to init %p\n", new, init);
   
   while (i < SLAB_SIZE - 1) {
     next = (void *) init + sizeof(pq);
     ++i;
   }
 
+  printf("initialized slab.\n");
+
   while (1) {
     oldroot = current_pyamt_image->pq_free;
     init->right = oldroot;
       break;
   }
 
+  printf("sync_alloc_nodes ok.\n");
+
   goto sync_alloc;
 }
 
 
   /* assumption: time_t is expressed in seconds */
   while (now+1 >= z->expiration) {
+    printf("before constructing new and old\n");
+
     pq *old_root = current_pyamt_image->roots;
-    pq *new_root = reference(meld(old_root, pq_new(now+31, amt_root(current_amt), 0, 0)));
+
+
+    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)) {
       z->valid_root = PQ_NODE(new_root)->root;
   char *imgname = 0;
   int mode = 0;
 
-  if (!PyArg_ParseTuple(args, "s|i", &imgname, mode))
+  if (!PyArg_ParseTuple(args, "s|i", &imgname, &mode))
     return 0;
   
   pyamt_context *z = calloc(sizeof(pyamt_context), 1);
   }
   
   z->state = CONTEXT_CLOSED;
-  if (mode & OPEN_WRITE)
-    z->img = write_image(imgname);
-  else
-    z->img = read_image(imgname);
+  z->img = write_image(imgname);
 
   switch (z->img.status) {
   case SHM_ERR: