*/
        if (trace->filter_pids.nr > 0)
                err = perf_evlist__set_filter_pids(evlist, trace->filter_pids.nr, trace->filter_pids.entries);
-       else if (evlist->threads->map[0] == -1)
+       else if (thread_map__pid(evlist->threads, 0) == -1)
                err = perf_evlist__set_filter_pid(evlist, getpid());
 
        if (err < 0) {
        if (forks)
                perf_evlist__start_workload(evlist);
 
-       trace->multiple_threads = evlist->threads->map[0] == -1 ||
+       trace->multiple_threads = thread_map__pid(evlist->threads, 0) == -1 ||
                                  evlist->threads->nr > 1 ||
                                  perf_evlist__first(evlist)->attr.inherit;
 again:
 
 
        perf_evsel__config(evsel, &opts);
 
-       evlist->threads->map[0] = getpid();
+       thread_map__set_pid(evlist->threads, 0, getpid());
 
        err = perf_evlist__open(evlist);
        if (err < 0) {
 
        if (per_cpu) {
                mp->cpu = evlist->cpus->map[idx];
                if (evlist->threads)
-                       mp->tid = evlist->threads->map[0];
+                       mp->tid = thread_map__pid(evlist->threads, 0);
                else
                        mp->tid = -1;
        } else {
                mp->cpu = -1;
-               mp->tid = evlist->threads->map[idx];
+               mp->tid = thread_map__pid(evlist->threads, idx);
        }
 }
 
 
        for (thread = 0; thread < threads->nr; ++thread) {
                if (__event__synthesize_thread(comm_event, mmap_event,
                                               fork_event,
-                                              threads->map[thread], 0,
+                                              thread_map__pid(threads, thread), 0,
                                               process, tool, machine,
                                               mmap_data, proc_map_timeout)) {
                        err = -1;
                 * comm.pid is set to thread group id by
                 * perf_event__synthesize_comm
                 */
-               if ((int) comm_event->comm.pid != threads->map[thread]) {
+               if ((int) comm_event->comm.pid != thread_map__pid(threads, thread)) {
                        bool need_leader = true;
 
                        /* is thread group leader in thread_map? */
                        for (j = 0; j < threads->nr; ++j) {
-                               if ((int) comm_event->comm.pid == threads->map[j]) {
+                               if ((int) comm_event->comm.pid == thread_map__pid(threads, j)) {
                                        need_leader = false;
                                        break;
                                }
 
        else
                sid->cpu = -1;
        if (!evsel->system_wide && evlist->threads && thread >= 0)
-               sid->tid = evlist->threads->map[thread];
+               sid->tid = thread_map__pid(evlist->threads, thread);
        else
                sid->tid = -1;
 }
                                __func__, __LINE__);
                        goto out_close_pipes;
                }
-               evlist->threads->map[0] = evlist->workload.pid;
+               thread_map__set_pid(evlist->threads, 0, evlist->workload.pid);
        }
 
        close(child_ready_pipe[1]);
 
                        int group_fd;
 
                        if (!evsel->cgrp && !evsel->system_wide)
-                               pid = threads->map[thread];
+                               pid = thread_map__pid(threads, thread);
 
                        group_fd = get_group_fd(evsel, cpu, thread);
 retry_open:
 
        threads = thread_map__alloc(items);
        if (threads != NULL) {
                for (i = 0; i < items; i++)
-                       threads->map[i] = atoi(namelist[i]->d_name);
+                       thread_map__set_pid(threads, i, atoi(namelist[i]->d_name));
                threads->nr = items;
        }
 
        struct thread_map *threads = thread_map__alloc(1);
 
        if (threads != NULL) {
-               threads->map[0] = tid;
-               threads->nr     = 1;
+               thread_map__set_pid(threads, 0, tid);
+               threads->nr = 1;
        }
 
        return threads;
                        threads = tmp;
                }
 
-               for (i = 0; i < items; i++)
-                       threads->map[threads->nr + i] = atoi(namelist[i]->d_name);
+               for (i = 0; i < items; i++) {
+                       thread_map__set_pid(threads, threads->nr + i,
+                                           atoi(namelist[i]->d_name));
+               }
 
                for (i = 0; i < items; i++)
                        zfree(&namelist[i]);
                threads = nt;
 
                for (i = 0; i < items; i++) {
-                       threads->map[j++] = atoi(namelist[i]->d_name);
+                       thread_map__set_pid(threads, j++, atoi(namelist[i]->d_name));
                        zfree(&namelist[i]);
                }
                threads->nr = total_tasks;
        struct thread_map *threads = thread_map__alloc(1);
 
        if (threads != NULL) {
-               threads->map[0] = -1;
-               threads->nr     = 1;
+               thread_map__set_pid(threads, 0, -1);
+               threads->nr = 1;
        }
        return threads;
 }
                        goto out_free_threads;
 
                threads = nt;
-               threads->map[ntasks - 1] = tid;
-               threads->nr              = ntasks;
+               thread_map__set_pid(threads, ntasks - 1, tid);
+               threads->nr = ntasks;
        }
 out:
        return threads;
        size_t printed = fprintf(fp, "%d thread%s: ",
                                 threads->nr, threads->nr > 1 ? "s" : "");
        for (i = 0; i < threads->nr; ++i)
-               printed += fprintf(fp, "%s%d", i ? ", " : "", threads->map[i]);
+               printed += fprintf(fp, "%s%d", i ? ", " : "", thread_map__pid(threads, i));
 
        return printed + fprintf(fp, "\n");
 }
 
        return threads ? threads->nr : 1;
 }
 
+static inline pid_t thread_map__pid(struct thread_map *map, int thread)
+{
+       return map->map[thread];
+}
+
+static inline void
+thread_map__set_pid(struct thread_map *map, int thread, pid_t pid)
+{
+       map->map[thread] = pid;
+}
 #endif /* __PERF_THREAD_MAP_H */