replicode
reduction_job.h
Go to the documentation of this file.
1 // reduction_job.h
2 //
3 // Author: Eric Nivel
4 //
5 // BSD license:
6 // Copyright (c) 2010, Eric Nivel
7 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are met:
10 //
11 // - Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // - Redistributions in binary form must reproduce the above copyright
14 // notice, this list of conditions and the following disclaimer in the
15 // documentation and/or other materials provided with the distribution.
16 // - Neither the name of Eric Nivel nor the
17 // names of their contributors may be used to endorse or promote products
18 // derived from this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
24 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef reduction_job_h
32 #define reduction_job_h
33 
34 #include "overlay.h"
35 #include "object.h"
36 
37 
38 namespace r_exec {
39 
41  public _Object {
42 protected:
43  _ReductionJob();
44 public:
45  uint64_t ijt; // time of injection of the job in the pipe.
46  virtual bool update(uint64_t now) = 0; // return false to shutdown the reduction core.
47  virtual void debug() {}
48 };
49 
50 template<class _P> class ReductionJob:
51  public _ReductionJob {
52 public:
55  ReductionJob(View *input, _P *processor): _ReductionJob(), input(input), processor(processor) {}
56  bool update(uint64_t now);
57  void debug() {
58 
59  processor->debug(input);
60  }
61 };
62 
63 template<class _P, class T, class C> class BatchReductionJob:
64  public _ReductionJob {
65 public:
66  P<_P> processor; // the controller that will process the job.
67  P<T> trigger; // the event that triggered the job.
68  P<C> controller; // the controller that produced the job.
69  BatchReductionJob(_P *processor, T *trigger, C *controller): _ReductionJob(), processor(processor), trigger(trigger), controller(controller) {}
70  bool update(uint64_t now);
71 };
72 
74  public _ReductionJob {
75 public:
76  bool update(uint64_t now);
77 };
78 
80  public _ReductionJob {
81 public:
83  AsyncInjectionJob(View *input): _ReductionJob(), input(input) {}
84  bool update(uint64_t now);
85 };
86 }
87 
88 #endif
P< T > trigger
Definition: reduction_job.h:67
Definition: base.h:75
P< View > input
Definition: reduction_job.h:82
bool now(const Context &context, uint16_t &index)
Definition: operator.cpp:55
P< C > controller
Definition: reduction_job.h:68
uint64_t ijt
Definition: reduction_job.h:45
#define dll_export
Definition: dll.h:44
bool update(uint64_t now)
Definition: reduction_job.cpp:45
virtual void debug()
Definition: reduction_job.h:47
Definition: _context.cpp:34
friend class _P
Definition: base.h:77
P< View > input
Definition: reduction_job.h:53
Definition: base.h:47
void debug()
Definition: reduction_job.h:57
Definition: view.h:47
ReductionJob(View *input, _P *processor)
Definition: reduction_job.h:55
AsyncInjectionJob(View *input)
Definition: reduction_job.h:83
P< _P > processor
Definition: reduction_job.h:54
Definition: reduction_job.h:40
Definition: reduction_job.h:50
Definition: reduction_job.h:73
Definition: reduction_job.h:63
BatchReductionJob(_P *processor, T *trigger, C *controller)
Definition: reduction_job.h:69
bool update(uint64_t now)
Definition: reduction_job.cpp:40
P< _P > processor
Definition: reduction_job.h:66
Definition: reduction_job.h:79