Przeglądaj źródła

isolate the functions to manipulate cg_t

Cédric Augonnet 15 lat temu
rodzic
commit
5af0b66425

+ 36 - 5
src/core/dependencies/cg.c

@@ -14,14 +14,45 @@
  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  */
 
-#include <core/dependencies/htable.h>
-#include <core/jobs.h>
-#include <core/policies/sched_policy.h>
-#include <core/dependencies/data-concurrency.h>
 #include <starpu.h>
 #include <common/config.h>
-#include <core/dependencies/tags.h>
 #include <core/dependencies/cg.h>
+#include <core/dependencies/tags.h>
+
+void _starpu_cg_list_init(struct cg_list_s *list)
+{
+	list->nsuccs = 0;
+	list->ndeps = 0;
+	list->ndeps_completed = 0;
+
+#ifdef DYNAMIC_DEPS_SIZE
+	/* this is a small initial default value ... may be changed */
+	list->succ_list_size = 4;
+	list->succ =
+		realloc(NULL, list->succ_list_size*sizeof(struct cg_s *));
+#endif
+}
+
+void _starpu_add_successor_to_cg_list(struct cg_list_s *successors, cg_t *cg)
+{
+	/* where should that cg should be put in the array ? */
+	unsigned index = STARPU_ATOMIC_ADD(&successors->nsuccs, 1) - 1;
+
+#ifdef DYNAMIC_DEPS_SIZE
+	if (index >= successors->succ_list_size)
+	{
+		/* the successor list is too small */
+		successors->succ_list_size *= 2;
+
+		/* NB: this is thread safe as the tag->lock is taken */
+		successors->succ = realloc(successors->succ, 
+			successors->succ_list_size*sizeof(struct cg_s *));
+	}
+#else
+	STARPU_ASSERT(index < NMAXDEPS);
+#endif
+	successors->succ[index] = cg;
+}
 
 void _starpu_notify_cg(cg_t *cg)
 {

+ 2 - 0
src/core/dependencies/cg.h

@@ -73,6 +73,8 @@ typedef struct cg_s {
 	} succ;
 } cg_t;
 
+void _starpu_cg_list_init(struct cg_list_s *list);
+void _starpu_add_successor_to_cg_list(struct cg_list_s *successors, cg_t *cg);
 void _starpu_notify_cg(cg_t *cg);
 
 #endif // __CG_H__

+ 2 - 28
src/core/dependencies/tags.c

@@ -69,16 +69,8 @@ static struct tag_s *_starpu_tag_init(starpu_tag_t id)
 
 	tag->id = id;
 	tag->state = INVALID_STATE;
-	tag->tag_successors.nsuccs = 0;
-	tag->tag_successors.ndeps = 0;
-	tag->tag_successors.ndeps_completed = 0;
 
-#ifdef DYNAMIC_DEPS_SIZE
-	/* this is a small initial default value ... may be changed */
-	tag->tag_successors.succ_list_size = 4;
-	tag->tag_successors.succ =
-		realloc(NULL, tag->tag_successors.succ_list_size*sizeof(struct cg_s *));
-#endif
+	_starpu_cg_list_init(&tag->tag_successors);
 
 	starpu_spin_init(&tag->lock);
 
@@ -177,25 +169,7 @@ static void _starpu_tag_add_succ(struct tag_s *tag, cg_t *cg)
 {
 	STARPU_ASSERT(tag);
 
-	struct cg_list_s *tag_successors = &tag->tag_successors;
-
-	/* where should that cg should be put in the array ? */
-	unsigned index = STARPU_ATOMIC_ADD(&tag_successors->nsuccs, 1) - 1;
-
-#ifdef DYNAMIC_DEPS_SIZE
-	if (index >= tag_successors->succ_list_size)
-	{
-		/* the successor list is too small */
-		tag_successors->succ_list_size *= 2;
-
-		/* NB: this is thread safe as the tag->lock is taken */
-		tag_successors->succ = realloc(tag_successors->succ, 
-			tag_successors->succ_list_size*sizeof(struct cg_s *));
-	}
-#else
-	STARPU_ASSERT(index < NMAXDEPS);
-#endif
-	tag_successors->succ[index] = cg;
+	_starpu_add_successor_to_cg_list(&tag->tag_successors, cg);
 
 	if (tag->state == DONE) {
 		/* the tag was already completed sooner */