@@ -14,6 +14,9 @@
|
|||||||
#include "MidiRosterLooper.h"
|
#include "MidiRosterLooper.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace BPrivate;
|
using namespace BPrivate;
|
||||||
|
|
||||||
// The midi_debug_level and midi_dispatcher_priority symbols
|
// 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 one and only BMidiRoster instance, which is created
|
||||||
// the first time the client app calls MidiRoster(). It is
|
// the first time the client app calls MidiRoster(). It is
|
||||||
// destroyed by the BMidiRosterKiller when the app quits.
|
// 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.
|
// Destroys the BMidiRoster instance when the app quits.
|
||||||
namespace BPrivate
|
namespace BPrivate
|
||||||
@@ -42,7 +48,11 @@ namespace BPrivate
|
|||||||
{
|
{
|
||||||
~BMidiRosterKiller()
|
~BMidiRosterKiller()
|
||||||
{
|
{
|
||||||
delete roster;
|
delete sRoster;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CreateRoster() {
|
||||||
|
sRoster = new BMidiRoster();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
midi_roster_killer;
|
midi_roster_killer;
|
||||||
@@ -206,11 +216,9 @@ BMidiRoster::Unregister(BMidiEndpoint* endp)
|
|||||||
BMidiRoster*
|
BMidiRoster*
|
||||||
BMidiRoster::MidiRoster()
|
BMidiRoster::MidiRoster()
|
||||||
{
|
{
|
||||||
if (roster == NULL) {
|
pthread_once(&sInitOnce, BPrivate::BMidiRosterKiller::CreateRoster);
|
||||||
new BMidiRoster();
|
|
||||||
}
|
|
||||||
|
|
||||||
return roster;
|
return sRoster;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -218,13 +226,6 @@ BMidiRoster::BMidiRoster()
|
|||||||
{
|
{
|
||||||
TRACE(("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();
|
fLooper = new BMidiRosterLooper();
|
||||||
|
|
||||||
if (!fLooper->Init(this))
|
if (!fLooper->Init(this))
|
||||||
|
|||||||
Reference in New Issue
Block a user