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

Message ID 20230320033810.980165-6-irogers@google.com
State New
Headers
Series Reference count checker and related fixes |

Commit Message

Ian Rogers March 20, 2023, 3:37 a.m. UTC
  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(+)
  

Patch

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;
 }