Ver código fonte

libnetwork/datastore: un-export Mutex

Keep the mutex internal to the DataStore.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 anos atrás
pai
commit
c14a9f5b3d
1 arquivos alterados com 11 adições e 11 exclusões
  1. 11 11
      libnetwork/datastore/datastore.go

+ 11 - 11
libnetwork/datastore/datastore.go

@@ -41,10 +41,10 @@ var (
 )
 )
 
 
 type datastore struct {
 type datastore struct {
+	mu    sync.Mutex
 	scope string
 	scope string
 	store store.Store
 	store store.Store
 	cache *cache
 	cache *cache
-	sync.Mutex
 }
 }
 
 
 // KVObject is Key/Value interface used by objects to be part of the DataStore
 // KVObject is Key/Value interface used by objects to be part of the DataStore
@@ -254,8 +254,8 @@ func (ds *datastore) PutObjectAtomic(kvObject KVObject) error {
 		pair     *store.KVPair
 		pair     *store.KVPair
 		err      error
 		err      error
 	)
 	)
-	ds.Lock()
-	defer ds.Unlock()
+	ds.mu.Lock()
+	defer ds.mu.Unlock()
 
 
 	if kvObject == nil {
 	if kvObject == nil {
 		return types.BadRequestErrorf("invalid KV Object : nil")
 		return types.BadRequestErrorf("invalid KV Object : nil")
@@ -299,8 +299,8 @@ add_cache:
 
 
 // GetObject returns a record matching the key
 // GetObject returns a record matching the key
 func (ds *datastore) GetObject(key string, o KVObject) error {
 func (ds *datastore) GetObject(key string, o KVObject) error {
-	ds.Lock()
-	defer ds.Unlock()
+	ds.mu.Lock()
+	defer ds.mu.Unlock()
 
 
 	if ds.cache != nil {
 	if ds.cache != nil {
 		return ds.cache.get(o)
 		return ds.cache.get(o)
@@ -333,8 +333,8 @@ func (ds *datastore) ensureParent(parent string) error {
 }
 }
 
 
 func (ds *datastore) List(key string, kvObject KVObject) ([]KVObject, error) {
 func (ds *datastore) List(key string, kvObject KVObject) ([]KVObject, error) {
-	ds.Lock()
-	defer ds.Unlock()
+	ds.mu.Lock()
+	defer ds.mu.Unlock()
 
 
 	if ds.cache != nil {
 	if ds.cache != nil {
 		return ds.cache.list(kvObject)
 		return ds.cache.list(kvObject)
@@ -388,8 +388,8 @@ func (ds *datastore) iterateKVPairsFromStore(key string, kvObject KVObject, call
 }
 }
 
 
 func (ds *datastore) Map(key string, kvObject KVObject) (map[string]KVObject, error) {
 func (ds *datastore) Map(key string, kvObject KVObject) (map[string]KVObject, error) {
-	ds.Lock()
-	defer ds.Unlock()
+	ds.mu.Lock()
+	defer ds.mu.Unlock()
 
 
 	kvol := make(map[string]KVObject)
 	kvol := make(map[string]KVObject)
 	cb := func(key string, val KVObject) {
 	cb := func(key string, val KVObject) {
@@ -405,8 +405,8 @@ func (ds *datastore) Map(key string, kvObject KVObject) (map[string]KVObject, er
 
 
 // DeleteObjectAtomic performs atomic delete on a record
 // DeleteObjectAtomic performs atomic delete on a record
 func (ds *datastore) DeleteObjectAtomic(kvObject KVObject) error {
 func (ds *datastore) DeleteObjectAtomic(kvObject KVObject) error {
-	ds.Lock()
-	defer ds.Unlock()
+	ds.mu.Lock()
+	defer ds.mu.Unlock()
 
 
 	if kvObject == nil {
 	if kvObject == nil {
 		return types.BadRequestErrorf("invalid KV Object : nil")
 		return types.BadRequestErrorf("invalid KV Object : nil")