瀏覽代碼

- even once a tag is associated to a task, it can either be ready or blocked.
So we create a separate flag.
- protect accesses to tag->state

Cédric Augonnet 16 年之前
父節點
當前提交
e37dc4a47d
共有 2 個文件被更改,包括 24 次插入12 次删除
  1. 22 11
      src/core/dependencies/tags.c
  2. 2 1
      src/core/dependencies/tags.h

+ 22 - 11
src/core/dependencies/tags.c

@@ -48,8 +48,11 @@ static struct tag_s *tag_init(starpu_tag_t id)
 	tag = malloc(sizeof(struct tag_s));
 	STARPU_ASSERT(tag);
 
+	tag->job = NULL;
+	tag->is_assigned = 0;
+
 	tag->id = id;
-	tag->state = UNASSIGNED;
+	tag->state = READY;
 	tag->nsuccs = 0;
 
 #ifdef DYNAMIC_DEPS_SIZE
@@ -60,8 +63,6 @@ static struct tag_s *tag_init(starpu_tag_t id)
 
 	init_mutex(&tag->lock);
 
-	tag->job = NULL;
-
 	/* initializing a mutex and a cond variable is a little expensive, so
  	 * we don't initialize them until they are needed */
 	tag->someone_is_waiting = 0;
@@ -118,22 +119,26 @@ static struct tag_s *gettag_struct(starpu_tag_t id)
 
 static void tag_set_ready(struct tag_s *tag)
 {
+	take_mutex(&tag->lock);
+
 	/* mark this tag as ready to run */
 	tag->state = READY;
 	/* declare it to the scheduler ! */
 	struct job_s *j = tag->job;
 
-	/* perhaps the corresponding task was not declared yet */
-	if (!j)
-		return;
+	release_mutex(&tag->lock);
 
+	/* perhaps the corresponding task was not declared yet */
+	if (tag->is_assigned)
+	{
 #ifdef NO_DATA_RW_LOCK
-	/* enforce data dependencies */
-	if (submit_job_enforce_data_deps(j))
-		return;
+		/* enforce data dependencies */
+		if (submit_job_enforce_data_deps(j))
+			return;
 #endif
-
-	push_task(j);
+	
+		push_task(j);
+	}
 }
 
 static void notify_cg(cg_t *cg)
@@ -195,10 +200,15 @@ void notify_dependencies(struct job_s *j)
 		/* in case there are dependencies, wake up the proper tasks */
 		tag = j->tag;
 
+		take_mutex(&tag->lock);
+
 		tag->state = DONE;
 		TRACE_TASK_DONE(tag->id);
 
 		nsuccs = tag->nsuccs;
+
+		release_mutex(&tag->lock);
+
 		for (succ = 0; succ < nsuccs; succ++)
 		{
 			notify_cg(tag->succ[succ]);
@@ -221,6 +231,7 @@ void tag_declare(starpu_tag_t id, struct job_s *job)
 	
 	struct tag_s *tag= gettag_struct(id);
 	tag->job = job;
+	tag->is_assigned = 1;
 	
 	job->tag = tag;
 }

+ 2 - 1
src/core/dependencies/tags.h

@@ -34,7 +34,6 @@
 #define TAG_SIZE        (sizeof(starpu_tag_t)*8)
 
 typedef enum {
-	UNASSIGNED,
 	DONE,
 	READY,
 	SCHEDULED,
@@ -55,6 +54,8 @@ struct tag_s {
 	struct _cg_t *succ[NMAXDEPS];
 #endif
 	struct job_s *job; /* which job is associated to the tag if any ? */
+
+	unsigned is_assigned;
 	
 	/* the application may wait on a tag to finish */
 	unsigned someone_is_waiting;