void set_tls_data(int32_t key,void *data) { hash_map_t h = (hash_map_t)pthread_getspecific(thread_key); if(!h) { h = hash_map_create(128,sizeof(key),sizeof(void*),tls_hash_func,tls_hash_key_eq,0); } hash_map_iter it = hash_map_find(h,(void*)&key); if(0 == hash_map_is_vaild_iter(it)) HASH_MAP_INSERT(int32_t,void*,h,key,data); else hash_map_iter_set_val(it,data); }
void set_tls_data(int32_t key,void *data) { hash_map_t h = (hash_map_t)pthread_getspecific(thread_key); if(!h) { h = hash_map_create(128,sizeof(key),sizeof(void*),tls_hash_func,tls_hash_key_eq); } hash_map_iter it = hash_map_find(h,(void*)&key); hash_map_iter end = hash_map_end(h); if(IT_EQ(it,end)) HASH_MAP_INSERT(int32_t,void*,h,key,data); else IT_SET_VAL(void*,it,data); }
void *get_tls_data(int32_t key) { hash_map_t h = (hash_map_t)pthread_getspecific(thread_key); if(!h) { h = hash_map_create(128,sizeof(key),sizeof(void*),tls_hash_func,tls_hash_key_eq); return NULL; } hash_map_iter it = hash_map_find(h,(void*)&key); hash_map_iter end = hash_map_end(h); if(!IT_EQ(it,end)) return IT_GET_VAL(void*,it); return NULL; }
void *get_tls_data(int32_t key) { hash_map_t h = (hash_map_t)pthread_getspecific(thread_key); if(!h) { h = hash_map_create(128,sizeof(key),sizeof(void*),tls_hash_func,tls_hash_key_eq,0); return 0; } hash_map_iter it = hash_map_find(h,(void*)&key); if(0 == hash_map_is_vaild_iter(it)) { return hash_map_iter_get_val(it); } return 0; }
void* dict_get(dict* d, char *key) { #ifdef TSTC dict_entry *e = 0; int r = tstc_find(d->dict, key, (void*)&e); if (r) { return e->v; } return e; #elif defined (HASHMAP) return hash_map_find(d->dict, key, strlen(key)); #else return (void*) tst_search(d->dict, key); #endif }
void run() { unsigned i, time; gasnett_tick_t start, end; hash_map_create(params[HASHMAP_SIZE], (grt_bool_t) params[ON_PTHREAD]); grt_barrier(); #ifdef LOCKS grt_lock_state_t state; #endif for (i = 0; i < MY_NUM_OPS; ++i) { grt_word_t key = keys[i], val = values[i]; #ifdef LOCKS hash_t hash = compute_hash(key); hash_map_lock(hash.proc, hash.offset, WRITE, &state); #endif hash_map_insert(key, val); #ifdef LOCKS hash_map_unlock(hash.proc, hash.offset); #endif } BARRIER(); start = gasnett_ticks_now(); #ifdef LOCKS grt_lock_state_t state1, state2; #endif for (i = 0; i < MY_NUM_OPS; ++i) { unsigned idx = grt_random_next() * MY_NUM_OPS; grt_word_t key1 = keys[i]; unsigned second_idx = grt_random_next() * MY_NUM_OPS; grt_word_t key2 = keys[second_idx]; #ifdef LOCKS lock(key1, key2, &state1, &state2); #endif grt_word_t val1, val2; #ifndef LOCKS #ifndef NOLOCKS stm_start(grt_id); #endif #endif grt_bool_t found1 = hash_map_find(key1, &val1); grt_bool_t found2 = hash_map_find(key2, &val2); hash_map_insert(key1, val2); hash_map_insert(key2, val1); #ifndef LOCKS #ifndef NOLOCKS stm_commit(grt_id); #endif #endif #if LOCKS unlock(key1, key2); #endif } end = gasnett_ticks_now(); time = ((unsigned) gasnett_ticks_to_us(end - start)); printf("processor %u: execution time=%f us\n", grt_id, (double) time); fflush(stdout); grt_write(0, time, ×[grt_id]); BARRIER(); if (grt_id == 0) { time = 0, max_time = 0; for (i = 0; i < grt_num_procs; ++i) { gasnett_tick_t this_time = times[i]; time += this_time; if (this_time >= max_time) max_time = this_time; } time_per_op = ((float) time) / params[NUM_OPS]; printf("total CPU time=%f us\n", (double) time); printf("time per operation=%f us\n", time_per_op); printf("max time=%f us\n", (double) max_time); } BARRIER(); hash_map_destroy(); BARRIER(); }