[PATCH v2 29/35] util: perf: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
Reviewed-by: Erik Skultety <eskultet@xxxxxxxxxx>
---
 src/util/virperf.c | 3 +--
 src/util/virperf.h | 8 ++++++--
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/util/virperf.c b/src/util/virperf.c
index 2c832b3..4537cd0 100644
--- a/src/util/virperf.c
+++ b/src/util/virperf.c
@@ -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];
 };
 
diff --git a/src/util/virperf.h b/src/util/virperf.h
index eee7a03..9d0d5ac 100644
--- a/src/util/virperf.h
+++ b/src/util/virperf.h
@@ -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__ */
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux