aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/poco/Foundation/include/Poco/ThreadTarget.h
blob: 88452694c9af3394da6955d9e109f85e8c32cefb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// 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
//


#ifndef Foundation_ThreadTarget_INCLUDED
#define Foundation_ThreadTarget_INCLUDED


#include "Poco/Foundation.h"
#include "Poco/Runnable.h"


namespace Poco {


class Foundation_API ThreadTarget: public Runnable
	/// This adapter simplifies using static member functions as well as 
	/// 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.
	/// 
	/// Usage:
	///    class MyObject
	///    {
	///        static void doSomething() {}
	///    };
	///    ThreadTarget ra(&MyObject::doSomething);
	///    Thread thr;
	///    thr.start(ra);
	///
	/// or:
	/// 
	///    void doSomething() {}
	/// 
	///    ThreadTarget ra(doSomething);
	///    Thread thr;
	///    thr.start(ra);
{
public:
	typedef void (*Callback)();
	
	ThreadTarget(Callback method);
	
	ThreadTarget(const ThreadTarget& te);

	~ThreadTarget();

	ThreadTarget& operator = (const ThreadTarget& te);

	void run();
	
private:
	ThreadTarget();

	Callback _method;
};


//
// inlines
//
inline void ThreadTarget::run()
{
	_method();
}


} // namespace Poco


#endif // Foundation_ThreadTarget_INCLUDED