~ubuntu-branches/ubuntu/trusty/hugin/trusty-proposed

« back to all changes in this revision

Viewing changes to src/foreign/zthread/include/zthread/ConcurrentExecutor.h

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2011-01-06 14:28:24 UTC
  • mfrom: (1.1.9 upstream) (0.1.21 experimental)
  • Revision ID: james.westby@ubuntu.com-20110106142824-zn9lxylg5z44dynn
* Drop Cyril Brulebois from Uploaders. Thank you very much for your work.
* Bump package version. (rc3 was re-released as 2010.4.0).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 __ZTCONCURRENTEXECUTOR_H__
 
24
#define __ZTCONCURRENTEXECUTOR_H__
 
25
 
 
26
#include "zthread/PoolExecutor.h"
 
27
 
 
28
namespace ZThread {
 
29
 
 
30
  /**
 
31
   * @class ConcurrentExecutor
 
32
   *
 
33
   * @author Eric Crahen <http://www.code-foo.com>
 
34
   * @date <2003-07-16T22:36:11-0400>
 
35
   * @version 2.3.0
 
36
   *
 
37
   * A ConcurrentExecutor spawns a single thread to service a series of Tasks.
 
38
   * 
 
39
   * @see PoolExecutor.
 
40
   */
 
41
  class ConcurrentExecutor : public Executor {
 
42
 
 
43
    PoolExecutor _executor;
 
44
 
 
45
  public:
 
46
    
 
47
    //! Create a ConcurrentExecutor
 
48
    ConcurrentExecutor(); 
 
49
 
 
50
    /**
 
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.
 
54
     *  
 
55
     * Tasks that are submitted after this function is called will 
 
56
     * not be interrupt()ed; unless this function is invoked again().
 
57
     *
 
58
     * @code
 
59
     * 
 
60
     * void aFunction() {
 
61
     *
 
62
     *   ConcurrentExecutor executor;
 
63
     *
 
64
     *   // Submit p Tasks
 
65
     *   for(size_t n = 0; n < p; n++)
 
66
     *     executor.execute(new aRunnable);
 
67
     *
 
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();
 
71
     *
 
72
     *   // Submit (q - p) Tasks
 
73
     *   for(size_t n = p; n < q; n++)
 
74
     *     executor.execute(new Chore);
 
75
     * 
 
76
     *   // Tasks [p, q) are not interrupted 
 
77
     *
 
78
     * }
 
79
     *
 
80
     * @endcode
 
81
     */
 
82
    virtual void interrupt();
 
83
    
 
84
    /**
 
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 
 
88
     * Executor.
 
89
     * 
 
90
     * @exception Cancellation_Exception thrown if this Executor has been canceled.
 
91
     * The Task being submitted will not be executed by this Executor.
 
92
     *
 
93
     * @exception Synchronization_Exception thrown only in the event of an error 
 
94
     * in the implementation of the library.
 
95
     *
 
96
     * @see Executor::execute(const Task&)
 
97
     */
 
98
    virtual void execute(const Task&);
 
99
    
 
100
    /**
 
101
     * @see Cancelable::cancel()
 
102
     */
 
103
    virtual void cancel();
 
104
    
 
105
    /**
 
106
     * @see Cancelable::isCanceled()
 
107
     */
 
108
    virtual bool isCanceled();
 
109
    
 
110
    /**
 
111
     * @see PoolExecutor::wait()
 
112
     */
 
113
    virtual void wait();
 
114
    
 
115
    /**
 
116
     * @see PoolExecutor::wait(unsigned long timeout)
 
117
     */
 
118
    virtual bool wait(unsigned long timeout);
 
119
    
 
120
  }; /* ConcurrentExecutor */
 
121
  
 
122
} // namespace ZThread
 
123
 
 
124
#endif // __ZTCONCURRENTEXECUTOR_H__