コード例 #1
0
ファイル: zgt_tx.C プロジェクト: abhi389/transaction_manager
void *begintx(void *arg){
  //Initialize a transaction object. Make sure it is
  //done after acquiring the semaphore for the tm and making sure that 
  //the operation can proceed using the condition variable. when creating
  //the tx object, set the tx to TR_ACTIVE and obno to -1; there is no 
  //semno as yet as none is waiting on this tx.
  
    struct param *node = (struct param*)arg;// get tid and count
    start_operation(node->tid, node->count); 
	printf("begin is here");
    zgt_tx *tx = new zgt_tx(node->tid,TR_ACTIVE, node->Txtype, pthread_self());	// Create new tx node
	open_logfile_for_append();
    fprintf(logfile, "T%d\t%c \tBeginTx\n", node->tid, node->Txtype);	// Write log record and close
    fflush(logfile);
  
    zgt_p(0);				// Lock Tx manager; Add node to transaction list
  
    tx->nextr = ZGT_Sh->lastr;
    ZGT_Sh->lastr = tx;   
    zgt_v(0); 			// Release tx manager 
  
  finish_operation(node->tid);
  pthread_exit(NULL);				// thread exit

}
コード例 #2
0
ファイル: zgt_tx.C プロジェクト: abhi389/transaction_manager
void *writetx(void *arg){ //do the operations for writing; similar to readTx
  struct param *node = (struct param*)arg;	// struct parameter that contains
  start_operation(node->tid, node->count); 
  //do the operations for writing; similar to readTx. Write your code
  zgt_p(0);				// Lock Tx manager; 
  zgt_tx *txptr=get_tx(node->tid);
  if(txptr != NULL){
		txptr->print_tm();
		if(txptr->status == TR_ABORT){//tx is aborted
			fprintf(logfile, "T%d\t%c \tWriteTx\n", node->tid, node->Txtype);	// Write log record and close
			fflush(logfile);
			zgt_v(0); 			// Release tx manager
		}
		else if(txptr->status == TR_ACTIVE){//Tx is active
			zgt_v(0); 			// Release tx manager
			int isLockObtain=txptr->set_lock(node->tid, txptr->sgno,node->obno, node->count,'X');//check is lock available
			if(isLockObtain == 0){//Lock is obtain for tx
				txptr->perform_readWrite(txptr->tid,node->obno,'X');
			}
		}
	
	}
  else {
	zgt_v(0); 			// Release tx manager 
	printf("Tx is not found it might be committed or not begin at all");
  }
  finish_operation(node->tid);
  pthread_exit(NULL);				// thread exit
}
コード例 #3
0
ファイル: zgt_tx.C プロジェクト: abhi389/transaction_manager
void *aborttx(void *arg)
{
  struct param *node = (struct param*)arg;// get tid and count  
  start_operation(node->tid, node->count);
  zgt_p(0);  //locking the transaction manager
  do_commit_abort(node->tid,TR_ABORT);
  zgt_v(0);  // releasing the transaction manager
  finish_operation(node->tid);
  pthread_exit(NULL);			// thread exit
}
コード例 #4
0
ファイル: pagesim.c プロジェクト: innuendo/OS-task-3
int page_sim_set(unsigned a, uint8_t v)
{
    unsigned offset;
    page * current_page = get_page_wrapper(a, &offset);
    current_page->meta->modified = true;
    if (!current_page) return ERROR;
    /* mutex already gained! */
    current_page->data[offset] = v;
    return finish_operation(current_page);
}
コード例 #5
0
ファイル: zgt_tx.C プロジェクト: abhi389/transaction_manager
void *committx(void *arg)
{
 //remove the locks before committing
  struct param *node = (struct param*)arg;// get tid and count
  start_operation(node->tid, node->count);
  zgt_tx *txptr=get_tx(node->tid);
  zgt_p(0); // locking the transaction manager
  txptr->status=TR_END;
  do_commit_abort(node->tid,TR_END);
  zgt_v(0);  // releasing the transaction manager
  finish_operation(node->tid);
  pthread_exit(NULL);			// thread exit
}
コード例 #6
0
ファイル: pagesim.c プロジェクト: innuendo/OS-task-3
int page_sim_get(unsigned a, uint8_t *v)
{
    unsigned offset;
    page * current_page = get_page_wrapper(a, &offset);
    if (!current_page)
    {
        pthread_mutex_unlock(&current_page->meta->lock);
        return ERROR;
    } 
        /* mutex already gained! */
    *v = current_page->data[offset];
    return finish_operation(current_page);
}
コード例 #7
0
ファイル: format-dialog.c プロジェクト: paulcbetts/gformat
void
do_next_operation(FormatDialog* dialog, const gchar* progress_text)
{
	if(dialog->format_error) {
		handle_format_error(dialog);
		return;
	}

	if(dialog->ops_left <= 0) {
		finish_operation(dialog);
		return;
	}

	gdouble percent = (gdouble)(dialog->total_ops - dialog->ops_left) / (gdouble)dialog->total_ops;
	dialog->ops_left--;
	gtk_progress_set_value(GTK_PROGRESS(dialog->progress_bar), percent);
}
コード例 #8
0
ファイル: format-dialog.c プロジェクト: paulcbetts/gformat
void 
handle_format_error(FormatDialog* dialog)
{
	show_error_dialog(dialog->toplevel, _("Error formatting device"), dialog->format_error->message);
	finish_operation(dialog);
}