View Issue Details

IDProjectCategoryView StatusLast Update
0002140ardourbugspublic2020-04-19 20:13
Reporterhansfbaier Assigned Totimbyr  
PrioritynormalSeverityblockReproducibilityalways
Status closedResolutionfixed 
PlatformLinux Ubuntu studio gutsyOSLinuxOS Version 2.6.22-14-rt
Summary0002140: UI freezes after playback and modifying midi notes
DescriptionAfter playback and moving the playhead to home
any operations that modify the midi model would freeze the UI.
Steps To Reproduce<space> <space> <home> <create/resize/delete note>
Additional InformationIt seems to be a deadlock problem. Probably the playing code somehow fails
to release its read lock so the write lock of the midi model operation
waits forever.

30 __kernel_vsyscall() 0xffffe410
29 pthread_cond_wait@@GLIBC_2.3.2() 0xb6984676
28 g_static_rw_lock_writer_lock() 0xb757e587
27 Glib::StaticRWLock::writer_lock() /home/jack/src/ardour/libs/glibmm2/glib/glibmm/thread.cc:301 0xb750d0e3
26 ARDOUR::MidiModel::write_lock() /home/jack/src/ardour/libs/ardour/ardour/midi_model.h:61 0xb7d6e492
25 ARDOUR::MidiModel::DeltaCommand::operator() /home/jack/src/ardour/libs/ardour/midi_model.cc:583 0xb7d66a90
24 ARDOUR::MidiModel::apply_command() /home/jack/src/ardour/libs/ardour/midi_model.cc:538 0xb7d643c3
23 MidiRegionView::create_note_at() /home/jack/src/ardour/gtk2_ardour/midi_region_view.cc:377 0x086a8730
22 MidiRegionView::canvas_event() /home/jack/src/ardour/gtk2_ardour/midi_region_view.cc:332 0x086a9735
21 sigc::bound_mem_functor1<bool, MidiRegionView, _GdkEvent*>::operator() /home/jack/src/ardour/libs/sigc++2/sigc++/functors/mem_fun.h:1838 0x086ac039
20 sigc::adaptor_functor<sigc::bound_mem_functor1<bool, MidiRegionView, _GdkEvent*> >::operator()<_GdkEvent* const&>() /home/jack/src/ardour/libs/sigc++2/sigc++/adaptors/adaptor_trait.h:84 0x086ac059
19 sigc::internal::slot_call1<sigc::bound_mem_functor1<bool, MidiRegionView, _GdkEvent*>, bool, _GdkEvent*>::call_it() /home/jack/src/ardour/libs/sigc++2/sigc++/functors/slot.h:137 0x086ac07f
18 sigc::slot1<bool, _GdkEvent*>::operator() /home/jack/src/ardour/libs/sigc++2/sigc++/functors/slot.h:512 0xb6cb472b
17 (anonymous namespace)::Item_signal_event_callback() /home/jack/src/ardour/libs/libgnomecanvasmm/libgnomecanvasmm/item.cc:138 0xb691a8fa
16 gnome_canvas_marshal_BOOLEAN__BOXED() 0xb6970c10
15 g_closure_invoke() 0xb7609772
14 <symbol is not available> 0xb761a323
13 <symbol is not available> 0x08f82b40
12 <symbol is not available> 0xbf925e00
11 <symbol is not available> 0x00000002
10 <symbol is not available> 0xbf925dec
9 <symbol is not available> 0x08eede20
8 <symbol is not available> 0x08eeb014
7 <symbol is not available> 0xb7639678
6 <symbol is not available> 0x094151b0
5 <symbol is not available> 0xbf925de4
4 <symbol is not available> 0x00000175
3 <symbol is not available> 0xbf925e14
2 <symbol is not available> 0x094068b0
1 <symbol is not available> 0x00000000
TagsNo tags attached.

Activities

hansfbaier

2008-03-25 05:17

reporter   ~0004812

It definetely is a deadlock problem.
With the debugger the mutexes read_counter is 1
and want_to_write is one.

So there is a read lock that has not been released.

2008-03-25 09:56

 

bugfix_unbalanced_locks_in_midi_model.diff (4,870 bytes)   
Index: libs/ardour/midi_model.cc
===================================================================
--- libs/ardour/midi_model.cc	(Revision 3179)
+++ libs/ardour/midi_model.cc	(Arbeitskopie)
@@ -36,6 +36,34 @@
 using namespace ARDOUR;
 
 
+void 
+MidiModel::write_lock()        
+{ 
+	_lock.writer_lock(); 
+	_automation_lock.lock(); 
+}
+
+void 
+MidiModel::write_unlock()      
+{ 
+	_lock.writer_unlock(); 
+	_automation_lock.unlock(); 
+}
+
+void 
+MidiModel::read_lock()   const 
+{ 
+	_lock.reader_lock(); 
+	/*_automation_lock.lock();*/ 
+}
+
+void 
+MidiModel::read_unlock() const 
+{ 
+	_lock.reader_unlock(); 
+	/*_automation_lock.unlock();*/ 
+}
+
 // Read iterator (const_iterator)
 
 MidiModel::const_iterator::const_iterator(const MidiModel& model, double t)
@@ -106,18 +134,21 @@
 	if (_event.size() == 0) {
 		//cerr << "Created MIDI iterator @ " << t << " is at end." << endl;
 		_is_end = true;
-		_model->read_unlock();
-		_locked = false;
-	} /*else {
+		if(_locked) {
+			_model->read_unlock();
+			_locked = false;
+		}
+	} else {
 		printf("MIDI Iterator = %X @ %lf\n", _event.type(), _event.time());
-	}*/
+	}
 }
 
 
 MidiModel::const_iterator::~const_iterator()
 {
-	if (_locked)
+	if (_locked) {
 		_model->read_unlock();
+	}
 }
 		
 
@@ -182,22 +213,20 @@
 			type = CC;
 
 	if (type == NOTE_ON) {
-		//cerr << "********** MIDI Iterator = note on" << endl;
+		cerr << "********** MIDI Iterator = note on" << endl;
 		_event = MIDI::Event((*_note_iter)->on_event(), false);
 		_active_notes.push(*_note_iter);
 		++_note_iter;
 	} else if (type == NOTE_OFF) {
-		//cerr << "********** MIDI Iterator = note off" << endl;
+		cerr << "********** MIDI Iterator = note off" << endl;
 		_event = MIDI::Event(_active_notes.top()->off_event(), false);
 		_active_notes.pop();
 	} else if (type == CC) {
-		//cerr << "********** MIDI Iterator = CC" << endl;
+		cerr << "********** MIDI Iterator = CC" << endl;
 		_model->control_to_midi_event(_event, *_control_iter);
 	} else {
-		//cerr << "********** MIDI Iterator = END" << endl;
+		cerr << "********** MIDI Iterator = END" << endl;
 		_is_end = true;
-		_model->read_unlock();
-		_locked = false;
 	}
 
 	assert(_is_end || _event.size() > 0);
@@ -233,9 +262,6 @@
 	_control_iter = other._control_iter;
 	
 	assert( ! _event.owns_buffer());
-	
-	if (_locked)
-		_model->read_lock();
 
 	return *this;
 }
@@ -265,16 +291,16 @@
 size_t
 MidiModel::read(MidiRingBuffer& dst, nframes_t start, nframes_t nframes, nframes_t stamp_offset) const
 {
-	//cerr << this << " MM::read @ " << start << " * " << nframes << " + " << stamp_offset << endl;
-	//cerr << this << " MM # notes: " << n_notes() << endl;
+	cerr << this << " MM::read @ " << start << " * " << nframes << " + " << stamp_offset << endl;
+	cerr << this << " MM # notes: " << n_notes() << endl;
 
 	size_t read_events = 0;
 
 	if (start != _next_read) {
 		_read_iter = const_iterator(*this, (double)start);
-		//cerr << "Repositioning iterator from " << _next_read << " to " << start << endl;
+		cerr << "Repositioning iterator from " << _next_read << " to " << start << endl;
 	} else {
-		//cerr << "Using cached iterator at " << _next_read << endl;
+		cerr << "Using cached iterator at " << _next_read << endl;
 	}
 
 	_next_read = start + nframes;
@@ -282,11 +308,15 @@
 	while (_read_iter != end() && _read_iter->time() < start + nframes) {
 		assert(_read_iter->size() > 0);
 		dst.write(_read_iter->time() + stamp_offset, _read_iter->size(), _read_iter->buffer());
-		//cerr << this << " MM::read event @ " << _read_iter->time() << endl;
+		cerr << this << " MM::read event @ " << _read_iter->time()  
+		     << "type: " << int(_read_iter->type()) 
+		     << "note: " << int(_read_iter->note()) 
+		     << "velocity: " << int(_read_iter->velocity()) 
+		     << endl;
 		++_read_iter;
 		++read_events;
 	}
-
+	
 	return read_events;
 }
 	
Index: libs/ardour/ardour/midi_model.h
===================================================================
--- libs/ardour/ardour/midi_model.h	(Revision 3179)
+++ libs/ardour/ardour/midi_model.h	(Arbeitskopie)
@@ -58,10 +58,10 @@
 	MidiModel(Session& s, size_t size=0);
 	
 	// This is crap.
-	void write_lock()        { _lock.writer_lock(); _automation_lock.lock(); }
-	void write_unlock()      { _lock.writer_unlock(); _automation_lock.unlock(); }
-	void read_lock()   const { _lock.reader_lock(); /*_automation_lock.lock();*/ }
-	void read_unlock() const { _lock.reader_unlock(); /*_automation_lock.unlock();*/ }
+	void write_lock();
+	void write_unlock();
+	void read_lock()   const;
+	void read_unlock() const;
 
 	void clear() { _notes.clear(); }
 
@@ -164,7 +164,7 @@
 		friend class MidiModel;
 
 		const MidiModel* _model;
-		MIDI::Event        _event;
+		MIDI::Event      _event;
 
 		typedef std::priority_queue<
 				boost::shared_ptr<Note>, std::deque< boost::shared_ptr<Note> >,

hansfbaier

2008-03-25 10:00

reporter   ~0004814

There were unbalanced locks in midi_model.cc.

timbyr

2008-04-14 12:47

developer   ~0004865

According to svn log this issue was fixed by reporter in branches/3.0@3211

system

2020-04-19 20:13

developer   ~0021666

Issue has been closed automatically, by Trigger Close Plugin.
Feel free to re-open with additional information if you think the issue is not resolved.

Issue History

Date Modified Username Field Change
2008-03-25 05:13 hansfbaier New Issue
2008-03-25 05:17 hansfbaier Note Added: 0004812
2008-03-25 09:56 hansfbaier File Added: bugfix_unbalanced_locks_in_midi_model.diff
2008-03-25 10:00 hansfbaier Note Added: 0004814
2008-04-14 12:47 timbyr Status new => resolved
2008-04-14 12:47 timbyr Fixed in Version => SVN/MIDI (trunk)
2008-04-14 12:47 timbyr Resolution open => fixed
2008-04-14 12:47 timbyr Assigned To => timbyr
2008-04-14 12:47 timbyr Note Added: 0004865
2020-04-19 20:13 system Note Added: 0021666
2020-04-19 20:13 system Status resolved => closed