Tidy up content mutexes slightly.
authorCarl Hetherington <cth@carlh.net>
Wed, 14 Aug 2013 15:11:29 +0000 (16:11 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 14 Aug 2013 15:11:29 +0000 (16:11 +0100)
src/lib/content.cc
src/lib/content.h
src/lib/sndfile_content.cc

index 9508144913bc5af335358d54b1e20e806381898e..44b52a4715597a68025a9052f939756573d2f5ba 100644 (file)
@@ -71,6 +71,7 @@ void
 Content::as_xml (xmlpp::Node* node) const
 {
        boost::mutex::scoped_lock lm (_mutex);
+       
        node->add_child("Path")->add_child_text (_path.string());
        node->add_child("Digest")->add_child_text (_digest);
        node->add_child("Position")->add_child_text (lexical_cast<string> (_position));
@@ -81,14 +82,18 @@ Content::as_xml (xmlpp::Node* node) const
 void
 Content::examine (shared_ptr<Job>)
 {
+       boost::mutex::scoped_lock lm (_mutex);
+       boost::filesystem::path p = _path;
+       lm.unlock ();
+       
        string d;
-       if (boost::filesystem::is_regular_file (_path)) {
-               d = md5_digest (_path);
+       if (boost::filesystem::is_regular_file (p)) {
+               d = md5_digest (p);
        } else {
-               d = md5_digest_directory (_path);
+               d = md5_digest_directory (p);
        }
-       
-       boost::mutex::scoped_lock lm (_mutex);
+
+       lm.lock ();
        _digest = d;
 }
 
@@ -158,7 +163,7 @@ Content::technical_summary () const
 Time
 Content::length_after_trim () const
 {
-       return full_length () - _trim_start - _trim_end;
+       return full_length() - trim_start() - trim_end();
 }
 
 /** @param t A time relative to the start of this content (not the position).
index e3f5597527fd240ee4ee4e4028f878adc0e1b7c7..3c57dddbe5847289fab8211439f4cf23a0f593ae 100644 (file)
@@ -114,6 +114,10 @@ protected:
        void signal_changed (int);
 
        boost::weak_ptr<const Film> _film;
+
+       /** _mutex which should be used to protect accesses, as examine
+           jobs can update content state in threads other than the main one.
+       */
        mutable boost::mutex _mutex;
 
 private:
index 7d09f715c9746aed7572aa09746e972de93d8cb5..d57cf04e3413b4b81baa97752c4ea0987ac881a3 100644 (file)
@@ -117,9 +117,13 @@ SndfileContent::examine (shared_ptr<Job> job)
        signal_changed (AudioContentProperty::AUDIO_LENGTH);
        signal_changed (AudioContentProperty::AUDIO_FRAME_RATE);
 
-       /* XXX: do this in signal_changed...? */
-       _audio_mapping = AudioMapping (_audio_channels);
-       _audio_mapping.make_default ();
+       {
+               boost::mutex::scoped_lock lm (_mutex);
+               /* XXX: do this in signal_changed...? */
+               _audio_mapping = AudioMapping (_audio_channels);
+               _audio_mapping.make_default ();
+       }
+       
        signal_changed (AudioContentProperty::AUDIO_MAPPING);
 }
 
@@ -129,9 +133,10 @@ SndfileContent::as_xml (xmlpp::Node* node) const
        node->add_child("Type")->add_child_text ("Sndfile");
        Content::as_xml (node);
        AudioContent::as_xml (node);
-       node->add_child("AudioChannels")->add_child_text (lexical_cast<string> (_audio_channels));
-       node->add_child("AudioLength")->add_child_text (lexical_cast<string> (_audio_length));
-       node->add_child("AudioFrameRate")->add_child_text (lexical_cast<string> (_audio_frame_rate));
+
+       node->add_child("AudioChannels")->add_child_text (lexical_cast<string> (audio_channels ()));
+       node->add_child("AudioLength")->add_child_text (lexical_cast<string> (audio_length ()));
+       node->add_child("AudioFrameRate")->add_child_text (lexical_cast<string> (content_audio_frame_rate ()));
        _audio_mapping.as_xml (node->add_child("AudioMapping"));
 }