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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 7143849a
...@@ -115,23 +115,19 @@ static int add_cgroup(struct perf_evlist *evlist, char *str) ...@@ -115,23 +115,19 @@ static int add_cgroup(struct perf_evlist *evlist, char *str)
goto found; goto found;
n++; n++;
} }
if (cgrp->refcnt == 0) if (atomic_read(&cgrp->refcnt) == 0)
free(cgrp); free(cgrp);
return -1; return -1;
found: found:
cgrp->refcnt++; atomic_inc(&cgrp->refcnt);
counter->cgrp = cgrp; counter->cgrp = cgrp;
return 0; return 0;
} }
void close_cgroup(struct cgroup_sel *cgrp) void close_cgroup(struct cgroup_sel *cgrp)
{ {
if (!cgrp) if (cgrp && atomic_dec_and_test(&cgrp->refcnt)) {
return;
/* XXX: not reentrant */
if (--cgrp->refcnt == 0) {
close(cgrp->fd); close(cgrp->fd);
zfree(&cgrp->name); zfree(&cgrp->name);
free(cgrp); free(cgrp);
......
#ifndef __CGROUP_H__ #ifndef __CGROUP_H__
#define __CGROUP_H__ #define __CGROUP_H__
#include <linux/atomic.h>
struct option; struct option;
struct cgroup_sel { struct cgroup_sel {
char *name; char *name;
int fd; int fd;
int refcnt; atomic_t refcnt;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment