瀏覽代碼

starpu_task_bundle_destroy is now reentrant.

Nicolas Collin 13 年之前
父節點
當前提交
fc27d78f08
共有 3 個文件被更改,包括 13 次插入19 次删除
  1. 1 9
      src/core/task.c
  2. 11 2
      src/core/task_bundle.c
  3. 1 8
      src/sched_policies/heft.c

+ 1 - 9
src/core/task.c

@@ -97,15 +97,7 @@ void starpu_task_deinit(struct starpu_task *task)
 	/* If case the task is (still) part of a bundle */
 	starpu_task_bundle_t bundle = task->bundle;
 	if (bundle)
-	{
-		_STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);
-		int ret = starpu_task_bundle_remove(bundle, task);
-
-		/* Perhaps the bundle was destroyed when removing the last
-		 * entry */
-		if (ret != 1)
-			_STARPU_PTHREAD_MUTEX_UNLOCK(&bundle->mutex);
-	}
+		starpu_task_bundle_remove(bundle, task);
 
 	struct _starpu_job *j = (struct _starpu_job *)task->starpu_private;
 

+ 11 - 2
src/core/task_bundle.c

@@ -109,10 +109,15 @@ int starpu_task_bundle_remove(starpu_task_bundle_t bundle, struct starpu_task *t
 {
 	struct _starpu_task_bundle_entry *item;
 
+	_STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);
+
 	item = bundle->list;
 
 	if (!item)
+	{
+		_STARPU_PTHREAD_MUTEX_UNLOCK(&bundle->mutex);
 		return -ENOENT;
+	}
 
 	STARPU_ASSERT(task->bundle == bundle);
 	task->bundle = NULL;
@@ -131,6 +136,7 @@ int starpu_task_bundle_remove(starpu_task_bundle_t bundle, struct starpu_task *t
 			return 1;
 		}
 
+		_STARPU_PTHREAD_MUTEX_UNLOCK(&bundle->mutex);
 		return 0;
 	}
 
@@ -143,6 +149,7 @@ int starpu_task_bundle_remove(starpu_task_bundle_t bundle, struct starpu_task *t
 		{
 			/* Remove the next element */
 			item->next = next->next;
+			_STARPU_PTHREAD_MUTEX_UNLOCK(&bundle->mutex);
 			free(next);
 			return 0;
 		}
@@ -150,6 +157,8 @@ int starpu_task_bundle_remove(starpu_task_bundle_t bundle, struct starpu_task *t
 		item = next;
 	}
 
+	_STARPU_PTHREAD_MUTEX_UNLOCK(&bundle->mutex);
+
 	/* We could not find the task in the bundle */
 	return -ENOENT;
 }
@@ -320,6 +329,8 @@ double starpu_task_bundle_expected_data_transfer_time(starpu_task_bundle_t bundl
 		entry = entry->next;
 	}
 
+	_STARPU_PTHREAD_MUTEX_UNLOCK(&bundle->mutex);
+
 	/* Compute the sum of data transfer time, and destroy the list */
 
 	double total_exp = 0.0;
@@ -337,7 +348,5 @@ double starpu_task_bundle_expected_data_transfer_time(starpu_task_bundle_t bundl
 		free(current);
 	}
 
-	_STARPU_PTHREAD_MUTEX_UNLOCK(&bundle->mutex);
-
 	return total_exp;
 }

+ 1 - 8
src/sched_policies/heft.c

@@ -478,14 +478,7 @@ static int _heft_push_task(struct starpu_task *task, unsigned prio)
 		/* Remove the task from the bundle since we have made a
 		 * decision for it, and that other tasks should not consider it
 		 * anymore. */
-		_STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);
-		int ret = starpu_task_bundle_remove(bundle, task);
-
-		/* Perhaps the bundle was destroyed when removing the last
-		 * entry */
-		if (ret != 1)
-			_STARPU_PTHREAD_MUTEX_UNLOCK(&bundle->mutex);
-
+		starpu_task_bundle_remove(bundle, task);
 	}
 	else
 	{