예제 #1
0
SortedList<T, Pred>::~SortedList() throw()
{
	destroyAllNodes(head_);
	if (freeAllocator_)
	{
		destroyAllocator();
	}
}
예제 #2
0
SortedList<T, Pred>& SortedList<T, Pred>::operator=(const SortedList &rhs) throw(SortedListException)
{
	// Special case, check for self-assignment and short circuit if true.
	if (this == &rhs)
	{
		return(*this);
	}

	if (rhs.shareAllocator_)
	{
		// We may have to get rid of an existing allocator.
		if (freeAllocator_)
		{
			destroyAllocator();
		}

		freeAllocator_ = false;
		shareAllocator_ = true;
		objAllocator_ = rhs.objAllocator_;
	}
	else
	{
		// Well, we already have an existing allocator, so...
		// I don't think we want to create a new one.
		// So, use an old one.
		shareAllocator_ = false;
//		OAConfig new_config(true); // Use CPP mem manager.
//		objAllocator_ = createAllocator(new_config);
	}

	sorter_ = rhs.sorter_;

	// Gank everything!
	destroyAllNodes(head_);
	// Build dummy head and tail nodes.
/*	head_ = allocNode();
	tail_ = allocNode();*/

	head_ = createNode(0);
	tail_ = createNode(0);

	// Everything's good, link'em.
	head_->Prev = NULL;
	head_->Next = tail_;

	tail_->Prev = head_;
	tail_->Next = NULL;

	copyNodes(rhs);
	// All done.
	
	return(*this);
}
int main(int argc, char *argv[]) {
	int numThreads, time, initListSize, elementsRange;
	Input input = parseArgs(argc, argv, &numThreads, &time, &initListSize, &elementsRange);

	struct allocator allocator;
	int allocSize = HEAP_SIZE;
#if !defined(OA)
	allocSize = 6000000;//15000000
#elif defined(MOA)
	allocSize=(numThreads>32 || (numThreads==32 && input.fractionInserts>0.2))?50000:allocSize; //for 32 threads a heap of 20000 items is too small.
#endif
	init_allocator(&allocator, lalloc, numThreads, dirties, allocSize, HPsPerThread);
#ifdef HASH_OP
	int logLen=0, size=(int)(initListSize/LOAD_FACTOR);
	while(size/=2) logLen++;
	assert(logLen!=0);//don't know why, but the HASH don't work well.
	if(logLen<9) logLen=9;
	assert(1<<logLen >= ARR_ENTRIES_PER_BIT);
	initHash(&hash, logLen);
#endif

	for (int i = 0; i < numThreads; i++) {
		tg[i].input = input;
		tg[i].input.threadID		= i;
		tg[i].dirty = dirties+i;
		tg[i].entryAllocator = lalloc+i;
	} // end of for loop, initializing the threads data

	initialize_ds(initListSize, elementsRange, tg);

	for (int i = 0; i < numThreads; i++) {
		if(pthread_create(&workerThreads[i], NULL, start_routine, &tg[i])){
			printf("Error occurred when creating thread %d\n", i);
			exit(1);
		}
	}
	////////////START TEST
	run = TRUE; __sync_synchronize();
	sleep(time);
	stop=TRUE;  __sync_synchronize();
	////////////END TEST

	for (int i=0; i< numThreads; ++i) {			// join all threads
		pthread_join(workerThreads[i], NULL);
	}
	//TIME g_timer_stop(t);

#ifndef MALLOC
	destroyAllocator(&allocator);
#endif
#if defined(OA)
	int numPhases = allocator.phase.phase/2-INIT_PHASE;
#else
	int numPhases = 0;
#endif
	num_ops = (long long)num_ops / (long double)time;
	const double M=1000000;
	printf(HG_VER "Threads=%d, Thpt=%ld, ThptM=%.1f, Phases=%d, Time=%f, InitSize=%d, Range=%d, SearchFrac=%.2f\n",
			numThreads, num_ops, num_ops/M, numPhases, (double)time, initListSize, elementsRange,
			1-tg[0].input.fractionInserts-tg[0].input.fractionDeletes);
	printf("___ %ld %d %.2f\n", num_ops, numThreads, 1-tg[0].input.fractionInserts-tg[0].input.fractionDeletes);
#if !defined(MOA) && !defined(OA)
extern int alcctr;
printf("alcctr = %d\n", alcctr);
//extern int m;
//printf("m =%d\n", m);
#endif
	//TIME printf("___ %f %d %.2f\n", totalTime, numThreads, 1 - atof(argv[6]) - atof(argv[5]));
	return 0;
}