odp_pktio_t odp_pktio_lookup(const char *dev) { odp_pktio_t id = ODP_PKTIO_INVALID; pktio_entry_t *entry; int i; odp_spinlock_lock(&pktio_tbl->lock); for (i = 1; i <= ODP_CONFIG_PKTIO_ENTRIES; ++i) { entry = get_pktio_entry(_odp_cast_scalar(odp_pktio_t, i)); if (!entry || is_free(entry)) continue; lock_entry(entry); if (!is_free(entry) && strncmp(entry->s.name, dev, IF_NAMESIZE) == 0) id = _odp_cast_scalar(odp_pktio_t, i); unlock_entry(entry); if (id != ODP_PKTIO_INVALID) break; } odp_spinlock_unlock(&pktio_tbl->lock); return id; }
int is_free(variable *var, term *haystack) { if (haystack == NULL) return 0; switch(haystack->tag) { case VAR: if (variable_equal(var, haystack->var)) { return 1; } return 0; case HOLE: return 0; case IMPLICIT: return 0; case LAM: case PI: if (variable_equal(var, haystack->var)) { return 0; } // fall-through case APP: return is_free(var, haystack->left) || is_free(var, haystack->right); case DATATYPE: { if (variable_equal(var, haystack->var)) { return 1; } #define IS_FREE_VEC(n, a) do { \ int __i; \ for (__i = 0; __i < n; __i++) { \ if (is_free(var, a[__i])) return 1; \ } \ } while (0) IS_FREE_VEC(haystack->num_params, haystack->params); IS_FREE_VEC(haystack->num_indices, haystack->indices); return 0; } case INTRO: case ELIM: { if (variable_equal(var, haystack->var)) { return 1; } IS_FREE_VEC(haystack->num_args, haystack->args); IS_FREE_VEC(haystack->num_params, haystack->params); IS_FREE_VEC(haystack->num_indices, haystack->indices); return 0; } case TYPE: return 0; default: sentinel("bad term"); } error: return 0; }
SeparationOpt (const vector<Ixn> &ixns): ixns(ixns), inv_m(0) { for (int i = 0; i < (int)ixns.size(); i++) { assert(!is_free(ixns[i].f0)); assert(is_free(ixns[i].f1)); for (int v = 0; v < 3; v++) include(ixns[i].f0->v[v]->node, nodes); } nvar = nodes.size()*3; ncon = ixns.size(); inv_m = 1;//nodes.size(); }
void find_face_intersection (const Face *face0, const Face *face1) { if (!is_free(face0) && !is_free(face1)) return; int t = omp_get_thread_num(); Bary b0, b1; bool is_ixn = intersection_midpoint(face0, face1, b0, b1); if (!is_ixn) return; Vec3 n = -normalize(face0->n/2. + SO::nold[face0]); farthest_points(face0, face1, n, b0, b1); SO::ixns[t].push_back(Ixn(face0, b0, face1, b1, n)); }
void dfree(void* ptr, int flag) { /* Your free and coalescing code goes here */ //bool left_f = is_free(left_block(ptr)); bool right_f = is_free(to_meta(right_block(ptr))); bool left_f = is_free((metadata_t *)(ptr - META_SIZE - FOOTER_SIZE)); if (!left_f && !right_f) { set_free(to_meta(ptr)); set_free((metadata_t *)to_footer(ptr)); add_node(to_meta(ptr)); } else if (left_f && !right_f) { //process the linked list //change the size of two blocks delete_node(to_meta(left_block(ptr))); int left_size = block_size(left_block(ptr)); int new_size = left_size + FOOTER_SIZE + META_SIZE + block_size(ptr); set_size(to_meta(left_block(ptr)), new_size); set_size((metadata_t *)to_footer(ptr), new_size); set_free(to_meta(left_block(ptr))); set_free((metadata_t *)to_footer(ptr)); add_node(to_meta(left_block(ptr))); } else if (!left_f && right_f) { //process the linked list delete_node(to_meta(right_block(ptr))); //change the size of two blocks int right_size = block_size(right_block(ptr)); int new_size = right_size + block_size(ptr) + FOOTER_SIZE + META_SIZE; set_size((metadata_t *)to_footer(right_block(ptr)), new_size); set_free((metadata_t *)to_footer(right_block(ptr))); set_size(to_meta(ptr), new_size); set_free(to_meta(ptr)); //process the linked list add_node(to_meta(ptr)); } else if (left_f && right_f) { //process the linked list delete_node(to_meta(right_block(ptr))); delete_node(to_meta(left_block(ptr))); //change the size of two blocks int right_size = block_size(right_block(ptr)); int left_size = block_size(left_block(ptr)); int new_size = block_size(ptr) + left_size + right_size + 2 * (FOOTER_SIZE + META_SIZE); set_size((metadata_t *)to_footer(right_block(ptr)), new_size); set_free((metadata_t *)to_footer(right_block(ptr))); set_size(to_meta(left_block(ptr)), new_size); set_free(to_meta(left_block(ptr))); add_node(to_meta(left_block(ptr))); } }
void play_server(char board[][7]) { int move=1,i, temp=100100; int col_order[7]={3,2,4,1,5,0,6}; int alpha=-100100; int beta=+100100; for(int j=0; j<7; j++) { if(is_free(col_order[j], board)) { update_board(col_order[j]+1, 's', board); temp=max(board,12,alpha, beta); if(temp<beta) { beta=temp; move=col_order[j]+1; } update_board(col_order[j]+1, 'a', board); } } update_board(move, 's', board); }
void compact() { void* threshold = NULL; void* last = NULL; item_p i = matched; item_p* prev = &matched; while (i != NULL) { threshold = i->data + block_size(i); if (is_free(i)) { *prev = i->next; i->next = unmatched; unmatched = i; if (last == NULL) last = i->data; i = *prev; } else { if (last != NULL) { memcpy(last, i->data, block_size(i)); i->data = last; last = last + block_size(i); prev = &(i->next); } i = i->next; } } freeblks = 0; if (last != NULL && last != threshold) { i = get_unmatched_item(); i->data = last; i->size = (char*)threshold - (char*)last; set_free(i); *prev = i; freeblks++; } }
void LinearSolver::print_to_file(vector<double>& var_val_vec, string filename) { vector<double> input_x_(nb_free_variables_); // for(int i=0; i<nb_variables_; i++) { if (is_free(variable_[i].index())) { input_x_[variable_[i].index()] = var_val_vec[i] ; } } CMeshSparseMatrix solve_matrix_A; m_solve_matrix_AT_.Transpose(solve_matrix_A); vector<double> function_vector(solve_matrix_A.GetRowNum()); solve_matrix_A.MultiplyVector(input_x_, function_vector); for (size_t i = 0; i < function_vector.size(); i++) { function_vector[i] -= m_solve_b_vec[i]; } size_t end_equ = m_equ_div_flag_vec[1]; ofstream file(filename.c_str()); file << end_equ << '\n'; for (size_t i = 0; i < end_equ; i++) { file << i << ' ' << function_vector[i] << '\n'; } file.close(); }
int main(int argc, const char * argv[]) { if(argc != 2){ printf("Usage: ./xxx port(port stands for the port wanna listen on.)\n"); exit(1); } signal(SIGCHLD, SIG_IGN); if(!is_free()){ // exit(0); } int port = atoi(argv[1]); struct sockaddr_in addr; bzero(&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_ANY); addr.sin_port = htons(port); int server_socket = socket(AF_INET, SOCK_STREAM, 0); bind(server_socket, (struct sockaddr *) &addr, sizeof(addr)); listen(server_socket, 0); ProcessPool* pool = new ProcessPool(server_socket, 1, 10); pool->init(); pool->addTask(print, NULL); pool->start(); if(pool) delete(pool); exit(0); }
void Multi_State::clock_tick() { // Defines what will happen each tick. player1.move(p1dir); player2.move(p2dir); check_collisions(); if (p1parts_to_add != 0) { // If theres body to add, add one player1.add_parts(1); p1parts_to_add--; } if (p2parts_to_add != 0) { player2.add_parts(1); p2parts_to_add--; } carrot_tick++; // Is added every tick if (carrot_tick == 10) { // When it updates every 10th tick carrot = rotten_carrots.at(rotten_carrots.size() - 1); rotten_carrots.pop_back(); do { sprite_x = get_engine()->rand_x(); sprite_y = get_engine()->rand_y(); } while (!is_free(sprite_x, sprite_y)); carrot.x = sprite_x; carrot.y = sprite_y; std::vector<Obstacles>::iterator it; it = rotten_carrots.begin(); // After we've removed the carrot we add it to the first position rotten_carrots.insert(it, carrot); carrot_tick = 0; } }
int max(char board[][7], int depth, int alpha, int beta) { if(depth==0) { return appx_score(board); } else if(check_win(board)==1) return -100000-depth; else if(check_win(board)==2) return 0; else { int temp=0, ctr=0; int col_order[7]={3,2,4,1,5,0,6}; int score_order[7]={-100000, -100000, -100000, -100000, -100000, -100000, -100000}; for(int i=0; i<7; i++) { if(is_free(i, board)) { update_board(i+1, 'c', board); score_order[ctr]=appx_score(board); col_order[ctr]=i; update_board(i+1, 'a', board); ctr=ctr+1; } } for(int x=0; x<ctr; x++) { for(int y=0; y<ctr-x-1; y++) { if(score_order[y]<score_order[y+1]) { int temp2 = col_order[y+1]; int temp1 = score_order[y+1]; col_order[y+1] = col_order[y]; col_order[y] = temp2; score_order[y+1] = score_order[y]; score_order[y] = temp1; } } } for(int j=0; j<ctr; j++) { if(alpha<beta) { update_board(col_order[j]+1, 'c', board); temp=mini(board, depth-1, alpha, beta); if(temp>alpha) alpha=temp; update_board(col_order[j]+1, 'a', board); } else return alpha; } return alpha; //beta becomes alpha } }
// -------------------------------------------- // // -------------------------------------------- static bool is_block_available(Tile* tiles, int gx, int gy) { for (int i = 0; i < 4; ++i) { if (!is_free(tiles, gx + BLOCK_X[i], gy + BLOCK_Y[i])) { return false; } } return true; }
void print_pd_map() { unsigned int i = 0; while(i < dt_size) { if(is_free(i)) { print("["); print_llu(i); print(" : "); while(i < dt_size && is_free(i)) { ++i; } print_llu(i); print(")"); } ++i; } println(""); }
Multi_State::Multi_State() { // Initalises player1 with number one sprite // which gives shows us 'player1' in the head of the sprite. player1.init(1); player2.init(2); // Assigns the objects, and sends a SDL_Surface* which is returned // from load_image as a argument. apple = Obstacles(Snake_Engine::load_image("./img/apple.bmp")); carrot = Obstacles(Snake_Engine::load_image("./img/carrot.bmp")); // Get a random position until we find a free one. do { sprite_x = get_engine()->rand_x(); sprite_y = get_engine()->rand_y(); } while (!is_free(sprite_x, sprite_y)); apple.x = sprite_x; apple.y = sprite_y; // Does the same thing but spawns 35 carrots. for (int i = 0; i != 35; i++) { do { sprite_x = get_engine()->rand_x(); sprite_y = get_engine()->rand_y(); } while (!is_free(sprite_x, sprite_y)); carrot.x = sprite_x; carrot.y = sprite_y; rotten_carrots.push_back(carrot); } carrot_tick = 0; green_background.x = 16; green_background.y = 16; green_background.w = 608; green_background.h = 448; finished = false; // Direction is initalized to right in the beginning p1dir = 2; p2dir = 2; p1points = 0; p2points = 0; p1parts_to_add = 0; p2parts_to_add = 0; }
void print_heap_dump() { printf("========= HEAP DUMP =========\n"); item_p i = matched; while (i != NULL) { printf("%p %c %7db\n", i->data, is_free(i) ? 'f' : 'u', i->size & (~1)); i = i->next; } printf("=============================\n"); }
void print_block_map(void* mapBuffer, uint32_t start, uint32_t size, FILE* stream, int block) { uint32_t i; for (i=0; i<size; i++) { if (is_free(mapBuffer, i)) fprintf(stream, "%x, %d\n", block, start+i+1 ); } }
static int add_entry( phys_addr_t ea, ucell size, range_t **r ) { if( !is_free( ea, size, *r ) ) { OFMEM_TRACE("add_entry: range not free!\n"); return -1; } add_entry_( ea, size, r ); return 0; }
kern_return_t ipc_space_create( ipc_table_size_t initial, ipc_space_t *spacep) { ipc_space_t space; ipc_entry_t table; ipc_entry_num_t new_size; mach_port_index_t index; space = is_alloc(); if (space == IS_NULL) return KERN_RESOURCE_SHORTAGE; table = it_entries_alloc(initial); if (table == IE_NULL) { is_free(space); return KERN_RESOURCE_SHORTAGE; } new_size = initial->its_size; memset((void *) table, 0, new_size * sizeof(struct ipc_entry)); /* * Initialize the free list in the table. * Add the entries in reverse order, and * set the generation number to -1, so that * initial allocations produce "natural" names. */ for (index = 0; index < new_size; index++) { ipc_entry_t entry = &table[index]; entry->ie_bits = IE_BITS_GEN_MASK; entry->ie_next = index+1; } table[new_size-1].ie_next = 0; is_ref_lock_init(space); space->is_references = 2; is_lock_init(space); space->is_active = TRUE; space->is_growing = FALSE; space->is_table = table; space->is_table_size = new_size; space->is_table_next = initial+1; ipc_splay_tree_init(&space->is_tree); space->is_tree_total = 0; space->is_tree_small = 0; space->is_tree_hash = 0; *spacep = space; return KERN_SUCCESS; }
void FreeHeader::set_free() { // If this is newly freed if (!is_free()) { alloc_size_ *= -1; set_smaller_free(NULL, NULL); set_larger_free(NULL, NULL); } }
static odp_pktio_t alloc_lock_pktio_entry(odp_pktio_params_t *params) { odp_pktio_t id; pktio_entry_t *entry; int i; for (i = 0; i < ODP_CONFIG_PKTIO_ENTRIES; ++i) { entry = &pktio_tbl->entries[i]; if (is_free(entry)) { lock_entry(entry); if (is_free(entry)) { init_pktio_entry(entry, params); id = i + 1; return id; /* return with entry locked! */ } unlock_entry(entry); } } return ODP_PKTIO_INVALID; }
struct myinfo myinfo() { struct myinfo res = {arena, freemem, usdmem, freeblks, usdblks,0}; item_p i = matched; size_t max_free = 0; while (i != NULL) { size_t curr = block_size(i); if (is_free(i) && curr > max_free) max_free = curr; i = i->next; } res.maxfreeblk = max_free; return res; }
bool buy_with_check( int customer ) { // It is unsafe to use just is_free() followed by buy(customer), // since it violates atomicity. bool bought = false; pthread_mutex_lock( &mutex ); if ( is_free() ) { buy( customer ); bought = true; } pthread_mutex_unlock( &mutex ); return bought; }
void LinearSolver::equations_value(vector<double>& var_val_vec) { vector<double> input_x_(nb_free_variables_); // for(int i=0; i<nb_variables_; i++) { if (is_free(variable_[i].index())) { input_x_[variable_[i].index()] = var_val_vec[i] ; } } print_f(input_x_); }
static odp_pktio_t alloc_lock_pktio_entry(void) { odp_pktio_t id; pktio_entry_t *entry; int i; for (i = 0; i < ODP_CONFIG_PKTIO_ENTRIES; ++i) { entry = &pktio_tbl->entries[i]; if (is_free(entry)) { lock_entry_classifier(entry); if (is_free(entry)) { init_pktio_entry(entry); id = _odp_cast_scalar(odp_pktio_t, i + 1); return id; /* return with entry locked! */ } unlock_entry_classifier(entry); } } return ODP_PKTIO_INVALID; }
void print_inode_map (void* mapBuffer, FILE* stream, group_des_t groupDes) { //also registers the allocated inodes uint32_t size = groupDes->nInodes; int start = groupDes->inodeStart; int block = groupDes->inodeMapBlock; uint32_t i; for (i=0; i<size; i++) { uint32_t nth = start + i; if (is_free(mapBuffer, i)) fprintf(stream, "%x, %d\n", block, nth ); } }
static odp_pktio_t alloc_lock_pktio_entry(odp_pktio_params_t *params) { odp_pktio_t id; pktio_entry_t *entry; int i; (void)params; for (i = 0; i < ODP_CONFIG_PKTIO_ENTRIES; ++i) { entry = &pktio_tbl->entries[i]; if (is_free(entry)) { lock_entry(entry); if (is_free(entry)) { set_taken(entry); entry->s.inq_default = ODP_QUEUE_INVALID; entry->s.outq_default = ODP_QUEUE_INVALID; id = i + 1; return id; /* return with entry locked! */ } unlock_entry(entry); } } return ODP_PKTIO_INVALID; }
State System::sample() { State s; while(1) { for(int i=0; i< NUM_DIM; i++) { s.x[i] = min_states[i] + RANDF*( max_states[i] - min_states[i]); } if( is_free(s) ) break; } return s; }
struct Map * GetFreeMap(struct Map *m) { struct Map *temp; for(temp = m; temp; temp = temp->next) { if(is_free(temp)) { return temp; } } return NULL; }
int odp_pktio_restart(odp_pktio_t id) { pktio_entry_t *entry; uint8_t port_id; int ret; entry = get_pktio_entry(id); if (entry == NULL) { ODP_DBG("pktio entry %d does not exist\n", id->unused_dummy_var); return -1; } if (odp_unlikely(is_free(entry))) { ODP_DBG("already freed pktio\n"); return -1; } if (odp_pktio_is_not_hns_eth(entry)) { ODP_DBG("pktio entry %d is not ODP UMD pktio\n", id->unused_dummy_var); return -1; } port_id = entry->s.pkt_odp.portid; if (!odp_eth_dev_is_valid_port(port_id)) { ODP_DBG("pktio entry %d ODP UMD Invalid port_id=%d\n", id->unused_dummy_var, port_id); return -1; } /* Stop device */ odp_eth_dev_stop(port_id); /* Start device */ ret = odp_eth_dev_start(port_id); if (ret < 0) { ODP_ERR("odp_eth_dev_start:err=%d, port=%u\n", ret, (unsigned)port_id); return -1; } ODP_DBG("odp pmd restart done\n\n"); return 0; }
void Solver<TQ>::reconstruct_gradient() { // reconstruct inactive elements of G from G_bar and free variables if(active_size == l) return; for(int i=active_size;i<l;i++) G[i] = G_bar[i] + p[i]; for(int i=0;i<active_size;i++) if(is_free(i)) { const float *Q_i = Q->get_Q(i,l); float alpha_i = alpha[i]; for(int j=active_size;j<l;j++) G[j] += alpha_i * Q_i[j]; } }