QuantumLibrary
quantum_icoro_context_base.h
1 /*
2 ** Copyright 2018 Bloomberg Finance L.P.
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 #ifndef BLOOMBERG_QUANTUM_ICORO_CONTEXT_BASE_H
17 #define BLOOMBERG_QUANTUM_ICORO_CONTEXT_BASE_H
18 
19 #include <future>
20 #include <chrono>
21 #include <quantum/interface/quantum_icontext_base.h>
22 #include <quantum/interface/quantum_icoro_sync.h>
23 
24 namespace Bloomberg {
25 namespace quantum {
26 
27 //==============================================================================================
28 // interface ICoroContextBase
29 //==============================================================================================
32 struct ICoroContextBase : public virtual IContextBase,
33  public ICoroSync
34 {
35  using Ptr = std::shared_ptr<ICoroContextBase>;
36 
40  virtual void wait(ICoroSync::Ptr sync) const = 0;
41 
47  virtual std::future_status waitFor(ICoroSync::Ptr sync,
48  std::chrono::milliseconds timeMs) const = 0;
49 
57  virtual void waitAt(int num,
58  ICoroSync::Ptr sync) const = 0;
59 
69  virtual std::future_status waitForAt(int num,
70  ICoroSync::Ptr sync,
71  std::chrono::milliseconds timeMs) const = 0;
72 
76  virtual void waitAll(ICoroSync::Ptr sync) const = 0;
77 };
78 
80 
81 }}
82 
83 #endif //BLOOMBERG_QUANTUM_ICORO_CONTEXT_BASE_H
virtual std::future_status waitFor(ICoroSync::Ptr sync, std::chrono::milliseconds timeMs) const =0
Waits for the future associated with this context to be ready for a maximum of 'timeMs' milliseconds.
Definition: quantum_buffer_impl.h:22
std::shared_ptr< IContextBase > Ptr
Definition: quantum_icontext_base.h:35
virtual void wait(ICoroSync::Ptr sync) const =0
Waits for the future associated with this context to be ready.
Provides an interface to facilitate 'implicit' coroutine yielding within other primitives such as mut...
Definition: quantum_icoro_sync.h:34
virtual void waitAll(ICoroSync::Ptr sync) const =0
Wait for all the futures in the continuation chain to be ready.
std::shared_ptr< ICoroSync > Ptr
Definition: quantum_icoro_sync.h:36
ICoroContextBase::Ptr ICoroContextBasePtr
Definition: quantum_icoro_context_base.h:79
virtual void waitAt(int num, ICoroSync::Ptr sync) const =0
Waits for the future in the 'num-th' continuation context to be ready.
This interface exposes shared functionality between IThreadContext and ICoroContext.
Definition: quantum_icontext_base.h:33
std::shared_ptr< ICoroContextBase > Ptr
Definition: quantum_icoro_context_base.h:35
virtual std::future_status waitForAt(int num, ICoroSync::Ptr sync, std::chrono::milliseconds timeMs) const =0
Waits for the future in the 'num-th' continuation context to be ready for a maximum of 'timeMs' milli...
Exposes methods to manipulate the coroutine context, especially future wait methods.
Definition: quantum_icoro_context_base.h:32