[haiku-commits] r35351 - haiku/trunk/src/kits/tracker

  • From: mmlr@xxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 31 Jan 2010 01:25:10 +0100 (CET)

Author: mmlr
Date: 2010-01-31 01:25:10 +0100 (Sun, 31 Jan 2010)
New Revision: 35351
Changeset: http://dev.haiku-os.org/changeset/35351/haiku
Ticket: http://dev.haiku-os.org/ticket/698

Modified:
   haiku/trunk/src/kits/tracker/FSUtils.cpp
   haiku/trunk/src/kits/tracker/Tracker.cpp
Log:
* 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.


Modified: haiku/trunk/src/kits/tracker/FSUtils.cpp
===================================================================
--- haiku/trunk/src/kits/tracker/FSUtils.cpp    2010-01-30 20:33:48 UTC (rev 
35350)
+++ haiku/trunk/src/kits/tracker/FSUtils.cpp    2010-01-31 00:25:10 UTC (rev 
35351)
@@ -3022,12 +3022,20 @@
        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

Modified: haiku/trunk/src/kits/tracker/Tracker.cpp
===================================================================
--- haiku/trunk/src/kits/tracker/Tracker.cpp    2010-01-30 20:33:48 UTC (rev 
35350)
+++ haiku/trunk/src/kits/tracker/Tracker.cpp    2010-01-31 00:25:10 UTC (rev 
35351)
@@ -107,6 +107,40 @@
 
 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 @@
 
        //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();
 }
 
 


Other related posts:

  • » [haiku-commits] r35351 - haiku/trunk/src/kits/tracker - mmlr