ticks_t wait_handler(ticks_t ti, struct timer_ln *wait_tl, void *data) { struct cell *p_cell; ticks_t ret; p_cell = (struct cell *)data; #ifdef TIMER_DEBUG LM_DBG("WAIT timer hit @%d for %p (timer_lm %p)\n", ti, p_cell, wait_tl); #endif #ifdef TM_DEL_UNREF /* stop cancel timers if any running */ if(is_invite(p_cell)) cleanup_localcancel_timers(p_cell); /* remove the cell from the hash table */ LOCK_HASH(p_cell->hash_index); remove_from_hash_table_unsafe(p_cell); UNLOCK_HASH(p_cell->hash_index); p_cell->flags |= T_IN_AGONY; if(t_linked_timers(p_cell)) { UNREF_FREE(p_cell, 0); } else { UNREF_FREE(p_cell, 1); } ret = 0; #else /* TM_DEL_UNREF */ if(p_cell->flags & T_IN_AGONY) { /* delayed delete */ /* we call delete now without any locking on hash/ref_count; we can do that because delete_handler is only entered after the delete timer was installed from wait_handler, which removed transaction from hash table and did not destroy it because some processes were using it; that means that the processes currently using the transaction can unref and no new processes can ref -- we can wait until ref_count is zero safely without locking */ ret = delete_cell(p_cell, 0 /* don't unlock on return */); } else { /* stop cancel timers if any running */ if(is_invite(p_cell)) cleanup_localcancel_timers(p_cell); /* remove the cell from the hash table */ LOCK_HASH(p_cell->hash_index); remove_from_hash_table_unsafe(p_cell); p_cell->flags |= T_IN_AGONY; /* delete (returns with UNLOCK-ed_HASH) */ ret = delete_cell(p_cell, 1 /* unlock on return */); } #endif /* TM_DEL_UNREF */ return ret; }
inline static void delete_handler( struct timer_link *dele_tl ) { struct cell *p_cell; p_cell = get_dele_timer_payload( dele_tl ); LM_DBG("removing %p \n", p_cell ); #ifdef EXTRA_DEBUG if (p_cell->damocles==0) { LM_ERR("transaction %p not scheduled for deletion" " and called from DELETE timer\n",p_cell); abort(); } #endif /* we call delete now without any locking on hash/ref_count; we can do that because delete_handler is only entered after the delete timer was installed from wait_handler, which removed transaction from hash table and did not destroy it because some processes were using it; that means that the processes currently using the transaction can unref and no new processes can ref -- we can wait until ref_count is zero safely without locking */ delete_cell( p_cell, 0 /* don't unlock on return */ ); LM_DBG("done\n"); }
inline static void wait_handler( struct timer_link *wait_tl ) { struct cell *p_cell; p_cell = get_wait_timer_payload( wait_tl ); #ifdef EXTRA_DEBUG if (p_cell->damocles) { LM_ERR("transaction %p scheduled for deletion and" " called from WAIT timer\n",p_cell); abort(); } LM_DBG("WAIT timer hit\n"); #endif /* stop cancel timers if any running */ if ( is_invite(p_cell) ) cleanup_localcancel_timers( p_cell ); /* the transaction is already removed from WT_LIST by the timer */ /* remove the cell from the hash table */ LM_DBG("removing %p from table \n", p_cell ); LOCK_HASH( p_cell->hash_index ); remove_from_hash_table_unsafe( p_cell ); /* jku: no more here -- we do it when we put a transaction on wait */ #ifdef EXTRA_DEBUG p_cell->damocles = 1; #endif /* delete (returns with UNLOCK-ed_HASH) */ delete_cell( p_cell, 1 /* unlock on return */ ); LM_DBG("done\n"); }
void delete_board(sudoku_board board, int side){ int i, j; for (i=0; i<side; ++i) { for (j=0; j<side; ++j) { delete_cell(&board[i][j], side); } free(board[i]); } free(board); }
void CreateHexCore::transferOctreeGrid() { QVector<bool> delete_node(m_Octree.getNumNodes(), false); QVector<bool> delete_cell(m_Octree.getNumCells(), false); for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) { vec3_t x; m_Grid->GetPoint(id_node, x.data()); int i_cell = m_Octree.findCell(x); if (m_Octree.hasChildren(i_cell)) { EG_BUG; } delete_cell[i_cell] = true; for (int i = 0; i < 8; ++i) { delete_node[m_Octree.getNode(i_cell, i)] = true; } } for (int layer = 0; layer < m_NumBreakOutLayers; ++layer) { for (int i = 0; i < m_Octree.getNumCells(); ++i) { if (delete_cell[i] && !m_Octree.hasChildren(i)) { for (int j = 0; j < 8; ++j) { delete_node[m_Octree.getNode(i,j)] = true; } } } for (int i = 0; i < m_Octree.getNumCells(); ++i) { if (!m_Octree.hasChildren(i)) { for (int j = 0; j < 8; ++j) { if (delete_node[m_Octree.getNode(i,j)]) { delete_cell[i] = true; break; } } } } } EG_VTKSP(vtkUnstructuredGrid, otgrid); m_Octree.toVtkGridPolyhedral(otgrid, true); //m_Octree.toVtkGridConforming(otgrid, true); MeshPartition add_part(otgrid); QList<vtkIdType> add_cells; for (vtkIdType id_cell = 0; id_cell < otgrid->GetNumberOfCells(); ++id_cell) { int i_cell = m_Octree.findCell(cellCentre(otgrid, id_cell)); if (!delete_cell[i_cell]) { add_cells.append(id_cell); } } add_part.setCells(add_cells); m_Part.addPartition(add_part); m_Part.setAllCells(); deleteOutside(m_Grid); }
void player_choice(char current_board[BOARD_SIZE][BOARD_SIZE], char future_board[BOARD_SIZE][BOARD_SIZE], char player) //function used to interpret the player's choice { int row = 0; int column = 0; int i = 0; int j = 0; switch(player) { case 'a': //adding a cell case 'A': printf("Inserting a cell.\n"); printf("Enter a row (any positive int < 40): "); scanf("%d", &row); if((row < 0) || (row > 40)) { printf("Invalid input.\n"); return; } printf("Enter a column (any positive int < 40): "); scanf("%d", &column); if((column < 0) || (column > 40)) { printf("Invalid input.\n"); return; } add_cell(future_board, row, column); //all edits are made to the future board change_board(current_board, future_board); //the boards a switched (current board is updated) printf("\033[2J\033[H"); print_board(current_board); //current board is printed break; case 'r': //removing a cell case 'R': printf("Removing a cell.\n"); printf("Enter a row (any positive int < 40): "); scanf("%d", &row); if((row < 0) || (row > 40)) { printf("Invalid input.\n"); return; } printf("Enter a column (any positive int < 40): "); scanf("%d", &column); if((column < 0) || (column > 40)) { printf("Invalid input.\n"); return; } delete_cell(future_board, row, column); change_board(current_board, future_board); printf("\033[2J\033[H"); print_board(current_board); break; case 'n': //applying the rules of the game case 'N': for(i = 0; i < BOARD_SIZE; i++) //the functions will read the current board but will apply the changes to the future board { for(j = 0; j < BOARD_SIZE; j++) { life_or_death(current_board, future_board, i, j, check_neighbors(current_board, i, j)); } } change_board(current_board, future_board); //boards are switched printf("\033[2J\033[H"); print_board(current_board); break; default: return; break; } return; }
int main() { int i; char chose[MAXLEN]; struct cell_f **f; struct cell_c **c; struct cell_f *head_f = NULL; struct cell_c *head_c = NULL; struct cell_f *h_f = NULL; FILE *fp_f, *fp_c; printf("Welcome!\n"); if ((fp_f = fopen("original_file.dat", "r")) == NULL) { fprintf(stderr, "Cannot open file: original_filet.dat\n"); return; } if ((fp_c = fopen("category_list.dat", "r")) == NULL) { fprintf(stderr, "Cannot open file: category_list.dat\n"); return; } f = make_original_file_list(&head_f, fp_f); c = make_original_category_list(&head_c, fp_c); i = 0; while(i != 1) { printf("機能一覧を表示します。\n"); printf("0: 新規ファイルの登録 \n1: 既存ファイルの削除 \n2: 任意のファイル、任意の項目への修正 \n3: 既存のファイルの検索 \n4: 新たな分類項目の追加 \n5: 既存の分類項目の削除 \n6: 任意のファイルのコメント抽出\n"); printf(">"); scanf("%s", chose); if(strlen(chose) > 1) { printf("入力エラーです。\n"); continue; } switch (chose[0]) { case '0': insert_cell_file(c, f); break; case '1': delete_file(f); break; case '2': rename_file(f); break; case '3': search_f(&h_f, f); delete_cell(&h_f); break; case '4': insert_cell_category(c); break; case '5': delete_category(c); break; case '6': sub_function(f); break; default: printf("入力エラーです。\n"); break; } printf("アプリケーションの実行を続けますか?\n"); printf("0: Yes 1: No\n"); printf(">"); scanf("%d", &i); while(i != 0 && i != 1) { printf("アプリケーションの実行を続けますか?\n"); printf("0: Yes 1: No\n"); printf(">"); scanf("%d", &i); } } fclose(fp_f); fclose(fp_c); if ((fp_f = fopen("original_file.dat", "w")) == NULL) { fprintf(stderr, "Cannot open file: original_filet.dat\n"); return; } if ((fp_c = fopen("category_list.dat", "w")) == NULL) { fprintf(stderr, "Cannot open file: original_filet.dat\n"); return; } while((*f) != NULL) { fprintf(fp_f, "%s %s %s %s %d\n", (*f)->main_title, (*f)->sub_title, (*f)->date, (*f)->path, (*f)->category); (*f) = (*f)->next; } while((*c) != NULL) { fprintf(fp_c, "%d %s\n", (*c)->number, (*c)->category); (*c) = (*c)->next; } fclose(fp_f); fclose(fp_c); return 0; }