Hi Jérémy,

On Tue, 15 Dec 2009, Jérémy Zurcher wrote:

   - don't use all these static methods, or go all static

I don't follow.  What do you mean?

- singleton pattern is used amongst other to not explicitly instanciate and destroy objects, so do so

Some comments on this:

  + The explicit instantiation is required to make
    sure that the classes initialize in the correct
    order.  We kept getting bugs because of a
    tangled web of dependencies between various
    singletons like Logger, Hydrogen, AudioEngine,
    Preferences, Sampler, Playlist, etc.

  + They have to be instantiated /somewhere/.  If
    the constructor is done at the global scope,
    we have no control of the order in which they
    are created.

  + The singleton pattern is abused in Hydrogen.
    With the exception of Logger (and /maybe/
    Preferences), there is no reason for these
    classes to be singleton.  They amount to
    being global variables.

  + Since they're just global variables, why not
    make them global variables instead of
    singletons?[1]

  + For Composite/Tritium, I have UN-singleton-ed
    almost all the classes (as of yesterday):
    
http://gitorious.org/composite/composite/commit/cafcb6416220b33d192a506275f3ab793c437a58
    (Note that Tritium::Engine used to be
    H2Core::Hydrogen.)  The GUI uses a global
    variable for the audio engine.

I also would like to propose to remove the thread from Logger class.

IMO this thread is nothing but resources consuming when things are running well.
And not really usefull when everything goes bad.

While processing audio, there must NOT be any IO, dynamic memory allocation, or anything that "could wait a long time" (like a mutex).[2] However, we wish to be able to have some manner of logging from within the audio parts of Hydrogen.

Therefore, a queue was set up to pass the messages to the Logger (which can be done in real-ish time[3]). The Logger has its own thread where it can output the messages at its leisure.

If you remove the logger thread, you will need some other thread (GUI?) to do its work... because it must not happen in the audio parts of the application.

Peace,
Gabriel

[1] See: Hyslop and Sutter, "Once is Not Enough", Dr. Dobb's
    Journal March 1, 2003 (http://www.ddj.com/cpp/184401625)
[2] See: 
http://jackaudio.org/files/docs/html/group__ClientCallbacks.html#ga62351a5803421b6c21b9ffb9124801ef
[3] QString's constructor and assignment operators
    are not realtime safe... so they technically should
    not be used in the audio sections either.  But,
    they remain because the benefits outweight the risks.
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Hydrogen-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hydrogen-devel

Reply via email to