[llvm-commits] [poolalloc] r108894 - in /poolalloc/trunk/runtime/FL2Allocator: PoolAllocator.cpp PoolAllocator.h

Patrick Simmons simmon12 at illinois.edu
Tue Jul 20 12:49:19 PDT 2010


Author: psimmons
Date: Tue Jul 20 14:49:19 2010
New Revision: 108894

URL: http://llvm.org/viewvc/llvm-project?rev=108894&view=rev
Log:
PoolAlloc runtime fixes for multithreading

Modified:
    poolalloc/trunk/runtime/FL2Allocator/PoolAllocator.cpp
    poolalloc/trunk/runtime/FL2Allocator/PoolAllocator.h

Modified: poolalloc/trunk/runtime/FL2Allocator/PoolAllocator.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/runtime/FL2Allocator/PoolAllocator.cpp?rev=108894&r1=108893&r2=108894&view=diff
==============================================================================
--- poolalloc/trunk/runtime/FL2Allocator/PoolAllocator.cpp (original)
+++ poolalloc/trunk/runtime/FL2Allocator/PoolAllocator.cpp Tue Jul 20 14:49:19 2010
@@ -483,6 +483,7 @@
                               unsigned DeclaredSize, unsigned ObjAlignment) {
   assert(Pool && "Null pool pointer passed into poolinit!\n");
   memset(Pool, 0, sizeof(PoolTy<PoolTraits>));
+  Pool->thread_refcount = 1;
   pthread_mutex_init(&Pool->pool_lock,NULL);
   Pool->AllocSize = INITIAL_SLAB_SIZE;
 
@@ -524,6 +525,15 @@
 //
 void pooldestroy(PoolTy<NormalPoolTraits> *Pool) {
   assert(Pool && "Null pool pointer passed in to pooldestroy!\n");
+
+#ifdef USE_DYNCALL
+  __sync_fetch_and_add(&Pool->thread_refcount,-1);
+#else
+  Pool->thread_refcount--;
+#endif
+  if(Pool->thread_refcount)
+	  return;
+
   pthread_mutex_destroy(&Pool->pool_lock);
 
 #ifdef ENABLE_POOL_IDS
@@ -908,31 +918,58 @@
 {
 	void** arg = (void**)arg_;
 	DCCallVM* callVM = dcNewCallVM((size_t)arg[1]*sizeof(size_t)+108);
+	arg[2+(size_t)arg[1]+2] = callVM;
 	int i;
 	for(i=0; i<(size_t)arg[1]; i++)
 		dcArgPointer(callVM,arg[2+i]);
 	dcArgPointer(callVM,arg[2+i]);
 	void* to_return = dcCallPointer(callVM,arg[0]);
-	dcFree(callVM);
-	free(arg_);
 	return to_return;
 }
 
+void* poolalloc_thread_manager(void* args_)
+{
+	void** args = (void**)args_;
+	size_t num_pools = (size_t)args[1];
+
+        void* to_return;
+	pthread_join((pthread_t)(args[2+num_pools+1]),&to_return);
+
+	for(int i=0; i<num_pools; i++)
+		if(args[2+i])
+			pooldestroy((PoolTy<NormalPoolTraits>*)args[2+i]);
+
+	dcFree((DCCallVM*)args[2+num_pools+2]);
+	free(args);
+        return to_return;
+}
+
 int poolalloc_pthread_create(pthread_t* thread,
 							 const pthread_attr_t* attr,
 							 void *(*start_routine)(void*), int num_pools, ...)
 {
-	void** arg_array = (void**)malloc(sizeof(void*)*(3+num_pools));
+	void** arg_array = (void**)malloc(sizeof(void*)*(5+num_pools));
 	arg_array[0] = (void*)start_routine;
 	arg_array[1] = (void*)num_pools;
 	va_list argpools;
 	va_start(argpools,num_pools);
 	int i;
 	for(i=0; i<num_pools; i++)
+	{
 		arg_array[2+i]=va_arg(argpools,void*);
+		PoolTy<NormalPoolTraits>* pool_ptr = reinterpret_cast<PoolTy<NormalPoolTraits>*>(arg_array[2+i]);
+		if(pool_ptr)
+			__sync_fetch_and_add(&pool_ptr->thread_refcount,1);
+	}
 	arg_array[2+i]=va_arg(argpools,void*);
 	va_end(argpools);
-	return pthread_create(thread,attr,poolalloc_thread_start,arg_array);
+
+	pthread_t dummy;
+	int to_return = pthread_create(&dummy,attr,poolalloc_thread_start,arg_array);
+	arg_array[2+i+1] = (void*)(dummy);
+	to_return |= pthread_create(thread,NULL,poolalloc_thread_manager,arg_array);
+
+	return to_return;
 }
 
 #endif

Modified: poolalloc/trunk/runtime/FL2Allocator/PoolAllocator.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/runtime/FL2Allocator/PoolAllocator.h?rev=108894&r1=108893&r2=108894&view=diff
==============================================================================
--- poolalloc/trunk/runtime/FL2Allocator/PoolAllocator.h (original)
+++ poolalloc/trunk/runtime/FL2Allocator/PoolAllocator.h Tue Jul 20 14:49:19 2010
@@ -178,6 +178,9 @@
 
   // Lock for the pool
   pthread_mutex_t pool_lock;
+
+  // Thread reference count for the pool
+  int thread_refcount;
 };
 
 extern "C" {





More information about the llvm-commits mailing list