Przeglądaj źródła

Cleared a bit the section of cell marking in bitmap_malloc()

Ioannis Koutras 12 lat temu
rodzic
commit
03880823bd
1 zmienionych plików z 14 dodań i 15 usunięć
  1. 14 15
      src/bitmap/bitmap_malloc.c

+ 14 - 15
src/bitmap/bitmap_malloc.c

@@ -46,7 +46,7 @@
  */
 void * bitmap_malloc(raw_block_header_t *raw_block, size_t req_size) { 
     bitmap_rb_t *rb_header;
-    size_t cells, stop, i, found;
+    size_t cells, stop, i, start_pos;
     void *ret;
     chunk_header_t *chunk_address;
     BMAP_EL_TYPE *bmap_p;
@@ -94,29 +94,29 @@ void * bitmap_malloc(raw_block_header_t *raw_block, size_t req_size) {
         add_arrays(temp1, temp2, rb_header->elements);
     }
 
-    found = 0;
+    start_pos = 0;
 
     for(i = 0; i < rb_header->elements; ++i) {
-        found = __builtin_ffsl(temp1[i]);
-        if(found) {
 
+        // __builtin_ffsl() returns the position of the first 1 starting from 1
+        start_pos = (size_t) __builtin_ffsl((long) temp1[i]);
+        // so if an 1 is found, it will change from 0 to the position
+        if(start_pos) {
 
             // 1. Mark the occupied cells
 
-            /* Because found starts from 1, we have to add 1 to the counter. */
+            size_t cell_no = i * BMAP_EL_SIZE_BITS + start_pos - 1;
             size_t mask_counter = cells;
-            size_t mask_start = found;
-            unsigned int vector_index = i;
 
             while(mask_counter != 0) {
                 if(mask_counter > BMAP_EL_SIZE_BITS) {
-                    bmap_p[vector_index] &= ~make_bit_mask(mask_start, 
-                            BMAP_EL_SIZE_BITS - mask_start + 1);
-                    mask_counter -= BMAP_EL_SIZE_BITS - mask_start + 1;
-                    vector_index++;
-                    mask_start = 1;
+                    bmap_p[i] &= ~make_bit_mask(start_pos, 
+                            BMAP_EL_SIZE_BITS - start_pos + 1);
+                    mask_counter -= BMAP_EL_SIZE_BITS - start_pos + 1;
+                    i++;
+                    start_pos = 1;
                 } else {
-                    bmap_p[vector_index] &= ~make_bit_mask(mask_start, 
+                    bmap_p[i] &= ~make_bit_mask(start_pos, 
                             mask_counter);
                     mask_counter = 0;
                 }
@@ -127,8 +127,7 @@ void * bitmap_malloc(raw_block_header_t *raw_block, size_t req_size) {
             chunk_address = (chunk_header_t *)((char *)rb_header +
                     sizeof(bitmap_rb_t) +
                     rb_header->elements * BMAP_EL_SIZE +
-                    (i * BMAP_EL_SIZE_BITS + found - 1) *
-                    rb_header->bytes_per_cell);
+                    cell_no * rb_header->bytes_per_cell);
 
             // 3. Update the chunk header