[PATCH v4 05/22] perf symbol: Sort names under write lock

Ian Rogers posted 22 patches 2 years, 10 months ago
There is a newer version of this series
[PATCH v4 05/22] perf symbol: Sort names under write lock
Posted by Ian Rogers 2 years, 10 months ago
If finding a name doesn't find the sorted names then they are
allocated and sorted. This shouldn't be done under a read lock as
another reader may access it. Release the read lock and acquire the
write lock, then release the write lock and reacquire the read lock.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/symbol.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 317c0706852f..a458aa8b87bb 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -2018,6 +2018,9 @@ static int map__groups__sort_by_name_from_rbtree(struct maps *maps)
 	if (maps_by_name == NULL)
 		return -1;
 
+	up_read(&maps->lock);
+	down_write(&maps->lock);
+
 	maps->maps_by_name = maps_by_name;
 	maps->nr_maps_allocated = maps->nr_maps;
 
@@ -2025,6 +2028,10 @@ static int map__groups__sort_by_name_from_rbtree(struct maps *maps)
 		maps_by_name[i++] = map;
 
 	__maps__sort_by_name(maps);
+
+	up_write(&maps->lock);
+	down_read(&maps->lock);
+
 	return 0;
 }
 
-- 
2.40.0.rc1.284.g88254d51c5-goog