summaryrefslogtreecommitdiff
path: root/src/lib/film.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2019-10-09 00:43:22 +0200
committerCarl Hetherington <cth@carlh.net>2019-10-09 00:43:22 +0200
commit1580bdc52a257870c908f32d2abe6fed84d83c50 (patch)
treede57d49257fd4805b0674b2a041736e0e3b5cb58 /src/lib/film.cc
parent940b4a72b6242c19570acc7a629ce271de565322 (diff)
Fix cross-thread access to info files. May help with #1618.
Diffstat (limited to 'src/lib/film.cc')
-rw-r--r--src/lib/film.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/lib/film.cc b/src/lib/film.cc
index dcaa73754..e85543b80 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -1740,3 +1740,37 @@ Film::marker (dcp::Marker type) const
}
return i->second;
}
+
+shared_ptr<InfoFileHandle>
+Film::info_file_handle (DCPTimePeriod period, bool read) const
+{
+ return shared_ptr<InfoFileHandle> (new InfoFileHandle(_info_file_mutex, info_file(period), read));
+}
+
+InfoFileHandle::InfoFileHandle (boost::mutex& mutex, boost::filesystem::path file, bool read)
+ : _lock (mutex)
+ , _file (file)
+{
+ if (read) {
+ _handle = fopen_boost (file, "rb");
+ if (!_handle) {
+ throw OpenFileError (file, errno, OpenFileError::READ);
+ }
+ } else {
+ bool const exists = boost::filesystem::exists (file);
+ if (exists) {
+ _handle = fopen_boost (file, "r+b");
+ } else {
+ _handle = fopen_boost (file, "wb");
+ }
+
+ if (!_handle) {
+ throw OpenFileError (file, errno, exists ? OpenFileError::READ_WRITE : OpenFileError::WRITE);
+ }
+ }
+}
+
+InfoFileHandle::~InfoFileHandle ()
+{
+ fclose (_handle);
+}