Skip to content

Commit

Permalink
perf thread_map: Introduce thread_map__reset function
Browse files Browse the repository at this point in the history
We need to reset newly allocated 'struct thread_map_data' entries,
because we will introduce new comm memeber, which will get set later or
not at all.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1435310967-14570-2-git-send-email-jolsa@kernel.org
[ Use sizeof(map->map[0]) to be independent of the array entry type ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Jiri Olsa authored and Arnaldo Carvalho de Melo committed Jun 26, 2015
1 parent d0cc439 commit 62eea46
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tools/perf/util/thread_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,26 @@ static int filter(const struct dirent *dir)
return 1;
}

static void thread_map__reset(struct thread_map *map, int start, int nr)
{
size_t size = (nr - start) * sizeof(map->map[0]);

memset(&map->map[start], 0, size);
}

static struct thread_map *thread_map__realloc(struct thread_map *map, int nr)
{
size_t size = sizeof(*map) + sizeof(map->map[0]) * nr;
int start = map ? map->nr : 0;

return realloc(map, size);
map = realloc(map, size);
/*
* We only realloc to add more items, let's reset new items.
*/
if (map)
thread_map__reset(map, start, nr);

return map;
}

#define thread_map__alloc(__nr) thread_map__realloc(NULL, __nr)
Expand Down

0 comments on commit 62eea46

Please sign in to comment.