Example #1
0
int set_contains(intset_t *set, val_t val, int transactional)
{
	int result = 0;
	void *v;

	v = (void *)val;
	
	switch(transactional) {
		case 0:	
			result = rbtree_contains(set, v);
			break;
			
		case 1: /* Normal transaction */	
			TX_START(NL);
			result = TMrbtree_contains(set, (void *)val);
			TX_END;
			break;
    
		case 2:
		case 3:
		case 4: /* Elastic transaction */
			TX_START(EL);
			result = TMrbtree_contains(set, (void *)val);
			TX_END;
			break;
			
		default:
			result=0;
			printf("number %d do not correspond to elasticity.\n", transactional);
			exit(1);
	}
	return result;
}
Example #2
0
int set_remove(intset_t *set, val_t val, int transactional)
{
	int result = 0;
	node_t *next;
	void *v;
	
	next = NULL;
	v = (void *) val;

	switch(transactional) {
		case 0: /* Unprotected */
			result = rbtree_delete(set, (void *)val);
			break;
			
		case 1: 
		case 2:
		case 3: /* Normal transaction */
			TX_START(NL);
			result = TMrbtree_delete(set, (void *)val);
			TX_END;
			break;
				
		case 4: /* Elastic transaction */
			TX_START(EL);
			result = TMrbtree_delete(set, (void *)val);
			TX_END;
			break;
			
		default:
			result=0;
			printf("number %d do not correspond to elasticity.\n", transactional);
			exit(1);
	}
	return result;
}
Example #3
0
/* 
 * Adding to the rbtree may require rotations (at least in this implementation)  
 * This operation requires strong dependencies between numerous transactional 
 * operations, hence, the use of normal transaction is necessary for safety.
 */ 
int set_add(intset_t *set, val_t val, int transactional)
{
  int result = 0;

  switch(transactional) {
	  case 0:
		  result = rbtree_insert(set, (void *)val, (void *)val);
		  break;
		  
	  case 1:
	  case 2: 	
	  case 3:
	  case 4:
		  TX_START(NL);
		  result = TMrbtree_insert(set, (void *)val, (void *)val);
		  TX_END;
		  break;
		  
	  default:
		  result=0;
		  printf("number %d do not correspond to elasticity.\n", transactional);
		  exit(1);
  }

  return result;
}
Example #4
0
int set_remove(intset_t *set, val_t val, int transactional)
{
	int result = 0;
	
#ifdef DEBUG
	printf("++> set_remove(%d)\n", (int)val);
	IO_FLUSH;
#endif
	
#ifdef SEQUENTIAL /* Unprotected */
	
	node_t *prev, *next;

	prev = set->head;
	next = prev->next;
	while (next->val < val) {
		prev = next;
		next = prev->next;
	}
	result = (next->val == val);
	if (result) {
		prev->next = next->next;
		free(next);
	}
			
#elif defined STM
	
	node_t *prev, *next;
	val_t v;
	node_t *n;
	TX_START(EL);
	prev = set->head;
	next = (node_t *)TX_LOAD(&prev->next);
	while (1) {
		v = TX_LOAD((uintptr_t *) &next->val);
		if (v >= val)
			break;
		prev = next;
		next = (node_t *)TX_LOAD(&prev->next);
	}
	result = (v == val);
	if (result) {
		n = (node_t *)TX_LOAD(&next->next);
		TX_STORE(&prev->next, n);
		FREE(next, sizeof(node_t));
	}
	TX_END;
	
#elif defined LOCKFREE
	result = harris_delete(set, val);
#endif
	
	return result;
}
Example #5
0
int set_add(intset_t *set, val_t val, int transactional)
{
	int result = 0;
	
#ifdef DEBUG
	printf("++> set_add(%d)\n", (int)val);
	IO_FLUSH;
#endif

	if (!transactional) {
		
		result = set_seq_add(set, val);
		
	} else { 
	
#ifdef SEQUENTIAL /* Unprotected */
		
		result = set_seq_add(set, val);
		
#elif defined STM
	
		node_t *prev, *next;
		val_t v;	
		TX_START(EL);
		prev = set->head;
		next = (node_t *)TX_LOAD(&prev->next);
		while (1) {
			v = TX_LOAD((uintptr_t *) &next->val);
			if (v >= val)
				break;
			prev = next;
			next = (node_t *)TX_LOAD(&prev->next);
		}
		result = (v != val);
		if (result) {
			TX_STORE(&prev->next, new_node(val, next, transactional));
		}
		TX_END;

#elif defined LOCKFREE
		result = harris_insert(set, val);
#endif
		
	}
	
	return result;
}
Example #6
0
/*! \brief Configures baud rate (refer datasheet) */
void initUART(void)
{
  // Not necessary; initialize anyway
  DDRD |= _BV(PD1);
  DDRD &= ~_BV(PD0);

  // Set baud rate; lower byte and top nibble
  UBRR0H = ((_UBRR) & 0xF00);
  UBRR0L = (uint8_t) ((_UBRR) & 0xFF);

  TX_START();
  RX_START();

  // Set frame format = 8-N-1
  UCSR0C = (_DATA << UCSZ00);

}
Example #7
0
int set_contains(intset_t *set, val_t val, int transactional)
{
	int result;
	
#ifdef DEBUG
	printf("++> set_contains(%d)\n", (int)val);
	IO_FLUSH;
#endif
	
#ifdef SEQUENTIAL
	node_t *prev, *next;
	
	prev = set->head;
	next = prev->next;
	while (next->val < val) {
		prev = next;
		next = prev->next;
	}
	result = (next->val == val);

#elif defined STM			

	node_t *prev, *next;
	val_t v = 0;

	TX_START(EL);
	prev = set->head;
	next = (node_t *)TX_LOAD(&prev->next);
	while (1) {
		v = TX_LOAD((uintptr_t *) &next->val);
		if (v >= val)
			break;
		prev = next;
		next = (node_t *)TX_LOAD(&prev->next);
	}		  
	TX_END;
	result = (v == val);
			
#elif defined LOCKFREE			
	result = harris_find(set, val);
#endif	
	
	return result;
}
Example #8
0
int set_move(intset_t *set, val_t val1, val_t val2, int transactional) {
  int result;

  if(transactional != 0) {
    TX_START(NL);
  }
  result = 0;
  if(!set_contains(set, val2, transactional)) {
    if(set_remove(set, val1, transactional)) {
      set_add(set, val2, transactional);
      result = 1;
    }
  }
  if(transactional != 0) {
    TX_END;
  }

  return result;
}
Example #9
0
int probe(gen_state_t *state, FILE *out)
{
    rvm_txid_t txid;
    probe_state_t *pstate;

    assert(state->phase == PROBE);

    if(state->pstate == NULL) {
        TX_START(txid);
        state->pstate = rvm_alloc(cfg, sizeof(probe_state_t));
        CHECK_ERROR(state->pstate == NULL,
                ("Failed to allocate probe state\n"));
        pstate = (probe_state_t*)state->pstate;
        pstate->curStartNode = state->start_list;
        pstate->cur_kmr = state->start_list->kmerPtr;
        pstate->posInContig = 0;
        pstate->floc = 0;
        pstate->nkmer_proc = 0;
        TX_COMMIT(txid);

        printf("Allocated probe state\n");

    } else {
        pstate = (probe_state_t*)state->pstate;
        printf("Probe restarting from kmer %ld\n", pstate->nkmer_proc);

        /* Seek to the correct output location in file */
        fseek(out, pstate->floc, SEEK_SET);
    }

    char unpackedKmer[KMER_LENGTH+1];

    while (pstate->curStartNode != NULL ) {
        
        /* Starting a new contig. This may not be true if we are recovering
           from a failure. */
        if(pstate->posInContig == 0) {
            TX_START(txid);

            pstate->cur_kmr = pstate->curStartNode->kmerPtr;

            /* Need to unpack the seed first */
            unpackSequence((unsigned char*) pstate->cur_kmr->kmer,
                    (unsigned char*) unpackedKmer, KMER_LENGTH);

            /* Initialize current contig with the seed content */
            memcpy(pstate->cur_contig, unpackedKmer, KMER_LENGTH * sizeof(char));
            pstate->posInContig = KMER_LENGTH;

            pstate->nkmer_proc++;

            if(pstate->nkmer_proc % PRINT_FREQ == 0) 
               printf("Probe kmer %ld\n", pstate->nkmer_proc);

            if(pstate->nkmer_proc % cp_freq == 0) {
                TX_COMMIT(txid);
            }

            if(pstate->nkmer_proc % fa_freq == 0) {
                printf("Simulating probe failure after %ldth kmer\n", pstate->nkmer_proc);
                exit(EXIT_FAILURE);
            }
        }

       /* Keep adding bases until we find a terminal node */
       char right_ext = pstate->cur_kmr->r_ext;
       while (right_ext != 'F') {
           TX_START(txid);

           pstate->cur_contig[pstate->posInContig] = right_ext;
           pstate->posInContig++;
           /* At position cur_contig[posInContig-KMER_LENGTH] starts the
            * last k-mer in the current contig */
           unsigned char *nextKmer = (unsigned char *)
                   &(pstate->cur_contig[pstate->posInContig - KMER_LENGTH]);
           pstate->cur_kmr = lookup_kmer(state->tbl, nextKmer);
           CHECK_ERROR(pstate->cur_kmr == NULL,
                   ("Couldn't find kmer %ld in hash table\n", pstate->nkmer_proc));

           right_ext = pstate->cur_kmr->r_ext;

           pstate->nkmer_proc++;

           if(pstate->nkmer_proc % PRINT_FREQ == 0) 
               printf("Probe kmer %ld\n", pstate->nkmer_proc);

           if(pstate->nkmer_proc % cp_freq == 0) {
               TX_COMMIT(txid);
           }

           if(pstate->nkmer_proc % fa_freq == 0) {
               printf("Simulating probe failure after %ldth kmer\n", pstate->nkmer_proc);
               exit(EXIT_FAILURE);
           }
       }

       /* Move on to the next contig */
       /* Print the contig since we have found the corresponding terminal node */
       pstate->cur_contig[pstate->posInContig] = '\0';
       pstate->floc += fprintf(out,"%s\n", pstate->cur_contig);

       /* Move to the next start node in the list */
       pstate->curStartNode = pstate->curStartNode->next;
       pstate->posInContig = 0;
   }

    return 1;
}