Hi Guys!
Krzysztof Foltman wrote:
> This looks sort of like #37, and may possibly be fixed by my fix (or, if
> it isn't, then my fix can be wrong!). With JACK on raw MIDI it may work
> because raw MIDI driver is hogging the device and preventing Hydrogen
> from accessing it. Did you reproduce it with beta3 or with trunk? If
> with trunk, does applying my other change (the ALSA MIDI driver minor
> refactoring) improve it?
>
> That's my quick guess at least. The guess is based on the above
> reasoning + double "JackOutput INIT" line in the log + double "***
> Hydrogen audio engine init *** " + message "Error the audio engine is
> not in UNINITIALIZED state" (all classic symptoms of Hydrogen object
> being created twice). Looks very familiar to me - but it's 1am here.
Very close! The problem appears to be that Hydrogen::get_instance() is called
at nearly the same time by two threads in the startup code (one has to do with
opening the first song file, the other for the regular startup code). Here's
the code:
/// Return the Hydrogen instance
Hydrogen* Hydrogen::get_instance()
{
if ( __instance == NULL ) {
__instance = new Hydrogen();
}
return __instance;
}
While the Hydrogen() constructor is executing... someone else calls
get_instance() and, finding a NULL __instance, double-calls the constructor.
That it works with -Xraw but not -Xseq -- I don't have a good explanation.
I think Sebastian said that Torben suggested serializing access to __instance
variables (i.e. using mutexes)... and this is indeed what is needed.
Below is a fix for the problem at hand. Please see that it fixes it for you.
I'll post a complete solution (for all *::get_instance() accessors) during my
lunch break tomorrow. Whether this is the Real Fix for the -Xseq/-Xraw
issue...
this should be done anyway.
Peace,
Gabriel
diff --git a/libs/hydrogen/src/hydrogen.cpp b/libs/hydrogen/src/hydrogen.cpp
index 2f6c915..7c10603 100644
--- a/libs/hydrogen/src/hydrogen.cpp
+++ b/libs/hydrogen/src/hydrogen.cpp
@@ -38,6 +38,9 @@
#include <ctime>
#include <cmath>
+#include <QtCore/QMutex>
+#include <QtCore/QMutexLocker>
+
#include <hydrogen/LocalFileMng.h>
#include <hydrogen/event_queue.h>
#include <hydrogen/adsr.h>
@@ -1743,6 +1746,9 @@ Hydrogen::~Hydrogen()
/// Return the Hydrogen instance
Hydrogen* Hydrogen::get_instance()
{
+ static QMutex _mx;
+ QMutexLocker lk(&_mx);
+
if ( __instance == NULL ) {
__instance = new Hydrogen();
}
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Hydrogen-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hydrogen-devel