Merge "FileImage: make thread-safe" into qt-dev

This commit is contained in:
Alistair Strachan 2019-04-13 23:23:33 +00:00 committed by Android (Google) Code Review
commit e4a2c3af61
1 changed files with 9 additions and 4 deletions

View File

@ -205,6 +205,8 @@ class FileImage(Image):
self.clobbered_blocks = RangeSet()
self.extended = RangeSet()
self.generator_lock = threading.Lock()
self.hashtree_info = None
if hashtree_info_generator:
self.hashtree_info = hashtree_info_generator.Generate(self)
@ -236,10 +238,13 @@ class FileImage(Image):
self._file.close()
def _GetRangeData(self, ranges):
for s, e in ranges:
self._file.seek(s * self.blocksize)
for _ in range(s, e):
yield self._file.read(self.blocksize)
# Use a lock to protect the generator so that we will not run two
# instances of this generator on the same object simultaneously.
with self.generator_lock:
for s, e in ranges:
self._file.seek(s * self.blocksize)
for _ in range(s, e):
yield self._file.read(self.blocksize)
def RangeSha1(self, ranges):
h = sha1()