git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[GSoC][RFC WIP PATCH 2/3] grep: remove locks on object reading operations

From
Matheus Tavares <matheus.bernardino@usp.br>
Date
Jul 19, 2019, 23:08 UTC
Message-ID
<10005e2838ef3bc219b4a775de522339046db318.1563570204.git.matheus.bernardino@usp.br>
In-Reply-To
<cover.1563570204.git.matheus.bernardino@usp.br>

git-grep has locks around the object reading operations it performs. But these have an internal lock now, which can be enabled through enable_obj_read_lock(). So let's use it and drop git-grep's ones.

Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
---
 builtin/grep.c | 18 +++---------------
 grep.c         |  3 ---
 2 files changed, 3 insertions(+), 18 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index 580fd38f41..682e2461d0 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -206,6 +206,7 @@ static void start_threads(struct grep_opt *opt)
 	pthread_cond_init(&cond_write, NULL);
 	pthread_cond_init(&cond_result, NULL);
 	grep_use_locks = 1;
+	enable_obj_read_lock();
 
 	for (i = 0; i < ARRAY_SIZE(todo); i++) {
 		strbuf_init(&todo[i].out, 0);
@@ -263,6 +264,7 @@ static int wait_all(void)
 	pthread_cond_destroy(&cond_write);
 	pthread_cond_destroy(&cond_result);
 	grep_use_locks = 0;
+	disable_obj_read_lock();
 
 	return hit;
 }
@@ -295,16 +297,6 @@ static int grep_cmd_config(const char *var, const char *value, void *cb)
 	return st;
 }
 
-static void *lock_and_read_oid_file(const struct object_id *oid, enum object_type *type, unsigned long *size)
-{
-	void *data;
-
-	grep_read_lock();
-	data = read_object_file(oid, type, size);
-	grep_read_unlock();
-	return data;
-}
-
 static int grep_oid(struct grep_opt *opt, const struct object_id *oid,
 		     const char *filename, int tree_name_len,
 		     const char *path)
@@ -457,10 +449,8 @@ static int grep_submodule(struct grep_opt *opt,
 
 		object = parse_object_or_die(oid, oid_to_hex(oid));
 
-		grep_read_lock();
 		data = read_object_with_reference(&object->oid, tree_type,
 						  &size, NULL);
-		grep_read_unlock();
 
 		if (!data)
 			die(_("unable to read tree (%s)"), oid_to_hex(&object->oid));
@@ -585,7 +575,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
 			void *data;
 			unsigned long size;
 
-			data = lock_and_read_oid_file(&entry.oid, &type, &size);
+			data = read_object_file(&entry.oid, &type, &size);
 			if (!data)
 				die(_("unable to read tree (%s)"),
 				    oid_to_hex(&entry.oid));
@@ -622,10 +612,8 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
 		struct strbuf base;
 		int hit, len;
 
-		grep_read_lock();
 		data = read_object_with_reference(&obj->oid, tree_type,
 						  &size, NULL);
-		grep_read_unlock();
 
 		if (!data)
 			die(_("unable to read tree (%s)"), oid_to_hex(&obj->oid));
diff --git a/grep.c b/grep.c
index f7c3a5803e..984a9e99cf 100644
--- a/grep.c
+++ b/grep.c
@@ -2109,10 +2109,7 @@ static int grep_source_load_oid(struct grep_source *gs)
 {
 	enum object_type type;
 
-	grep_read_lock();
 	gs->buf = read_object_file(gs->identifier, &type, &gs->size);
-	grep_read_unlock();
-
 	if (!gs->buf)
 		return error(_("'%s': unable to read %s"),
 			     gs->name,
-- 
2.22.0
Previous: Matheus TavaresNext: Matheus Tavares
Message 3 of 4 in “grep: allow parallelism in zlib inflation”
  1. Matheus TavaresJul 19, 2019
  2. [GSoC][RFC WIP PATCH 1/3] object-store: make read_object_file_extended() thread-safeMatheus Tavares, Jul 19, 2019
  3. [GSoC][RFC WIP PATCH 2/3] grep: remove locks on object reading operationsMatheus Tavares, Jul 19, 2019
  4. [GSoC][RFC WIP PATCH 3/3] grep: re-enable threads in non-worktree caseMatheus Tavares, Jul 19, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.