Ejemplo n.º 1
0
static BalloonChunk *
BalloonGetChunk(Balloon *b,         // IN/OUT
                int isLargePage)    // IN
{
   BalloonChunk *chunk;
   BalloonChunkList *chunkList = &b->pages[isLargePage];

   /* Get first chunk from the list */
   if (DblLnkLst_IsLinked(&chunkList->chunks)) {
      chunk = DblLnkLst_Container(chunkList->chunks.next, BalloonChunk, node);
      if (chunk->nEntries < BALLOON_CHUNK_ENTRIES) {
         /* This chunk has free slots, use it */
         return chunk;
      }
   }

   /* create new chunk */
   chunk = BalloonChunk_Create();
   if (chunk != NULL) {
      DblLnkLst_LinkFirst(&chunkList->chunks, &chunk->node);

      /* update stats */
      chunkList->nChunks++;
   }

   return chunk;
}
Ejemplo n.º 2
0
static BalloonChunk *
BalloonGetChunkOrFallback(Balloon *b,      // IN/OUT
                          int isLargePage) // IN
{
   BalloonChunk *chunk = BalloonGetChunk(b, isLargePage);
   if (chunk == NULL) {
      BalloonChunkList *chunkList = &b->pages[isLargePage];

      ASSERT(b->fallbackChunk != NULL);
      chunk = b->fallbackChunk;
      b->fallbackChunk = NULL;

      DblLnkLst_LinkFirst(&chunkList->chunks, &chunk->node);
      chunkList->nChunks++;
   }

   return chunk;
}
Ejemplo n.º 3
0
/* Test code entry point */
int
main(int argc,    // IN
     char **argv) // IN
{
   member *c1;
   member *c2;
   member *c3;
   member *c4;

   DblLnkLst_Links h;
   member *a1;
   member *a2;
   member *a3;

   printf("Circular list: there is no origin\n");

   /* Create the 1st member */
   c1 = make_member(1);
   /* Special case: there is no list to merge with, initially */

   /* Add the 2nd member _after_ the 1st one */
   c2 = make_member(2);
   DblLnkLst_Link(&c1->l, &c2->l);

   /* Add the 3rd member _after_ the 2nd one */
   c3 = make_member(3);
   DblLnkLst_Link(&c1->l, &c3->l);

   /* Add the 4th member _before_ the 3rd one */
   c4 = make_member(4);
   DblLnkLst_Link(&c3->l, &c4->l);

   printf("See it from this member...\n");
   dump_circular(c1);
   printf("...Or from this one\n");
   dump_circular(c4);

   printf("\n");
   printf("Anchored (linear) list: it has a beginning and an end\n");

   /* Create the 'head' of the list */
   DblLnkLst_Init(&h);

   /* Add the 1st member at the _end_ */
   a1 = make_member(5);
   DblLnkLst_LinkLast(&h, &a1->l);

   /* Add the 2nd member at the _beginning_ */
   a2 = make_member(6);
   DblLnkLst_LinkFirst(&h, &a2->l);

   /* Add the 3rd member _before_ the 1st one */
   a3 = make_member(7);
   DblLnkLst_Link(&a1->l, &a3->l);

   dump_anchored(&h);

   printf("\n");
   printf("Merge both lists: the result is an anchored list\n");

   DblLnkLst_Link(&h, &c4->l);

   dump_anchored(&h);

   printf("\n");
   printf("Remove a member\n");

   DblLnkLst_Unlink1(&c3->l);

   dump_anchored(&h);

   printf("\n");
   printf("Split the result in two lists: an anchored one and a circular "
          "one\n");
   DblLnkLst_Unlink(&h, &a1->l);

   dump_anchored(&h);
   dump_circular(a1);

   return 0;
}