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

util: cgroup: 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 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: NSukrit Bhatnagar <skrtbhtngr@gmail.com>
Reviewed-by: NErik Skultety <eskultet@redhat.com>
上级 0f80c718
......@@ -50,7 +50,6 @@
#include "vircgrouppriv.h"
#include "virutil.h"
#include "viralloc.h"
#include "virerror.h"
#include "virlog.h"
#include "virfile.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__ */
......@@ -42,7 +42,7 @@ struct virCgroupController {
char *placement;
};
struct virCgroup {
struct _virCgroup {
char *path;
struct virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册