1 | /* |
---|
2 | * Copyright (c) 2005, Eric Crahen |
---|
3 | * |
---|
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
5 | * of this software and associated documentation files (the "Software"), to deal |
---|
6 | * in the Software without restriction, including without limitation the rights |
---|
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
8 | * copies of the Software, and to permit persons to whom the Software is furnished |
---|
9 | * to do so, subject to the following conditions: |
---|
10 | * |
---|
11 | * The above copyright notice and this permission notice shall be included in all |
---|
12 | * copies or substantial portions of the Software. |
---|
13 | * |
---|
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
---|
18 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
---|
19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
---|
20 | * |
---|
21 | */ |
---|
22 | |
---|
23 | #ifndef __ZTEXECUTOR_H__ |
---|
24 | #define __ZTEXECUTOR_H__ |
---|
25 | |
---|
26 | #include "zthread/Thread.h" |
---|
27 | #include "zthread/Waitable.h" |
---|
28 | |
---|
29 | namespace ZThread { |
---|
30 | |
---|
31 | |
---|
32 | /** |
---|
33 | * @class Executor |
---|
34 | * |
---|
35 | * @author Eric Crahen <http://www.code-foo.com> |
---|
36 | * @date <2003-07-16T22:39:39-0400> |
---|
37 | * @version 2.3.0 |
---|
38 | * |
---|
39 | * Execeutors are an implementation of the Executor pattern. This is |
---|
40 | * a more versatile construct than a thread pool. A paper describing can |
---|
41 | * be found in the proceedings of the 2002 VikingPLOP conference. |
---|
42 | * |
---|
43 | * <b>Executing</b> |
---|
44 | * |
---|
45 | * - <em>execute</em>()ing task with an Executor will submit the task, scheduling |
---|
46 | * it for execution at some future time depending on the Executor being used. |
---|
47 | * |
---|
48 | * <b>Disabling</b> |
---|
49 | * |
---|
50 | * - <em>cancel</em>()ing an Executor will cause it to stop accepting |
---|
51 | * new tasks. |
---|
52 | * |
---|
53 | * <b>Interrupting</b> |
---|
54 | * |
---|
55 | * - <em>interrupt</em>()ing an Executor will cause the any thread running |
---|
56 | * a task which was submitted prior to the invocation of this function to |
---|
57 | * be interrupted during the execution of that task. |
---|
58 | * |
---|
59 | * <b>Waiting</b> |
---|
60 | * |
---|
61 | * - <em>wait</em>()ing on a PoolExecutor will block the calling thread |
---|
62 | * until all tasks that were submitted prior to the invocation of this function |
---|
63 | * have completed. |
---|
64 | * |
---|
65 | * @see Cancelable |
---|
66 | * @see Waitable |
---|
67 | */ |
---|
68 | class Executor : public Cancelable, public Waitable, private NonCopyable { |
---|
69 | public: |
---|
70 | |
---|
71 | /** |
---|
72 | * If supported by the Executor, interrupt all tasks submitted prior to |
---|
73 | * the invocation of this function. |
---|
74 | */ |
---|
75 | virtual void interrupt() = 0; |
---|
76 | |
---|
77 | /** |
---|
78 | * Submit a task to this Executor. |
---|
79 | * |
---|
80 | * @param task Task to be run by a thread managed by this executor |
---|
81 | * |
---|
82 | * @pre The Executor should have been canceled prior to this invocation. |
---|
83 | * @post The submitted task will be run at some point in the future by this Executor. |
---|
84 | * |
---|
85 | * @exception Cancellation_Exception thrown if the Executor was canceled prior to |
---|
86 | * the invocation of this function. |
---|
87 | */ |
---|
88 | virtual void execute(const Task& task) = 0; |
---|
89 | |
---|
90 | }; |
---|
91 | |
---|
92 | } // namespace ZThread |
---|
93 | |
---|
94 | #endif // __ZTEXECUTOR_H__ |
---|