Move Thread classes from Tracker to shared

So that they may be utilized outside of Tracker
This commit is contained in:
John Scipione 2013-10-08 19:46:21 -04:00
parent 4d5508263e
commit fb6cc6d855
6 changed files with 46 additions and 44 deletions

View File

@ -36,15 +36,55 @@ All rights reserved.
#include <Debug.h>
#include <Looper.h>
#include <OS.h>
#include "ObjectList.h"
#include "FunctionObject.h"
#include "Utilities.h"
namespace BPrivate {
class MessengerAutoLocker {
// move this into AutoLock.h
public:
MessengerAutoLocker(BMessenger* messenger)
: fMessenger(messenger),
fHasLock(messenger->LockTarget())
{}
~MessengerAutoLocker()
{
Unlock();
}
bool operator!() const
{
return !fHasLock;
}
bool IsLocked() const
{
return fHasLock;
}
void Unlock()
{
if (fHasLock) {
BLooper* looper;
fMessenger->Target(&looper);
if (looper)
looper->Unlock();
fHasLock = false;
}
}
private:
BMessenger* fMessenger;
bool fHasLock;
};
class SimpleThread {
// this should only be used as a base class,
// subclass needs to add proper locking mechanism
@ -78,6 +118,7 @@ private:
FunctionObject* fFunctor;
};
class ThreadSequence : private SimpleThread {
public:
static void Launch(BObjectList<FunctionObject>*, bool async = true,
@ -93,6 +134,7 @@ private:
BObjectList<FunctionObject>* fFunctorList;
};
// would use SingleParamFunctionObjectWithResult, except mwcc won't handle this
template <class Param1>
class SingleParamFunctionObjectWorkaround : public
@ -105,7 +147,6 @@ public:
{
}
virtual void operator()()
{ (fFunction)(fParam1); }
@ -116,6 +157,7 @@ private:
Param1 fParam1;
};
template <class T>
class SimpleMemberFunctionObjectWorkaround : public
FunctionObjectWithResult<status_t> {

View File

@ -45,6 +45,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
ShakeTrackingFilter.cpp
StringForRate.cpp
StringForSize.cpp
Thread.cpp
Variant.cpp
;

View File

@ -117,7 +117,7 @@ ThreadSequence::Launch(BObjectList<FunctionObject>* list, bool async,
ThreadSequence::ThreadSequence(BObjectList<FunctionObject>* list,
int32 priority)
: SimpleThread(priority),
fFunctorList(list)
fFunctorList(list)
{
Go();
}

View File

@ -83,7 +83,6 @@ for architectureObject in [ MultiArchSubDirSetup ] {
TemplatesMenu.cpp
Tests.cpp
TextWidget.cpp
Thread.cpp
TitleView.cpp
Tracker.cpp
TrackerInitialState.cpp

View File

@ -381,46 +381,6 @@ class LooperAutoLocker {
};
class MessengerAutoLocker {
// move this into AutoLock.h
public:
MessengerAutoLocker(BMessenger* messenger)
: fMessenger(messenger),
fHasLock(messenger->LockTarget())
{}
~MessengerAutoLocker()
{
Unlock();
}
bool operator!() const
{
return !fHasLock;
}
bool IsLocked() const
{
return fHasLock;
}
void Unlock()
{
if (fHasLock) {
BLooper* looper;
fMessenger->Target(&looper);
if (looper)
looper->Unlock();
fHasLock = false;
}
}
private:
BMessenger* fMessenger;
bool fHasLock;
};
class ShortcutFilter : public BMessageFilter {
public:
ShortcutFilter(uint32 shortcutKey, uint32 shortcutModifier,