]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: cgroup: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC
authorSukrit Bhatnagar <skrtbhtngr@gmail.com>
Tue, 24 Jul 2018 15:52:09 +0000 (21:22 +0530)
committerErik Skultety <eskultet@redhat.com>
Fri, 27 Jul 2018 15:19:18 +0000 (17:19 +0200)
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@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/util/vircgroup.c
src/util/vircgroup.h
src/util/vircgrouppriv.h

index 140b01692fd0aeb82eca7fe7f3cac2dcce46fe1b..bc5f77469f316cc744b5e0a1cc87117b71b753de 100644 (file)
@@ -50,7 +50,6 @@
 #include "vircgrouppriv.h"
 
 #include "virutil.h"
-#include "viralloc.h"
 #include "virerror.h"
 #include "virlog.h"
 #include "virfile.h"
index e4ffd57b6bae35f4f7c12dcbf9b5db878f9a7402..065861d7008252a4d3a2b4c779f1adc5e8bb04ea 100644 (file)
 
 # 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__ */
index 722863e5b6410f424bb2c347c4128f683d228361..a72bee1ef2686e21323157342124ad2f5c2e119f 100644 (file)
@@ -42,7 +42,7 @@ struct virCgroupController {
     char *placement;
 };
 
-struct virCgroup {
+struct _virCgroup {
     char *path;
 
     struct virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST];