From 7f9b60ab3ae1b4ad8b1fd526ccd77ec698a578be Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Fri, 3 Jan 2020 01:04:23 +0300 Subject: [PATCH] Fix race condition error --- mojangtextures/batch_uuids_provider.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mojangtextures/batch_uuids_provider.go b/mojangtextures/batch_uuids_provider.go index d3259c1..b0b1826 100644 --- a/mojangtextures/batch_uuids_provider.go +++ b/mojangtextures/batch_uuids_provider.go @@ -41,8 +41,8 @@ func (s *jobsQueue) Dequeue(n int) []*jobItem { s.lock.Lock() defer s.lock.Unlock() - if n > s.Size() { - n = s.Size() + if n > s.size() { + n = s.size() } items := s.items[0:n] @@ -52,6 +52,13 @@ func (s *jobsQueue) Dequeue(n int) []*jobItem { } func (s *jobsQueue) Size() int { + s.lock.Lock() + defer s.lock.Unlock() + + return s.size() +} + +func (s *jobsQueue) size() int { return len(s.items) }