poco/Foundation/include/Poco/ThreadTarget.h

88 lines
1.6 KiB
C
Raw Normal View History

2012-04-29 20:52:25 +02:00
//
// ThreadTarget.h
//
// Library: Foundation
// Package: Threading
// Module: ThreadTarget
//
// Definition of the ThreadTarget class.
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
2012-04-29 20:52:25 +02:00
//
#ifndef Foundation_ThreadTarget_INCLUDED
#define Foundation_ThreadTarget_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/Runnable.h"
namespace Poco {
class Foundation_API ThreadTarget: public Runnable
2022-07-07 11:18:20 +02:00
/// This adapter simplifies using static member functions as well as
2012-04-29 20:52:25 +02:00
/// standalone functions as targets for threads.
/// Note that it is possible to pass those entities directly to Thread::start().
/// This adapter is provided as a convenience for higher abstraction level
/// scenarios where Runnable abstract class is used.
///
/// For using a non-static member function as a thread target, please
/// see the RunnableAdapter class.
2022-07-07 11:18:20 +02:00
///
2012-04-29 20:52:25 +02:00
/// Usage:
/// class MyObject
/// {
/// static void doSomething() {}
/// };
/// ThreadTarget ra(&MyObject::doSomething);
/// Thread thr;
/// thr.start(ra);
///
/// or:
2022-07-07 11:18:20 +02:00
///
2012-04-29 20:52:25 +02:00
/// void doSomething() {}
2022-07-07 11:18:20 +02:00
///
2012-04-29 20:52:25 +02:00
/// ThreadTarget ra(doSomething);
/// Thread thr;
/// thr.start(ra);
{
public:
typedef void (*Callback)();
2022-07-07 11:18:20 +02:00
2012-04-29 20:52:25 +02:00
ThreadTarget(Callback method);
2022-07-07 11:18:20 +02:00
2012-04-29 20:52:25 +02:00
ThreadTarget(const ThreadTarget& te);
~ThreadTarget();
ThreadTarget& operator = (const ThreadTarget& te);
void run();
2022-07-07 11:18:20 +02:00
2012-04-29 20:52:25 +02:00
private:
ThreadTarget();
Callback _method;
};
//
// inlines
//
inline void ThreadTarget::run()
{
_method();
}
} // namespace Poco
#endif // Foundation_ThreadTarget_INCLUDED