Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf cgroup: Use atomic.h for refcounting

Now that we have atomic.h, we should convert all of the existing
refcounts to use it.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-t3v2uma5digcj2tpkrs3m84u@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+6 -8
+3 -7
tools/perf/util/cgroup.c
··· 115 115 goto found; 116 116 n++; 117 117 } 118 - if (cgrp->refcnt == 0) 118 + if (atomic_read(&cgrp->refcnt) == 0) 119 119 free(cgrp); 120 120 121 121 return -1; 122 122 found: 123 - cgrp->refcnt++; 123 + atomic_inc(&cgrp->refcnt); 124 124 counter->cgrp = cgrp; 125 125 return 0; 126 126 } 127 127 128 128 void close_cgroup(struct cgroup_sel *cgrp) 129 129 { 130 - if (!cgrp) 131 - return; 132 - 133 - /* XXX: not reentrant */ 134 - if (--cgrp->refcnt == 0) { 130 + if (cgrp && atomic_dec_and_test(&cgrp->refcnt)) { 135 131 close(cgrp->fd); 136 132 zfree(&cgrp->name); 137 133 free(cgrp);
+3 -1
tools/perf/util/cgroup.h
··· 1 1 #ifndef __CGROUP_H__ 2 2 #define __CGROUP_H__ 3 3 4 + #include <linux/atomic.h> 5 + 4 6 struct option; 5 7 6 8 struct cgroup_sel { 7 9 char *name; 8 10 int fd; 9 - int refcnt; 11 + atomic_t refcnt; 10 12 }; 11 13 12 14