VM* vm_new(int num_cpus) { if (num_cpus <= 0) { LOG_ERROR("vm_new: num_cpus <= 0"); return NULL; } VM* vm = (VM*)IOMalloc(sizeof(VM)); if (!vm) { LOG_ERROR("vm_new: can't allocate VM"); return NULL; } memset(vm, 0, sizeof(VM)); vm->num_cpus = num_cpus; vm->cpus = (CPU**)IOMalloc(sizeof(CPU*) * num_cpus); if (!vm->cpus) { LOG_ERROR("vm_new: can't allocate cpus[]"); vm_delete(vm); return NULL; } memset(vm->cpus, 0, sizeof(sizeof(CPU*) * num_cpus)); for (int i = 0; i < vm->num_cpus; i++) { CPU* cpu = cpu_new(); if (!cpu) { vm_delete(vm); return NULL; } vm->cpus[i] = cpu; } LOG("created VM"); return vm; }
/** * Cleanup function for VM 'viewport' stmt. */ void vm_viewport_cleanup(VMStmt *curstmt) { VMStmtViewport * stmtobj = (VMStmtViewport *) curstmt; // Free the parameter initializer expressions. // delete_exprtree(stmtobj->expr_from); stmtobj->expr_from = NULL; delete_exprtree(stmtobj->expr_at); stmtobj->expr_at = NULL; delete_exprtree(stmtobj->expr_angle); stmtobj->expr_angle = NULL; // Free up the lvalue objects we've associated with this context. // vm_delete_lvalue(stmtobj->lv_from); stmtobj->lv_from = NULL; vm_delete_lvalue(stmtobj->lv_at); stmtobj->lv_at = NULL; vm_delete_lvalue(stmtobj->lv_angle); stmtobj->lv_angle = NULL; // Recursively free the statements in our block. // vm_delete(stmtobj->block); stmtobj->block = NULL; }
/** * Cleanup function for VM visibility stmt. * * @param curstmt - VMStmt * - Base pointer to the statement for this type. */ void vm_visibility_cleanup(VMStmt *curstmt) { VMStmtVisibility * stmtbkgrnd = (VMStmtVisibility *) curstmt; // Free the parameter initializer expressions. // delete_exprtree(stmtbkgrnd->expr_color); stmtbkgrnd->expr_color = NULL; delete_exprtree(stmtbkgrnd->expr_distance); stmtbkgrnd->expr_distance = NULL; // Recursively free the statements in our block. // vm_delete(stmtbkgrnd->block); stmtbkgrnd->block = NULL; }
/** * Cleanup function for VM background stmt. * * @param curstmt - VMStmt * - Base pointer to the statement for this type. */ void vm_background_cleanup(VMStmt *curstmt) { VMStmtBackground * stmtbkgrnd = (VMStmtBackground *) curstmt; // Free the parameter initializer expressions. // delete_exprtree(stmtbkgrnd->expr_color1); stmtbkgrnd->expr_color1 = NULL; delete_exprtree(stmtbkgrnd->expr_color2); stmtbkgrnd->expr_color2 = NULL; // Recursively free the statements in our block. // vm_delete(stmtbkgrnd->block); stmtbkgrnd->block = NULL; }