Skip to content

Commit 4b800e6

Browse files
committed
RawImageData reference counting delegated to shared_ptr
1 parent f4b9a08 commit 4b800e6

File tree

3 files changed

+7
-25
lines changed

3 files changed

+7
-25
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ cscope.out
1313
*.vcproj
1414
*.vcxproj
1515
.vscode/
16+
CMakeLists.txt.user
1617

1718
# Compiled Object files
1819
*.slo

src/librawspeed/common/RawImage.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ RawImageData::RawImageData(const iPoint2D& _dim, int _bpc, int _cpp)
5757
}
5858

5959
RawImageData::~RawImageData() {
60-
assert(dataRefCount == 0);
6160
mOffset = iPoint2D(0, 0);
6261

6362
destroyData();
@@ -282,28 +281,14 @@ void RawImageData::createBadPixelMap()
282281
}
283282

284283
RawImage::RawImage(RawImageData* p) : p_(p) {
285-
MutexLocker guard(&p_->mymutex);
286-
++p_->dataRefCount;
284+
287285
}
288286

289287
RawImage::RawImage(const RawImage& p) : p_(p.p_) {
290-
MutexLocker guard(&p_->mymutex);
291-
++p_->dataRefCount;
292-
}
293288

294-
RawImage::~RawImage() {
295-
p_->mymutex.Lock();
289+
}
296290

297-
--p_->dataRefCount;
298291

299-
if (p_->dataRefCount == 0) {
300-
p_->mymutex.Unlock();
301-
delete p_;
302-
return;
303-
}
304-
305-
p_->mymutex.Unlock();
306-
}
307292

308293
void RawImageData::transferBadPixelsToMap()
309294
{

src/librawspeed/common/RawImage.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,6 @@ class RawImageData : public ErrorLog {
172172
Mutex mBadPixelMutex; // Mutex for 'mBadPixelPositions, must be used if more
173173
// than 1 thread is accessing vector
174174

175-
private:
176-
uint32_t dataRefCount GUARDED_BY(mymutex) = 0;
177175

178176
protected:
179177
RawImageType dataType;
@@ -191,7 +189,6 @@ class RawImageData : public ErrorLog {
191189
iPoint2D mOffset;
192190
iPoint2D uncropped_dim;
193191
std::unique_ptr<TableLookUp> table;
194-
Mutex mymutex;
195192
};
196193

197194
class RawImageDataU16 final : public RawImageData {
@@ -235,17 +232,16 @@ class RawImageDataFloat final : public RawImageData {
235232
static RawImage create(const iPoint2D& dim,
236233
RawImageType type = RawImageType::UINT16,
237234
uint32_t componentsPerPixel = 1);
238-
RawImageData* operator->() const { return p_; }
239-
RawImageData& operator*() const { return *p_; }
235+
RawImageData* operator->() const { return p_.operator->(); }
236+
RawImageData& operator*() const { return p_.operator*(); }
240237
explicit RawImage(RawImageData* p); // p must not be NULL
241-
~RawImage();
242238
RawImage(const RawImage& p);
243239
RawImage& operator=(const RawImage& p) noexcept;
244240
RawImage& operator=(RawImage&& p) noexcept;
245241

246-
RawImageData* get() { return p_; }
242+
RawImageData* get() { return p_.get(); }
247243
private:
248-
RawImageData* p_; // p_ is never NULL
244+
std::shared_ptr<RawImageData> p_; // p_ is never NULL
249245
};
250246

251247
inline RawImage RawImage::create(RawImageType type) {

0 commit comments

Comments
 (0)