Skip to content

Commit

Permalink
Fixed threading issues on RAWRead.cpp.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggarra13 committed Sep 23, 2023
1 parent adc93f8 commit a08f7bd
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/tlIO/RAWRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ namespace tl
{
int ret;
{
// LibRaw is not thread safe. We use a static mutex
// so only one threads constructs a LibRaw at a time.
static std::mutex mutex;
std::lock_guard<std::mutex> lock(mutex);
iProcessor.reset(new LibRaw());
}
Expand Down Expand Up @@ -192,9 +189,12 @@ namespace tl
const libraw_image_sizes_t& sizes(iProcessor->imgdata.sizes);

// Let us unpack the image
ret = iProcessor->unpack();
LIBRAW_ERROR(unpack, ret);

{
std::lock_guard<std::mutex> lock(mutex);
ret = iProcessor->unpack();
LIBRAW_ERROR(unpack, ret);
}

ret = iProcessor->raw2image_ex(/*substract_black=*/true);
LIBRAW_ERROR(raw2image_ex, ret);

Expand Down Expand Up @@ -259,6 +259,8 @@ namespace tl
protected:
void _openFile(const std::string& fileName) const
{
std::lock_guard<std::mutex> lock(mutex);

int ret;
if (_memory)
{
Expand Down Expand Up @@ -306,13 +308,18 @@ namespace tl
}

private:
// LibRaw is not thread safe. We use a static mutex
// so only one threads constructs a LibRaw at a time.
static std::mutex mutex;
std::unique_ptr<LibRaw> iProcessor;
libraw_processed_image_t* image = nullptr;
io::Info _info;
const file::MemoryRead* _memory;
};
}

std::mutex File::mutex;

void Read::_init(
const file::Path& path,
const std::vector<file::MemoryRead>& memory,
Expand Down

0 comments on commit a08f7bd

Please sign in to comment.