浏览代码

protect the tag structure with a starpu_spinlock_t

Cédric Augonnet 16 年之前
父节点
当前提交
0536b51fa0
共有 3 个文件被更改,包括 24 次插入26 次删除
  1. 20 23
      src/core/dependencies/tags.c
  2. 2 1
      src/core/dependencies/tags.h
  3. 2 2
      src/core/jobs.c

+ 20 - 23
src/core/dependencies/tags.c

@@ -74,7 +74,7 @@ static struct tag_s *tag_init(starpu_tag_t id)
 	tag->succ = realloc(NULL, tag->succ_list_size*sizeof(struct _cg_t *));
 #endif
 
-	pthread_spin_init(&tag->lock, 0);
+	starpu_spin_init(&tag->lock);
 
 	return tag;
 }
@@ -89,14 +89,14 @@ void starpu_tag_remove(starpu_tag_t id)
 
 	pthread_rwlock_unlock(&tag_global_rwlock);
 
-	pthread_spin_lock(&tag->lock);
-	
 #ifdef DYNAMIC_DEPS_SIZE
+	starpu_spin_lock(&tag->lock);
+
 	if (tag)
 		free(tag->succ);
-#endif
 
-	pthread_spin_unlock(&tag->lock);
+	starpu_spin_unlock(&tag->lock);
+#endif
 
 	free(tag);
 }
@@ -198,8 +198,6 @@ static void tag_add_succ(struct tag_s *tag, cg_t *cg)
 #endif
 		tag->succ[index] = cg;
 	}
-
-	pthread_spin_unlock(&tag->lock);
 }
 
 static void notify_tag_dependencies(struct tag_s *tag)
@@ -207,7 +205,7 @@ static void notify_tag_dependencies(struct tag_s *tag)
 	unsigned nsuccs;
 	unsigned succ;
 
-	pthread_spin_lock(&tag->lock);
+	starpu_spin_lock(&tag->lock);
 
 	tag->state = DONE;
 	TRACE_TASK_DONE(tag->id);
@@ -221,15 +219,15 @@ static void notify_tag_dependencies(struct tag_s *tag)
 		struct tag_s *cgtag = cg->tag;
 
 		if (!used_by_apps)
-			pthread_spin_lock(&cgtag->lock);
+			starpu_spin_lock(&cgtag->lock);
 
 		notify_cg(cg);
 
 		if (!used_by_apps)
-			pthread_spin_unlock(&cgtag->lock);
+			starpu_spin_unlock(&cgtag->lock);
 	}
 
-	pthread_spin_unlock(&tag->lock);
+	starpu_spin_unlock(&tag->lock);
 }
 
 void notify_dependencies(struct job_s *j)
@@ -271,7 +269,7 @@ void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t
 	/* create the associated completion group */
 	struct tag_s *tag_child = gettag_struct(id);
 
-	pthread_spin_lock(&tag_child->lock);
+	starpu_spin_lock(&tag_child->lock);
 
 	cg_t *cg = create_cg(ndeps, tag_child, 0);
 
@@ -285,12 +283,12 @@ void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t
 		 * so cg should be among dep_id's successors*/
 		TRACE_CODELET_TAG_DEPS(id, dep_id);
 		struct tag_s *tag_dep = gettag_struct(dep_id);
-		pthread_spin_lock(&tag_dep->lock);
+		starpu_spin_lock(&tag_dep->lock);
 		tag_add_succ(tag_dep, cg);
-		pthread_spin_unlock(&tag_dep->lock);
+		starpu_spin_unlock(&tag_dep->lock);
 	}
 
-	pthread_spin_unlock(&tag_child->lock);
+	starpu_spin_unlock(&tag_child->lock);
 }
 
 void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...)
@@ -300,12 +298,11 @@ void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...)
 	/* create the associated completion group */
 	struct tag_s *tag_child = gettag_struct(id);
 
-	pthread_spin_lock(&tag_child->lock);
+	starpu_spin_lock(&tag_child->lock);
 
 	cg_t *cg = create_cg(ndeps, tag_child, 0);
 
 	STARPU_ASSERT(ndeps != 0);
-
 	
 	va_list pa;
 	va_start(pa, ndeps);
@@ -318,13 +315,13 @@ void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...)
 		 * so cg should be among dep_id's successors*/
 		TRACE_CODELET_TAG_DEPS(id, dep_id);
 		struct tag_s *tag_dep = gettag_struct(dep_id);
-		pthread_spin_lock(&tag_dep->lock);
+		starpu_spin_lock(&tag_dep->lock);
 		tag_add_succ(tag_dep, cg);
-		pthread_spin_unlock(&tag_dep->lock);
+		starpu_spin_unlock(&tag_dep->lock);
 	}
 	va_end(pa);
 
-	pthread_spin_unlock(&tag_child->lock);
+	starpu_spin_unlock(&tag_child->lock);
 }
 
 /* this function may be called by the application (outside callbacks !) */
@@ -340,12 +337,12 @@ void starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id)
 	{
 		struct tag_s *tag = gettag_struct(id[i]);
 		
-		pthread_spin_lock(&tag->lock);
+		starpu_spin_lock(&tag->lock);
 
 		if (tag->state == DONE)
 		{
 			/* that tag is done already */
-			pthread_spin_unlock(&tag->lock);
+			starpu_spin_unlock(&tag->lock);
 		}
 		else
 		{
@@ -366,7 +363,7 @@ void starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id)
 	for (i = 0; i < current; i++)
 	{
 		tag_add_succ(tag_array[i], cg);
-		pthread_spin_unlock(&tag_array[i]->lock);
+		starpu_spin_unlock(&tag_array[i]->lock);
 	}
 
 	pthread_mutex_lock(&cg->cg_mutex);

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

@@ -20,6 +20,7 @@
 #include <stdint.h>
 #include <pthread.h>
 #include <core/jobs.h>
+#include <common/starpu-spinlock.h>
 
 /* we do not necessarily want to allocate room for 256 dependencies, but we
    want to handle the few situation where there are a lot of dependencies as
@@ -53,7 +54,7 @@ typedef enum {
 struct job_s;
 
 struct tag_s {
-	pthread_spinlock_t lock;
+	starpu_spinlock_t lock;
 	starpu_tag_t id; /* an identifier for the task */
 	tag_state state;
 	unsigned nsuccs; /* how many successors ? */

+ 2 - 2
src/core/jobs.c

@@ -165,7 +165,7 @@ static unsigned not_all_task_deps_are_fulfilled(job_t j)
 
 	struct tag_s *tag = j->tag;
 
-	pthread_spin_lock(&tag->lock);
+	starpu_spin_lock(&tag->lock);
 
 	if (tag->ndeps != tag->ndeps_completed)
 	{
@@ -178,7 +178,7 @@ static unsigned not_all_task_deps_are_fulfilled(job_t j)
 		ret = 0;
 	}
 
-	pthread_spin_unlock(&tag->lock);
+	starpu_spin_unlock(&tag->lock);
 	return ret;
 }