소스 검색

Moved the whole bitmap vector outside the header

Previously, the first element of the bitmap vector was inside the bitmap header struct. It now lies right after every bitmap header.
Ioannis Koutras 13 년 전
부모
커밋
789f41c86a
4개의 변경된 파일13개의 추가작업 그리고 10개의 파일을 삭제
  1. 0 1
      private-include/bitmap/bitmap_rb.h
  2. 3 3
      src/bitmap/bitmap_free.c
  3. 5 4
      src/bitmap/bitmap_malloc.c
  4. 5 2
      src/raw_block.c

+ 0 - 1
private-include/bitmap/bitmap_rb.h

@@ -46,7 +46,6 @@ typedef struct bitmap_rb_s {
     size_t elements; /**< The necessary amount of bitmap elements */
     /* FIXME - As long as the bitmap arrays are fixed-sized,
      * this is also fixed */
-    BMAP_EL_TYPE bmap; /**< The bitmap vector */
 } bitmap_rb_t;
 
 /** Chunk header data structure */

+ 3 - 3
src/bitmap/bitmap_free.c

@@ -1,5 +1,5 @@
 /*
- *   Copyright 2012 Institute of Communication and Computer Systems (ICCS) 
+ *   Copyright Institute of Communication and Computer Systems (ICCS) 
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   you may not use this file except in compliance with the License.
@@ -96,13 +96,13 @@ void bitmap_free(raw_block_header_t *raw_block, void *ptr) {
 
     cell_no = ((char *)chunk_header -
             ((char *)rb_header + sizeof(bitmap_rb_t) + 
-             (rb_header->elements - 1) * BMAP_EL_SIZE))
+             rb_header->elements * BMAP_EL_SIZE))
         / rb_header->bytes_per_cell;
 
     bmap_index = cell_no / BMAP_EL_SIZE_BITS;
     start_pos = cell_no % BMAP_EL_SIZE_BITS;
 
-    bmap_p = &rb_header->bmap;
+    bmap_p = (BMAP_EL_TYPE *)((char *)rb_header + sizeof(bitmap_rb_t));
 
     // If the sum of the starting position and the cells that are used is more
     // than the available bits of one bitmap array element, then we have to

+ 5 - 4
src/bitmap/bitmap_malloc.c

@@ -1,5 +1,5 @@
 /*
- *   Copyright 2012 Institute of Communication and Computer Systems (ICCS) 
+ *   Copyright Institute of Communication and Computer Systems (ICCS) 
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   you may not use this file except in compliance with the License.
@@ -77,7 +77,9 @@ void * bitmap_malloc(raw_block_header_t *raw_block, size_t req_size) {
     pthread_mutex_lock(&raw_block->mutex);
 #endif /* HAVE_LOCKS */
 
-    copy_array(temp1, &rb_header->bmap, rb_header->elements);
+    bmap_p = (BMAP_EL_TYPE *)((char *)rb_header + sizeof(bitmap_rb_t));
+
+    copy_array(temp1, bmap_p, rb_header->elements);
 
     // perform bitwise shift & and operations in the BMAP_EL_TYPE arrays
     for(i = 1; i < stop; i <<= 1) {
@@ -93,7 +95,6 @@ void * bitmap_malloc(raw_block_header_t *raw_block, size_t req_size) {
 
     found = 0;
 
-    bmap_p = &rb_header->bmap;
     for(i = 0; i < rb_header->elements; ++i) {
         found = __builtin_ffsl(temp1[i]);
         if(found) {
@@ -111,7 +112,7 @@ void * bitmap_malloc(raw_block_header_t *raw_block, size_t req_size) {
             // Calculate the pointer to the chunk to be retrieved
             chunk_address = (chunk_header_t *)((char *)rb_header +
                     sizeof(bitmap_rb_t) +
-                    (rb_header->elements - 1) * BMAP_EL_SIZE +
+                    rb_header->elements * BMAP_EL_SIZE +
                     (i * BMAP_EL_SIZE_BITS + found - 1) *
                     rb_header->bytes_per_cell);
             chunk_address->num_of_cells = cells;

+ 5 - 2
src/raw_block.c

@@ -1,5 +1,5 @@
 /*
- *   Copyright 2011 Institute of Communication and Computer Systems (ICCS) 
+ *   Copyright Institute of Communication and Computer Systems (ICCS) 
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   you may not use this file except in compliance with the License.
@@ -70,7 +70,10 @@ raw_block_header_t *create_new_raw_block(size_t raw_block_size, rb_type type) {
                  sizeof(raw_block_header_t) - sizeof(bitmap_rb_t)) /
                 (BMAP_EL_SIZE + BMAP_EL_SIZE_BITS * bitmap_rb->bytes_per_cell);
 
-            bitmap_p = &bitmap_rb->bmap;
+            /* Initialize the bitmap vector just right after the raw block
+             * header */
+            bitmap_p = (BMAP_EL_TYPE *)((char *)bitmap_rb +
+                    sizeof(bitmap_rb_t));
             for(size_t i = 0; i < bitmap_rb->elements; ++i) {
                 *bitmap_p = BMAP_EL_INIT_VAL;
                 bitmap_p++;