TM_CALLABLE void remove(int val TM_ARG) { //std::cout << " val " << val << std::endl; //bool found = false; uint32_t buck = val % N_BUCKETS; //std::cout << "cuck " << buck << std::endl; uint32_t slots = TM_READ(bucket_entries[buck]); //std::cout << slots << " slots " << std::endl; if(slots>0){ for(uint32_t i = 0; i<slots ; i++){ if(val==TM_READ(bucket[buck][i]) && val !=0 ){ //TM_WRITE(bucket[buck][i], 0); TM_WRITE(bucket_entries[buck], TM_READ(bucket_entries[buck])-1); //found = true; for(uint32_t e = i; e<slots; e++){ TM_WRITE(bucket[buck][e], TM_READ(bucket[buck][e+1])); //shift the remainder elements to the left } break; } } } //if(!found) std::cout << "not present" << val << std::endl; //else std::cout << "PRESENT" << val << std::endl; }
TM_CALLABLE bool lookup(int val TM_ARG) const { bool found =false; uint32_t buck = val % N_BUCKETS; uint32_t slots = TM_READ(bucket_entries[buck]); for(uint32_t i = 0; i<slots ; i++){ if(val==TM_READ(bucket[buck][i])) found =true; } return found; }
TM_CALLABLE void insert(int val TM_ARG) { //std::cout << " n buck " << N_BUCKETS << std::endl; uint32_t buck = val % N_BUCKETS; uint32_t slots = TM_READ(bucket_entries[buck])+1; TM_WRITE(bucket_entries[buck], slots); TM_WRITE(bucket[buck][slots], val); }
bool Disjoint::ro_transaction(uint32_t id, uint32_t startpoint TM_ARG) { PaddedBuffer& rBuffer = use_shared_read_buffer ? publicBuffer : privateBuffers[id]; unsigned sum = 0; unsigned index = startpoint; for (unsigned i = 0; i < locations_per_transaction; i++) { sum += TM_READ(rBuffer.buffer[index].value); // compute the next index index = (index + 1) % DJBUFFER_SIZE; } return (sum == 0); }
/*** Run a bunch of random transactions */ void bench_test(uintptr_t, uint32_t* seed) { // cache the seed locally so we can restore it on abort // // NB: volatile needed because using a non-volatile local in conjunction // with a setjmp-longjmp control transfer is undefined, and gcc won't // allow it with -Wall -Werror. volatile uint32_t local_seed = *seed; TM_BEGIN(atomic) { for (uint32_t i = 0; i < CFG.ops; ++i) { uint32_t loc = rand_r_32(&local_seed) % CFG.elements; TM_WRITE(matrix[loc], 1 + TM_READ(matrix[loc])); } } TM_END; *seed = local_seed; }
TM_CALLABLE bool iterate(int val TM_ARG) const { //std::cout << "start iterate " << std::endl; bool found =false; for(uint32_t e = 0; e<N_BUCKETS; e++){ // if(e>N_BUCKETS-3)std::cout << "hey we made it !! " << e<< std::endl; uint32_t buck = e;// % N_BUCKETS; uint32_t slots = N_SLOTS;//TM_READ(bucket_entries[buck]); for(uint32_t i = 0; i<slots ; i++){ val+=TM_READ(bucket[buck][i]); } } // std::cout << "end iterate " << std::endl; if(val>25000) return true; else return false; }
/*** Run a bunch of random transactions */ void bench_test(uintptr_t id, uint32_t* seed) { uint32_t loc[1024]; int snapshot[1024]; //determine the locations prior to the transaction for(uint32_t i = 0; i < CFG.ops; i++) { uint32_t r = rand_r(seed) % CFG.elements; local_mats[id][r]++; loc[i] = r; } TM_BEGIN(atomic) { for (uint32_t i = 0; i < CFG.ops; ++i) { snapshot[i] = TM_READ(matrix[loc[i]]); } for (uint32_t i = 0; i < CFG.ops; ++i) { TM_WRITE(matrix[loc[i]], 1 + snapshot[i]); } } TM_END; }