[lxc-devel] [go-lxc/v2] Do not copy the underlying mutex
caglar10ur on Github
lxc-bot at linuxcontainers.org
Sat Sep 16 22:30:27 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 514 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170916/3250b16b/attachment.bin>
-------------- next part --------------
From 379087f32bf9553f64059ac7fca8815ac00fc439 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=2E=C3=87a=C4=9Flar=20Onur?= <caglar at 10ur.org>
Date: Sat, 16 Sep 2017 15:27:33 -0700
Subject: [PATCH] Do not copy the underlying mutex
This changes the return type of 3 functions. This should be safe
assuming the expected usage of those functions in the form of;
```
c := lxc.DefinedContainers(lxcpath)
...
```
Should help to #82 as well
---
container.go | 2 +-
lxc-binding.go | 18 +++++++++---------
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/container.go b/container.go
index ffc7276..95bb677 100644
--- a/container.go
+++ b/container.go
@@ -26,8 +26,8 @@ import (
// Container struct
type Container struct {
- container *C.struct_lxc_container
mu sync.RWMutex
+ container *C.struct_lxc_container
verbosity Verbosity
}
diff --git a/lxc-binding.go b/lxc-binding.go
index a45648f..f2f3cce 100644
--- a/lxc-binding.go
+++ b/lxc-binding.go
@@ -116,12 +116,12 @@ func ContainerNames(lxcpath ...string) []string {
// Containers returns the defined and active containers on the system. Only
// containers that could retrieved successfully are returned.
-func Containers(lxcpath ...string) []Container {
- var containers []Container
+func Containers(lxcpath ...string) []*Container {
+ var containers []*Container
for _, v := range ContainerNames(lxcpath...) {
if container, err := NewContainer(v, lxcpath...); err == nil {
- containers = append(containers, *container)
+ containers = append(containers, container)
}
}
@@ -151,12 +151,12 @@ func DefinedContainerNames(lxcpath ...string) []string {
// DefinedContainers returns the defined containers on the system. Only
// containers that could retrieved successfully are returned.
-func DefinedContainers(lxcpath ...string) []Container {
- var containers []Container
+func DefinedContainers(lxcpath ...string) []*Container {
+ var containers []*Container
for _, v := range DefinedContainerNames(lxcpath...) {
if container, err := NewContainer(v, lxcpath...); err == nil {
- containers = append(containers, *container)
+ containers = append(containers, container)
}
}
@@ -186,12 +186,12 @@ func ActiveContainerNames(lxcpath ...string) []string {
// ActiveContainers returns the active containers on the system. Only
// containers that could retrieved successfully are returned.
-func ActiveContainers(lxcpath ...string) []Container {
- var containers []Container
+func ActiveContainers(lxcpath ...string) []*Container {
+ var containers []*Container
for _, v := range ActiveContainerNames(lxcpath...) {
if container, err := NewContainer(v, lxcpath...); err == nil {
- containers = append(containers, *container)
+ containers = append(containers, container)
}
}
More information about the lxc-devel
mailing list