2
* Copyright (c) 2005, Eric Crahen
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:
11
* The above copyright notice and this permission notice shall be included in all
12
* copies or substantial portions of the Software.
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.
23
#ifndef __ZTCONCURRENTEXECUTOR_H__
24
#define __ZTCONCURRENTEXECUTOR_H__
26
#include "zthread/PoolExecutor.h"
31
* @class ConcurrentExecutor
33
* @author Eric Crahen <http://www.code-foo.com>
34
* @date <2003-07-16T22:36:11-0400>
37
* A ConcurrentExecutor spawns a single thread to service a series of Tasks.
41
class ConcurrentExecutor : public Executor {
43
PoolExecutor _executor;
47
//! Create a ConcurrentExecutor
51
* Interrupting a ConcurrentExecutor will cause the thread running the tasks to be
52
* be interrupted once during the execution of each task that has been submitted
53
* at the time this function is called.
55
* Tasks that are submitted after this function is called will
56
* not be interrupt()ed; unless this function is invoked again().
62
* ConcurrentExecutor executor;
65
* for(size_t n = 0; n < p; n++)
66
* executor.execute(new aRunnable);
68
* // Tasks [m, p) may be interrupted, where m is the first task that has
69
* // not completed at the time the interrupt() is invoked.
70
* executor.interrupt();
72
* // Submit (q - p) Tasks
73
* for(size_t n = p; n < q; n++)
74
* executor.execute(new Chore);
76
* // Tasks [p, q) are not interrupted
82
virtual void interrupt();
85
* Submit a Task to this Executor. This will not block the current thread
86
* for very long. The task will be enqueued internally and eventually run
87
* in the context of the single thread driving all the Tasks submitted to this
90
* @exception Cancellation_Exception thrown if this Executor has been canceled.
91
* The Task being submitted will not be executed by this Executor.
93
* @exception Synchronization_Exception thrown only in the event of an error
94
* in the implementation of the library.
96
* @see Executor::execute(const Task&)
98
virtual void execute(const Task&);
101
* @see Cancelable::cancel()
103
virtual void cancel();
106
* @see Cancelable::isCanceled()
108
virtual bool isCanceled();
111
* @see PoolExecutor::wait()
116
* @see PoolExecutor::wait(unsigned long timeout)
118
virtual bool wait(unsigned long timeout);
120
}; /* ConcurrentExecutor */
122
} // namespace ZThread
124
#endif // __ZTCONCURRENTEXECUTOR_H__