* Provide a LaunchLooper that receives launch messages and executes the launch
functions provided with the given arguments. * Make use of that looper to replace spawning a thread for each launch task. On the one side this reduces the amount of used threads (and should fix #698) and on the other side it makes the order in which refs are sent a bit more predictable. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35351 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -3022,12 +3022,20 @@ TrackerOpenWith(const BMessage *refs)
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
AsynchLaunchBinder(void (*func)(const entry_ref *, const BMessage *, bool on),
|
AsynchLaunchBinder(void (*func)(const entry_ref *, const BMessage *, bool on),
|
||||||
const entry_ref *entry, const BMessage *message, bool on)
|
const entry_ref *appRef, const BMessage *refs, bool openWithOK)
|
||||||
{
|
{
|
||||||
Thread::Launch(NewFunctionObject(func, entry, message, on),
|
BMessage *task = new BMessage;
|
||||||
B_NORMAL_PRIORITY, "LaunchTask");
|
task->AddPointer("function", (void *)func);
|
||||||
|
task->AddMessage("refs", refs);
|
||||||
|
task->AddBool("openWithOK", openWithOK);
|
||||||
|
if (appRef != NULL)
|
||||||
|
task->AddRef("appRef", appRef);
|
||||||
|
|
||||||
|
extern BLooper *gLaunchLooper;
|
||||||
|
gLaunchLooper->PostMessage(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
|||||||
@@ -107,6 +107,40 @@ namespace BPrivate {
|
|||||||
|
|
||||||
NodePreloader *gPreloader = NULL;
|
NodePreloader *gPreloader = NULL;
|
||||||
|
|
||||||
|
class LaunchLooper : public BLooper {
|
||||||
|
public:
|
||||||
|
LaunchLooper()
|
||||||
|
:
|
||||||
|
BLooper("launch looper")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void
|
||||||
|
MessageReceived(BMessage *message)
|
||||||
|
{
|
||||||
|
void (*function)(const entry_ref *, const BMessage *, bool);
|
||||||
|
BMessage refs;
|
||||||
|
bool openWithOK;
|
||||||
|
entry_ref appRef;
|
||||||
|
|
||||||
|
if (message->FindPointer("function", (void **)&function) != B_OK
|
||||||
|
|| message->FindMessage("refs", &refs) != B_OK
|
||||||
|
|| message->FindBool("openWithOK", &openWithOK) != B_OK) {
|
||||||
|
printf("incomplete launch message\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message->FindRef("appRef", &appRef) == B_OK)
|
||||||
|
function(&appRef, &refs, openWithOK);
|
||||||
|
else
|
||||||
|
function(NULL, &refs, openWithOK);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
BLooper *gLaunchLooper = NULL;
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
void
|
void
|
||||||
InitIconPreloader()
|
InitIconPreloader()
|
||||||
{
|
{
|
||||||
@@ -204,11 +238,16 @@ TTracker::TTracker()
|
|||||||
|
|
||||||
//This is how often it should update the free space bar on the volume icons
|
//This is how often it should update the free space bar on the volume icons
|
||||||
SetPulseRate(1000000);
|
SetPulseRate(1000000);
|
||||||
|
|
||||||
|
gLaunchLooper = new LaunchLooper();
|
||||||
|
gLaunchLooper->Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TTracker::~TTracker()
|
TTracker::~TTracker()
|
||||||
{
|
{
|
||||||
|
gLaunchLooper->Lock();
|
||||||
|
gLaunchLooper->Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user