diff options
author | Jacob Vosmaer (GitLab) <jacob@gitlab.com> | 2018-04-06 14:50:23 +0300 |
---|---|---|
committer | Jacob Vosmaer (GitLab) <jacob@gitlab.com> | 2018-04-06 14:50:23 +0300 |
commit | 796fdd9316fe755330dc37b7c51dfe652acbc9f1 (patch) | |
tree | 2157f121d62b72d1d1795e7eff08ef855b2f0802 | |
parent | 18818d2fc5c6e8a2f197883b56774e57d8024a96 (diff) |
Revert "Merge branch 'dont-use-atomic' into 'master'"
This reverts merge request !653
-rw-r--r-- | STYLE.md | 13 | ||||
-rw-r--r-- | internal/middleware/limithandler/testhelper_test.go | 16 |
2 files changed, 6 insertions, 23 deletions
@@ -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) { |