[RFC PATCH 4/5] builtin/grep.c: add todo_item helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use a helper for indexing into the todo array with any of the todo_*
variables, in preparation for not keeping those reduced mod TODO_SIZE.

Signed-off-by: Rasmus Villemoes <rv@xxxxxxxxxxxxxxxxxx>
---
 builtin/grep.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/builtin/grep.c b/builtin/grep.c
index 92b9e6198d..35ed79b0dd 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -62,6 +62,11 @@ static unsigned int todo_start;
 static unsigned int todo_end;
 static unsigned int todo_done;
 
+static inline struct work_item *todo_item(unsigned int idx)
+{
+	return &todo[idx % ARRAY_SIZE(todo)];
+}
+
 /* Has all work items been added? */
 static int all_work_added;
 
@@ -101,7 +106,7 @@ static void add_work(struct grep_opt *opt, const struct grep_source *gs)
 		pthread_cond_wait(&cond_write, &grep_mutex);
 	}
 
-	w = &todo[todo_end];
+	w = todo_item(todo_end);
 	w->source = *gs;
 	if (opt->binary != GREP_BINARY_TEXT)
 		grep_source_load_driver(&w->source, opt->repo->index);
@@ -125,7 +130,7 @@ static struct work_item *get_work(void)
 	if (todo_start == todo_end && all_work_added) {
 		ret = NULL;
 	} else {
-		ret = &todo[todo_start];
+		ret = todo_item(todo_start);
 		todo_start = (todo_start + 1) % ARRAY_SIZE(todo);
 	}
 	grep_unlock();
@@ -141,7 +146,7 @@ static void work_done(struct work_item *w)
 	old_done = todo_done;
 	for(; todo_done != todo_start;
 	    todo_done = (todo_done+1) % ARRAY_SIZE(todo)) {
-		w = &todo[todo_done];
+		w = todo_item(todo_done);
 		if (!w->done)
 			break;
 		if (w->out.len) {
-- 
2.20.1




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux