From 796fdd9316fe755330dc37b7c51dfe652acbc9f1 Mon Sep 17 00:00:00 2001 From: "Jacob Vosmaer (GitLab)" Date: Fri, 6 Apr 2018 11:50:23 +0000 Subject: Revert "Merge branch 'dont-use-atomic' into 'master'" This reverts merge request !653 --- STYLE.md | 13 +------------ internal/middleware/limithandler/testhelper_test.go | 16 +++++----------- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/STYLE.md b/STYLE.md index d72775073..3a6ae2bad 100644 --- a/STYLE.md +++ b/STYLE.md @@ -107,15 +107,4 @@ instead of: func (server) GetBlob(_ *pb.GetBlobRequest, _ pb.BlobService_GetBlobServer) error { return helper.Unimplemented } -``` - -## Concurrency - -The [documentation of "sync/atomic"](https://golang.org/pkg/sync/atomic/) says: - -> These functions require great care to be used correctly. Except for -special, low-level applications, synchronization is better done with -channels or the facilities of the sync package. - -Gitaly is not a low-level application so we should avoid "sync/atomic". -We use channels and [package "sync"](https://golang.org/pkg/sync/). +``` \ No newline at end of file diff --git a/internal/middleware/limithandler/testhelper_test.go b/internal/middleware/limithandler/testhelper_test.go index e197b18f4..40eff4f01 100644 --- a/internal/middleware/limithandler/testhelper_test.go +++ b/internal/middleware/limithandler/testhelper_test.go @@ -1,29 +1,23 @@ package limithandler_test import ( - "sync" + "sync/atomic" pb "gitlab.com/gitlab-org/gitaly/internal/middleware/limithandler/testpb" "golang.org/x/net/context" ) type server struct { - requestCount int - sync.Mutex - blockCh chan (struct{}) + requestCount uint64 + blockCh chan (struct{}) } func (s *server) registerRequest() { - s.Lock() - s.requestCount++ - s.Unlock() + atomic.AddUint64(&s.requestCount, 1) } func (s *server) getRequestCount() int { - s.Lock() - count := s.requestCount - s.Unlock() - return count + return int(atomic.LoadUint64(&s.requestCount)) } func (s *server) Unary(ctx context.Context, in *pb.UnaryRequest) (*pb.UnaryResponse, error) { -- cgit v1.2.3