提交 b99b66f8 编写于 作者: S Sukrit Bhatnagar 提交者: Erik Skultety

util: perf: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC

Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in
src/util/viralloc.h, define a new wrapper around an existing
cleanup function which will be called when a variable declared
with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant
viralloc.h include, since that has moved from the source module into
the header.

When a variable of type virPerfPtr is declared using VIR_AUTOPTR,
the function virPerfFree will be run automatically on it when it
goes out of scope.

This commit also adds an intermediate typedef for virPerf
type for use with the cleanup macros.
Signed-off-by: NSukrit Bhatnagar <skrtbhtngr@gmail.com>
Reviewed-by: NErik Skultety <eskultet@redhat.com>
上级 d18a5f71
......@@ -26,7 +26,6 @@
#endif
#include "virperf.h"
#include "viralloc.h"
#include "virerror.h"
#include "virlog.h"
#include "virfile.h"
......@@ -61,7 +60,7 @@ struct virPerfEvent {
};
typedef struct virPerfEvent *virPerfEventPtr;
struct virPerf {
struct _virPerf {
struct virPerfEvent events[VIR_PERF_EVENT_LAST];
};
......
......@@ -23,6 +23,7 @@
# define __VIR_PERF_H__
# include "virutil.h"
# include "viralloc.h"
/* Some Intel processor families introduced some RDT (Resource Director
* Technology) features to monitor or control shared resource based on
......@@ -62,8 +63,9 @@ typedef enum {
VIR_ENUM_DECL(virPerfEvent);
struct virPerf;
typedef struct virPerf *virPerfPtr;
struct _virPerf;
typedef struct _virPerf virPerf;
typedef virPerf *virPerfPtr;
virPerfPtr virPerfNew(void);
......@@ -83,4 +85,6 @@ int virPerfReadEvent(virPerfPtr perf,
virPerfEventType type,
uint64_t *value);
VIR_DEFINE_AUTOPTR_FUNC(virPerf, virPerfFree)
#endif /* __VIR_PERF_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册