* 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:
Michael Lotz 2010-01-31 00:25:10 +00:00
parent d6a142a912
commit 497aa62c2f
2 changed files with 50 additions and 3 deletions

View File

@ -3022,12 +3022,20 @@ TrackerOpenWith(const BMessage *refs)
return B_OK;
}
static void
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),
B_NORMAL_PRIORITY, "LaunchTask");
BMessage *task = new BMessage;
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

View File

@ -107,6 +107,40 @@ namespace BPrivate {
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
InitIconPreloader()
{
@ -204,11 +238,16 @@ TTracker::TTracker()
//This is how often it should update the free space bar on the volume icons
SetPulseRate(1000000);
gLaunchLooper = new LaunchLooper();
gLaunchLooper->Run();
}
TTracker::~TTracker()
{
gLaunchLooper->Lock();
gLaunchLooper->Quit();
}