static void * trygo( void * arg) { lladdIterator_t * it = (lladdIterator_t *) arg; pthread_mutex_lock(&mutex); pthread_mutex_unlock(&mutex); int itRet = 0; assert(it->type >= 0 && it->type < MAX_ITERATOR_TYPES); while((itRet = Titerator_tryNext(-1, it))) { assert(it->type >= 0 && it->type < MAX_ITERATOR_TYPES); byte * key, * value; int keySize, valueSize; keySize = Titerator_key (-1, it, &key); valueSize = Titerator_value(-1, it, &value); assert(keySize == sizeof(lsn_t)); LogEntry * e = (LogEntry*)value; linearHash_remove_arg * arg = (linearHash_remove_arg*)stasis_log_entry_update_args_ptr(e); assert(arg->keySize == sizeof(lsn_t)); assert(arg->valueSize == sizeof(char)); lsn_t i = *(lsn_t*)(arg+1); array[i]++; assert(*(lsn_t*)key == i); assert(array[i] == 1); Titerator_tupleDone(-1, it); } return NULL; }
/** Take two iterators, and make sure they represent the same set. */ static void iterator_test(int xid, lladdIterator_t * reference_impl, lladdIterator_t * tested_impl) { pblHashTable_t * hash = pblHtCreate(); int numEntries = 0; while(Titerator_next(xid, reference_impl)) { int keySize, valSize; byte *key, *val, *valScratch; keySize = Titerator_key(xid, reference_impl, &key); valSize = Titerator_value(xid, reference_impl, &valScratch); val = stasis_malloc(valSize, byte); memcpy(val, valScratch, valSize); // pblHtInsert stores values a pointers to application managed memory. pblHtInsert(hash, key, keySize, val); numEntries ++; } while(Titerator_next(xid, tested_impl)) { numEntries --; int keySize, valSize; byte *key, *val, *valScratch; keySize = Titerator_key(xid, tested_impl, &key); valSize = Titerator_value(xid, tested_impl, &valScratch); val = pblHtLookup(hash, key, keySize); assert(val); assert(!memcmp(val, valScratch, valSize)); free(val); pblHtRemove(hash, key, keySize); } assert(!numEntries); }
JNIEXPORT jbyteArray JNICALL Java_stasis_jni_Stasis_iterator_1key (JNIEnv *e, jclass c, jlong xid, jbyteArray jbait) { size_t sz; lladdIterator_t** it = (lladdIterator_t**)bytes_jbyteArray(e,jbait,&sz); byte * key; sz = Titerator_key(xid, *it, &key); return jbyteArray_bytes(e,key,sz); }