Browse Source

src: minor fixes following cppcheck recommandations

Nathalie Furmento 8 years ago
parent
commit
6f514d9536
2 changed files with 19 additions and 9 deletions
  1. 14 7
      src/core/task.c
  2. 5 2
      src/datawizard/memalloc.c

+ 14 - 7
src/core/task.c

@@ -56,6 +56,8 @@ static int limit_min_submitted_tasks;
 static int limit_max_submitted_tasks;
 static int watchdog_crash;
 
+#define _STARPU_TASK_MAGIC 42
+
 /* Called once at starpu_init */
 void _starpu_task_init(void)
 {
@@ -98,7 +100,7 @@ void starpu_task_init(struct starpu_task *task)
 	task->predicted_transfer = NAN;
 	task->predicted_start = NAN;
 
-	task->magic = 42;
+	task->magic = _STARPU_TASK_MAGIC;
 	task->sched_ctx = STARPU_NMAX_SCHED_CTXS;
 
 	task->flops = 0.0;
@@ -566,7 +568,9 @@ static int _starpu_task_submit_head(struct starpu_task *task)
 
 		/* Check buffers */
 		if (task->dyn_handles == NULL)
-			STARPU_ASSERT_MSG(STARPU_TASK_GET_NBUFFERS(task) <= STARPU_NMAXBUFS, "Codelet %p has too many buffers (%d vs max %d). Either use --enable-maxbuffers configure option to increase the max, or use dyn_handles instead of handles.", task->cl, STARPU_TASK_GET_NBUFFERS(task), STARPU_NMAXBUFS);
+			STARPU_ASSERT_MSG(STARPU_TASK_GET_NBUFFERS(task) <= STARPU_NMAXBUFS,
+					  "Codelet %p has too many buffers (%d vs max %d). Either use --enable-maxbuffers configure option to increase the max, or use dyn_handles instead of handles.",
+					  task->cl, STARPU_TASK_GET_NBUFFERS(task), STARPU_NMAXBUFS);
 
 		if (task->dyn_handles)
 		{
@@ -577,7 +581,7 @@ static int _starpu_task_submit_head(struct starpu_task *task)
 		{
 			starpu_data_handle_t handle = STARPU_TASK_GET_HANDLE(task, i);
 			/* Make sure handles are valid */
-			STARPU_ASSERT_MSG(handle->magic == 42, "data %p is invalid (was it already unregistered?)", handle);
+			STARPU_ASSERT_MSG(handle->magic == _STARPU_TASK_MAGIC, "data %p is invalid (was it already unregistered?)", handle);
 			/* Make sure handles are not partitioned */
 			STARPU_ASSERT_MSG(handle->nchildren == 0, "only unpartitioned data (or the pieces of a partitioned data) can be used in a task");
 			/* Provide the home interface for now if any,
@@ -617,7 +621,7 @@ int starpu_task_submit(struct starpu_task *task)
 {
 	_STARPU_LOG_IN();
 	STARPU_ASSERT(task);
-	STARPU_ASSERT_MSG(task->magic == 42, "Tasks must be created with starpu_task_create, or initialized with starpu_task_init.");
+	STARPU_ASSERT_MSG(task->magic == _STARPU_TASK_MAGIC, "Tasks must be created with starpu_task_create, or initialized with starpu_task_init.");
 
 	int ret;
 	unsigned is_sync = task->synchronous;
@@ -817,6 +821,8 @@ void starpu_codelet_init(struct starpu_codelet *cl)
 	memset(cl, 0, sizeof(struct starpu_codelet));
 }
 
+#define _STARPU_CODELET_WORKER_NAME_LEN 32
+
 void starpu_codelet_display_stats(struct starpu_codelet *cl)
 {
 	unsigned worker;
@@ -834,8 +840,8 @@ void starpu_codelet_display_stats(struct starpu_codelet *cl)
 
 	for (worker = 0; worker < nworkers; worker++)
 	{
-		char name[32];
-		starpu_worker_get_name(worker, name, 32);
+		char name[_STARPU_CODELET_WORKER_NAME_LEN];
+		starpu_worker_get_name(worker, name, _STARPU_CODELET_WORKER_NAME_LEN);
 
 		fprintf(stderr, "\t%s -> %lu / %lu (%2.2f %%)\n", name, cl->per_worker_stats[worker], total, (100.0f*cl->per_worker_stats[worker])/total);
 	}
@@ -1276,7 +1282,8 @@ static void *watchdog_func(void *arg)
 		if (!config->watchdog_ok && last_nsubmitted
 				&& last_nsubmitted == starpu_task_nsubmitted())
 		{
-			_STARPU_MSG("The StarPU watchdog detected that no task finished for %fs (can be configured through STARPU_WATCHDOG_TIMEOUT)\n", timeout);
+			_STARPU_MSG("The StarPU watchdog detected that no task finished for %fs (can be configured through STARPU_WATCHDOG_TIMEOUT)\n",
+				    timeout);
 			if (watchdog_crash)
 			{
 				_STARPU_MSG("Crashing the process\n");

+ 5 - 2
src/datawizard/memalloc.c

@@ -231,7 +231,8 @@ static unsigned may_free_subtree(starpu_data_handle_t handle, unsigned node)
 		unsigned res;
 		starpu_data_handle_t child_handle = starpu_data_get_child(handle, child);
 		res = may_free_subtree(child_handle, node);
-		if (!res) return 0;
+		if (!res)
+			return 0;
 	}
 
 	/* no problem was found */
@@ -608,8 +609,10 @@ static size_t try_to_throw_mem_chunk(struct _starpu_mem_chunk *mc, unsigned node
 								freed = 1;
 							}
 							else
+							{
 								/* Free */
 								freed = do_free_mem_chunk(mc, node);
+							}
 						}
 					}
 				}
@@ -714,7 +717,7 @@ restart:
 		if (!mc->data->is_not_important)
 			/* Important data, skip */
 			continue;
-		if (mc->footprint != footprint || _starpu_data_interface_compare(data->per_node[node].data_interface, data->ops, mc->data->per_node[node].data_interface, mc->ops) != 1 )
+		if (mc->footprint != footprint || _starpu_data_interface_compare(data->per_node[node].data_interface, data->ops, mc->data->per_node[node].data_interface, mc->ops) != 1)
 			/* Not the right type of interface, skip */
 			continue;
 		if (next_mc)