Move Thread classes from Tracker to shared
So that they may be utilized outside of Tracker
This commit is contained in:
parent
4d5508263e
commit
fb6cc6d855
@ -36,15 +36,55 @@ All rights reserved.
|
|||||||
|
|
||||||
|
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
|
#include <Looper.h>
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
|
|
||||||
#include "ObjectList.h"
|
#include "ObjectList.h"
|
||||||
#include "FunctionObject.h"
|
#include "FunctionObject.h"
|
||||||
#include "Utilities.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace BPrivate {
|
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 {
|
class SimpleThread {
|
||||||
// this should only be used as a base class,
|
// this should only be used as a base class,
|
||||||
// subclass needs to add proper locking mechanism
|
// subclass needs to add proper locking mechanism
|
||||||
@ -78,6 +118,7 @@ private:
|
|||||||
FunctionObject* fFunctor;
|
FunctionObject* fFunctor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ThreadSequence : private SimpleThread {
|
class ThreadSequence : private SimpleThread {
|
||||||
public:
|
public:
|
||||||
static void Launch(BObjectList<FunctionObject>*, bool async = true,
|
static void Launch(BObjectList<FunctionObject>*, bool async = true,
|
||||||
@ -93,6 +134,7 @@ private:
|
|||||||
BObjectList<FunctionObject>* fFunctorList;
|
BObjectList<FunctionObject>* fFunctorList;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// would use SingleParamFunctionObjectWithResult, except mwcc won't handle this
|
// would use SingleParamFunctionObjectWithResult, except mwcc won't handle this
|
||||||
template <class Param1>
|
template <class Param1>
|
||||||
class SingleParamFunctionObjectWorkaround : public
|
class SingleParamFunctionObjectWorkaround : public
|
||||||
@ -105,7 +147,6 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual void operator()()
|
virtual void operator()()
|
||||||
{ (fFunction)(fParam1); }
|
{ (fFunction)(fParam1); }
|
||||||
|
|
||||||
@ -116,6 +157,7 @@ private:
|
|||||||
Param1 fParam1;
|
Param1 fParam1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class SimpleMemberFunctionObjectWorkaround : public
|
class SimpleMemberFunctionObjectWorkaround : public
|
||||||
FunctionObjectWithResult<status_t> {
|
FunctionObjectWithResult<status_t> {
|
@ -45,6 +45,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
|||||||
ShakeTrackingFilter.cpp
|
ShakeTrackingFilter.cpp
|
||||||
StringForRate.cpp
|
StringForRate.cpp
|
||||||
StringForSize.cpp
|
StringForSize.cpp
|
||||||
|
Thread.cpp
|
||||||
Variant.cpp
|
Variant.cpp
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ ThreadSequence::Launch(BObjectList<FunctionObject>* list, bool async,
|
|||||||
ThreadSequence::ThreadSequence(BObjectList<FunctionObject>* list,
|
ThreadSequence::ThreadSequence(BObjectList<FunctionObject>* list,
|
||||||
int32 priority)
|
int32 priority)
|
||||||
: SimpleThread(priority),
|
: SimpleThread(priority),
|
||||||
fFunctorList(list)
|
fFunctorList(list)
|
||||||
{
|
{
|
||||||
Go();
|
Go();
|
||||||
}
|
}
|
@ -83,7 +83,6 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
|||||||
TemplatesMenu.cpp
|
TemplatesMenu.cpp
|
||||||
Tests.cpp
|
Tests.cpp
|
||||||
TextWidget.cpp
|
TextWidget.cpp
|
||||||
Thread.cpp
|
|
||||||
TitleView.cpp
|
TitleView.cpp
|
||||||
Tracker.cpp
|
Tracker.cpp
|
||||||
TrackerInitialState.cpp
|
TrackerInitialState.cpp
|
||||||
|
@ -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 {
|
class ShortcutFilter : public BMessageFilter {
|
||||||
public:
|
public:
|
||||||
ShortcutFilter(uint32 shortcutKey, uint32 shortcutModifier,
|
ShortcutFilter(uint32 shortcutKey, uint32 shortcutModifier,
|
||||||
|
Loading…
Reference in New Issue
Block a user