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: Sukrit Bhatnagar <skrtbhtngr@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Sukrit Bhatnagar 2018-07-28 23:31:41 +05:30 committed by Erik Skultety
parent d18a5f716a
commit b99b66f846
2 changed files with 7 additions and 4 deletions

View File

@ -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];
};

View File

@ -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__ */