void pmem_add(phys_addr_t start, size_t length) { pmem_region_t* reg; recheck: reg = pmem_region_head; while(reg) { if(start >= reg->start && start < (reg->start + reg->length)) { /* start within this region */ if((start + length) <= (reg->start + reg->length)) { /* end withing this section, so completely with us already */ return; } length -= (reg->start + reg->length) - start; start = reg->start + reg->length; goto recheck; } if((start + length) > reg->start && (start + length) < (reg->start + reg->length)) { /* end within this region */ if(start >= reg->start) { /* start too, so no more left over. */ return; } length = (reg->start - start); goto recheck; } reg = reg->next; } /* we have a checked region here, with correct start and end. * now allocate the required management structures, etc. */ pmem_region_t* region = (pmem_region_t*)kheap_alloc(sizeof(pmem_region_t)); bitmap_t* bmap = bmap_new(PMEM_PAGES(length)); if(!region || !bmap) { error("not enough memory to allocate memory management structures!\n"); if(region) kheap_free(region); if(bmap) kheap_free(bmap); return; } region->start = start; region->length = length; region->bmap = bmap; region->next = NULL; pmem_region_tail->next = region; pmem_region_tail = region; }
static void* pthread_main (void *arg) { int* arr = (int*)arg; int thrn = *(arr); arr++; int num_elem = *(arr);arr++; #ifdef DEBUG printf ("starting thread %d num elem %d\n", thrn, num_elem); #endif int i; _depth = num_nodes + 1; for (i = 0; i < num_elem; i++){ #ifdef DEBUG printf ("iterating thread %d elem #%d\n", thrn, arr[i]); #endif _update_path = num_nodes; bmap_init_static (num_nodes); _node_to_start = arr[i]; _stop_cnt = 0; _found_min = (_global_found_min == ULONG_MAX ? ULONG_MAX: _global_found_min + 1); #ifdef DEBUG _stat_cut_by_weight = _stat_cut_by_presence = _stat_evaluated = _stat_found_hash = 0; #endif GraphPath *path = path_new (); Bitmap *bitmap = bmap_new (); int res = find_shortest_path (bitmap, &path); #ifdef DEBUG printf ("MAX: %lu -> %lu (weight:%lu, presence:%lu, eval:%lu, hash:%lu)\n", _found_min, path->total_weight, _stat_cut_by_weight, _stat_cut_by_presence, _stat_evaluated, _stat_found_hash); bmap_print_hash (); #endif if (res){ /* begin critical section */ pthread_mutex_lock (&_mutex); if (path->total_weight < _global_found_min){ match_cnt = 0; if (best_found_path) path_free (best_found_path); best_found_path = path_clone (path); _global_found_min = path->total_weight; } if (path->total_weight == _global_found_min){ match_cnt++; } if (match_cnt >= MINIMUM_NUMBER_MATCHES_RESULTS){ print_solution (best_found_path); exit(0); } pthread_mutex_unlock (&_mutex); /* end critical section */ } path_free (path); bmap_free (bitmap); _depth += 2; } bmap_free_static (); return 0; }