[PATCH v2 08/41] util: cgroup: 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 virCgroupPtr is declared using
VIR_AUTOPTR, the function virCgroupFree will be run
automatically on it when it goes out of scope.

This commit also adds an intermediate typedef for virCgroup
type for use with the cleanup macros.

Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@xxxxxxxxx>
---
 src/util/vircgroup.c     | 1 -
 src/util/vircgroup.h     | 9 +++++++--
 src/util/vircgrouppriv.h | 2 +-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 140b016..bc5f774 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -50,7 +50,6 @@
 #include "vircgrouppriv.h"
 
 #include "virutil.h"
-#include "viralloc.h"
 #include "virerror.h"
 #include "virlog.h"
 #include "virfile.h"
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
index e4ffd57..065861d 100644
--- a/src/util/vircgroup.h
+++ b/src/util/vircgroup.h
@@ -27,9 +27,11 @@
 
 # include "virutil.h"
 # include "virbitmap.h"
+# include "viralloc.h"
 
-struct virCgroup;
-typedef struct virCgroup *virCgroupPtr;
+struct _virCgroup;
+typedef struct _virCgroup virCgroup;
+typedef virCgroup *virCgroupPtr;
 
 enum {
     VIR_CGROUP_CONTROLLER_CPU,
@@ -297,4 +299,7 @@ int virCgroupSetOwner(virCgroupPtr cgroup,
 int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller);
 
 bool virCgroupControllerAvailable(int controller);
+
+VIR_DEFINE_AUTOPTR_FUNC(virCgroup, virCgroupFree)
+
 #endif /* __VIR_CGROUP_H__ */
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
index 722863e..a72bee1 100644
--- a/src/util/vircgrouppriv.h
+++ b/src/util/vircgrouppriv.h
@@ -42,7 +42,7 @@ struct virCgroupController {
     char *placement;
 };
 
-struct virCgroup {
+struct _virCgroup {
     char *path;
 
     struct virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST];
-- 
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