added start() method that takes a Poco::SharedPtr to a Runnable

This commit is contained in:
Günter Obiltschnig
2019-02-23 13:46:54 -05:00
parent e3e8c3474b
commit b961ea8148
2 changed files with 47 additions and 34 deletions

View File

@@ -52,7 +52,7 @@ class Foundation_API Thread: private ThreadImpl
/// Furthermore, a thread can be assigned a name.
/// The name of a thread can be changed at any time.
{
public:
public:
typedef ThreadImpl::TIDImpl TID;
using ThreadImpl::Callable;
@@ -66,7 +66,7 @@ public:
PRIO_HIGH = PRIO_HIGH_IMPL, /// A higher than normal thread priority.
PRIO_HIGHEST = PRIO_HIGHEST_IMPL /// The highest thread priority.
};
enum Policy
{
POLICY_DEFAULT = POLICY_DEFAULT_IMPL
@@ -74,10 +74,10 @@ public:
Thread();
/// Creates a thread. Call start() to start it.
Thread(const std::string& name);
/// Creates a named thread. Call start() to start it.
~Thread();
/// Destroys the thread.
@@ -112,17 +112,17 @@ public:
/// a scheduling policy can be specified. The policy is currently
/// only used on POSIX platforms where the values SCHED_OTHER (default),
/// SCHED_FIFO and SCHED_RR are supported.
int getOSPriority() const;
/// Returns the thread's priority, expressed as an operating system
/// specific priority value.
///
/// May return 0 if the priority has not been explicitly set.
static int getMinOSPriority(int policy = POLICY_DEFAULT);
/// Returns the minimum operating system-specific priority value,
/// which can be passed to setOSPriority() for the given policy.
static int getMaxOSPriority(int policy = POLICY_DEFAULT);
/// Returns the maximum operating system-specific priority value,
/// which can be passed to setOSPriority() for the given policy.
@@ -144,6 +144,12 @@ public:
/// valid during the entire lifetime of the thread, as
/// only a reference to it is stored internally.
void start(Poco::SharedPtr<Runnable> pTarget);
/// Starts the thread with the given target.
///
/// The Thread ensures that the given target stays
/// alive while the thread is running.
void start(Callable target, void* pData = 0);
/// Starts the thread with the given target and parameter.
@@ -155,15 +161,15 @@ public:
}
void join();
/// Waits until the thread completes execution.
/// Waits until the thread completes execution.
/// If multiple threads try to join the same
/// thread, the result is undefined.
void join(long milliseconds);
/// Waits for at most the given interval for the thread
/// to complete. Throws a TimeoutException if the thread
/// does not complete within the specified time interval.
bool tryJoin(long milliseconds);
/// Waits for at most the given interval for the thread
/// to complete. Returns true if the thread has finished,
@@ -175,9 +181,9 @@ public:
static bool trySleep(long milliseconds);
/// Starts an interruptible sleep. When trySleep() is called,
/// the thread will remain suspended until:
/// - the timeout expires or
/// - the timeout expires or
/// - wakeUp() is called
///
///
/// Function returns true if sleep attempt was completed, false
/// if sleep was interrupted by a wakeUp() call.
/// A frequent scenario where trySleep()/wakeUp() pair of functions
@@ -185,13 +191,13 @@ public:
/// with periodic activity between the idle times; trying to sleep
/// (as opposed to sleeping) allows immediate ending of idle thread
/// from the outside.
///
/// The trySleep() and wakeUp() calls should be used with
/// understanding that the suspended state is not a true sleep,
/// but rather a state of waiting for an event, with timeout
/// expiration. This makes order of calls significant; calling
/// wakeUp() before calling trySleep() will prevent the next
/// trySleep() call to actually suspend the thread (which, in
///
/// The trySleep() and wakeUp() calls should be used with
/// understanding that the suspended state is not a true sleep,
/// but rather a state of waiting for an event, with timeout
/// expiration. This makes order of calls significant; calling
/// wakeUp() before calling trySleep() will prevent the next
/// trySleep() call to actually suspend the thread (which, in
/// some scenarios, may be desirable behavior).
void wakeUp();
@@ -212,7 +218,7 @@ public:
/// If the current thread is the main thread, 0 is returned.
static TID currentTid();
/// Returns the native thread ID for the current thread.
/// Returns the native thread ID for the current thread.
protected:
ThreadLocalStorage& tls();
@@ -223,7 +229,7 @@ protected:
std::string makeName();
/// Creates a unique name for a thread.
static int uniqueId();
/// Creates and returns a unique id for a thread.
@@ -244,7 +250,7 @@ protected:
{
_functor();
}
private:
Functor _functor;
};
@@ -282,7 +288,7 @@ inline int Thread::id() const
inline std::string Thread::name() const
{
FastMutex::ScopedLock lock(_mutex);
return _name;
}
@@ -290,7 +296,7 @@ inline std::string Thread::name() const
inline std::string Thread::getName() const
{
FastMutex::ScopedLock lock(_mutex);
return _name;
}
@@ -321,22 +327,22 @@ inline Thread* Thread::current()
inline void Thread::setOSPriority(int prio, int policy)
{
setOSPriorityImpl(prio, policy);
setOSPriorityImpl(prio, policy);
}
inline int Thread::getOSPriority() const
{
return getOSPriorityImpl();
}
inline int Thread::getMinOSPriority(int policy)
{
return ThreadImpl::getMinOSPriorityImpl(policy);
}
inline int Thread::getMaxOSPriority(int policy)
{
return ThreadImpl::getMaxOSPriorityImpl(policy);