Browse Source

lbalance: Switch to tlist2

lbalance uses the tlist module. tlist causes compile warnings on clang if
you're not careful, because it can put 0 length arrays in the middle of
structures.  tlist2 doesn't have the problem, and also has a slightly
cleaner interface.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson 8 years ago
parent
commit
dcc0a08c26
2 changed files with 19 additions and 20 deletions
  1. 1 1
      ccan/lbalance/_info
  2. 18 19
      ccan/lbalance/lbalance.c

+ 1 - 1
ccan/lbalance/_info

@@ -85,7 +85,7 @@ int main(int argc, char *argv[])
 		return 1;
 		return 1;
 
 
 	if (strcmp(argv[1], "depends") == 0) {
 	if (strcmp(argv[1], "depends") == 0) {
-		printf("ccan/tlist\n");
+		printf("ccan/tlist2\n");
 		return 0;
 		return 0;
 	}
 	}
 
 

+ 18 - 19
ccan/lbalance/lbalance.c

@@ -1,6 +1,6 @@
 /* Licensed under GPLv3+ - see LICENSE file for details */
 /* Licensed under GPLv3+ - see LICENSE file for details */
 #include <ccan/lbalance/lbalance.h>
 #include <ccan/lbalance/lbalance.h>
-#include <ccan/tlist/tlist.h>
+#include <ccan/tlist2/tlist2.h>
 #include <sys/time.h>
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <sys/resource.h>
 #include <unistd.h>
 #include <unistd.h>
@@ -8,9 +8,6 @@
 #include <assert.h>
 #include <assert.h>
 #include <stdlib.h>
 #include <stdlib.h>
 
 
-/* Define tlist_lbalance_task */
-TLIST_TYPE(lbalance_task, struct lbalance_task);
-
 struct stats {
 struct stats {
 	/* How many stats of for this value do we have? */
 	/* How many stats of for this value do we have? */
 	unsigned int num_stats;
 	unsigned int num_stats;
@@ -18,8 +15,19 @@ struct stats {
 	float work_rate;
 	float work_rate;
 };
 };
 
 
+struct lbalance;
+
+struct lbalance_task {
+	struct lbalance *lb;
+	struct list_node list;
+
+	/* The time this task started */
+	struct timeval start;
+	float tasks_sum_start;
+};
+
 struct lbalance {
 struct lbalance {
-	struct tlist_lbalance_task tasks;
+	TLIST2(struct lbalance_task, list) tasks;
 	unsigned int num_tasks;
 	unsigned int num_tasks;
 
 
 	/* We figured out how many we want to run. */
 	/* We figured out how many we want to run. */
@@ -42,22 +50,13 @@ struct lbalance {
 	struct stats *stats;
 	struct stats *stats;
 };
 };
 
 
-struct lbalance_task {
-	struct lbalance *lb;
-	struct list_node list;
-
-	/* The time this task started */
-	struct timeval start;
-	float tasks_sum_start;
-};
-
 struct lbalance *lbalance_new(void)
 struct lbalance *lbalance_new(void)
 {
 {
 	struct lbalance *lb = malloc(sizeof *lb);
 	struct lbalance *lb = malloc(sizeof *lb);
 	if (!lb)
 	if (!lb)
 		return NULL;
 		return NULL;
 
 
-	tlist_init(&lb->tasks);
+	tlist2_init(&lb->tasks);
 	lb->num_tasks = 0;
 	lb->num_tasks = 0;
 	gettimeofday(&lb->prev_tasks_time, NULL);
 	gettimeofday(&lb->prev_tasks_time, NULL);
 	lb->tasks_sum = 0.0;
 	lb->tasks_sum = 0.0;
@@ -140,7 +139,7 @@ struct lbalance_task *lbalance_task_new(struct lbalance *lb)
 	update_tasks_sum(lb, &task->start);
 	update_tasks_sum(lb, &task->start);
 
 
 	task->tasks_sum_start = lb->tasks_sum;
 	task->tasks_sum_start = lb->tasks_sum;
-	tlist_add_tail(&lb->tasks, task, list);
+	tlist2_add_tail(&lb->tasks, task);
 	lb->num_tasks++;
 	lb->num_tasks++;
 
 
 	return task;
 	return task;
@@ -229,7 +228,7 @@ void lbalance_task_free(struct lbalance_task *task,
 	task->lb->target_uptodate = false;
 	task->lb->target_uptodate = false;
 
 
 	/* Remove this task. */
 	/* Remove this task. */
-	tlist_del_from(&task->lb->tasks, task, list);
+	tlist2_del_from(&task->lb->tasks, task);
 	task->lb->num_tasks--;
 	task->lb->num_tasks--;
 	free(task);
 	free(task);
 }
 }
@@ -314,9 +313,9 @@ void lbalance_free(struct lbalance *lb)
 {
 {
 	struct lbalance_task *task;
 	struct lbalance_task *task;
 
 
-	while ((task = tlist_top(&lb->tasks, list))) {
+	while ((task = tlist2_top(&lb->tasks))) {
 		assert(task->lb == lb);
 		assert(task->lb == lb);
-		tlist_del_from(&lb->tasks, task, list);
+		tlist2_del_from(&lb->tasks, task);
 		lb->num_tasks--;
 		lb->num_tasks--;
 		free(task);
 		free(task);
 	}
 	}