void timer_postpone(timer_event_t *event, timer_time_t time) { pthread_mutex_lock(&timer_mutex); event->time = time; int index = heap_index(&timer_events, event); heap_percolate_down(&timer_events, index); pthread_mutex_unlock(&timer_mutex); }
void operator()(T* first, T* last) { T* array = first; int end = heap_index(first, last); heapify(array, end + 1); while (0 < end) { std::swap(array[end], array[0]); --end; sift_down(array, 0, end); } } // end of operator()
void* heap_alloc(pony_actor_t* actor, heap_t* heap, size_t size) { if(size == 0) { return NULL; } else if(size <= HEAP_MAX) { return heap_alloc_small(actor, heap, heap_index(size)); } else { return heap_alloc_large(actor, heap, size); } }
LLVMValueRef gencall_allocstruct(compile_t* c, gentype_t* g) { // Disable debug anchor dwarf_location(&c->dwarf, NULL); // We explicitly want a boxed version. // Get the size of the structure. size_t size = (size_t)LLVMABISizeOfType(c->target_data, g->structure); // Get the finaliser, if there is one. const char* final = genname_finalise(g->type_name); LLVMValueRef final_fun = LLVMGetNamedFunction(c->module, final); // Allocate the object. LLVMValueRef args[3]; args[0] = codegen_ctx(c); LLVMValueRef result; if(final_fun == NULL) { if(size <= HEAP_MAX) { uint32_t index = heap_index(size); args[1] = LLVMConstInt(c->i32, index, false); result = gencall_runtime(c, "pony_alloc_small", args, 2, ""); } else { args[1] = LLVMConstInt(c->intptr, size, false); result = gencall_runtime(c, "pony_alloc_large", args, 2, ""); } } else { args[1] = LLVMConstInt(c->intptr, size, false); args[2] = LLVMConstBitCast(final_fun, c->final_fn); result = gencall_runtime(c, "pony_alloc_final", args, 3, ""); } result = LLVMBuildBitCast(c->builder, result, g->structure_ptr, ""); // Set the descriptor. if(g->underlying != TK_STRUCT) { LLVMValueRef desc_ptr = LLVMBuildStructGEP(c->builder, result, 0, ""); LLVMBuildStore(c->builder, g->desc, desc_ptr); } return result; }
void* heap_realloc(pony_actor_t* actor, heap_t* heap, void* p, size_t size) { if(p == NULL) return heap_alloc(actor, heap, size); chunk_t* chunk = (chunk_t*)pagemap_get(p); if(chunk == NULL) { // Get new memory and copy from the old memory. void* q = heap_alloc(actor, heap, size); memcpy(q, p, size); return q; } if(chunk->size < HEAP_SIZECLASSES) { // Previous allocation was a heap_alloc_small. if(size <= HEAP_MAX) { uint32_t sizeclass = heap_index(size); // If the new allocation is the same size or smaller, return the old one. if(sizeclass <= chunk->size) return p; } // Get new memory and copy from the old memory. void* q = heap_alloc(actor, heap, size); memcpy(q, p, SIZECLASS_SIZE(chunk->size)); return q; } // Previous allocation was a heap_alloc_large. if(size <= chunk->size) return p; // Get new memory and copy from the old memory. void* q = heap_alloc(actor, heap, size); memcpy(q, p, chunk->size); return q; }