hrev46742 adds 1 changeset to branch 'master' old head: c71a35bdd5f115d82a0c35b59ab4f6b9077c5588 new head: 1d63ae96cd791d4433383720644e8a2089655830 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=1d63ae9+%5Ec71a35b ---------------------------------------------------------------------------- 1d63ae9: libmidi2: fix BMidiRoster init. * should fix #10175. [ Jérôme Duval <jerome.duval@xxxxxxxxx> ] ---------------------------------------------------------------------------- Revision: hrev46742 Commit: 1d63ae96cd791d4433383720644e8a2089655830 URL: http://cgit.haiku-os.org/haiku/commit/?id=1d63ae9 Author: Jérôme Duval <jerome.duval@xxxxxxxxx> Date: Wed Jan 22 18:12:59 2014 UTC Ticket: https://dev.haiku-os.org/ticket/10175 ---------------------------------------------------------------------------- 1 file changed, 14 insertions(+), 13 deletions(-) src/kits/midi2/MidiRoster.cpp | 27 ++++++++++++++------------- ---------------------------------------------------------------------------- diff --git a/src/kits/midi2/MidiRoster.cpp b/src/kits/midi2/MidiRoster.cpp index 93a9a16..6ea0248 100644 --- a/src/kits/midi2/MidiRoster.cpp +++ b/src/kits/midi2/MidiRoster.cpp @@ -14,6 +14,9 @@ #include "MidiRosterLooper.h" #include "protocol.h" +#include <pthread.h> + + using namespace BPrivate; // The midi_debug_level and midi_dispatcher_priority symbols @@ -33,7 +36,10 @@ int32 midi_dispatcher_priority = B_REAL_TIME_PRIORITY; // The one and only BMidiRoster instance, which is created // the first time the client app calls MidiRoster(). It is // destroyed by the BMidiRosterKiller when the app quits. -static BMidiRoster* roster = NULL; +static BMidiRoster* sRoster = NULL; + +static pthread_once_t sInitOnce = PTHREAD_ONCE_INIT; + // Destroys the BMidiRoster instance when the app quits. namespace BPrivate @@ -42,7 +48,11 @@ namespace BPrivate { ~BMidiRosterKiller() { - delete roster; + delete sRoster; + } + + static void CreateRoster() { + sRoster = new BMidiRoster(); } } midi_roster_killer; @@ -206,11 +216,9 @@ BMidiRoster::Unregister(BMidiEndpoint* endp) BMidiRoster* BMidiRoster::MidiRoster() { - if (roster == NULL) { - new BMidiRoster(); - } + pthread_once(&sInitOnce, BPrivate::BMidiRosterKiller::CreateRoster); - return roster; + return sRoster; } @@ -218,13 +226,6 @@ BMidiRoster::BMidiRoster() { TRACE(("BMidiRoster::BMidiRoster")) - // While our constructor is executing, some function may - // call MidiRoster() again, which causes an endless loop. - // To prevent this, we immediately fill in "roster"; now - // subsequent calls to MidiRoster() won't mess up things. - - roster = this; - fLooper = new BMidiRosterLooper(); if (!fLooper->Init(this))