QuantumLibrary
quantum_icoro_sync.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_SYNC_H
17 #define BLOOMBERG_QUANTUM_ICORO_SYNC_H
18 
19 #include <memory>
20 #include <atomic>
21 #include <chrono>
22 #include <quantum/quantum_traits.h>
23 
24 namespace Bloomberg {
25 namespace quantum {
26 
27 //==============================================================================================
28 // interface ICoroSync
29 //==============================================================================================
34 struct ICoroSync
35 {
36  using Ptr = std::shared_ptr<ICoroSync>;
37 
39  virtual ~ICoroSync() = default;
40 
43  virtual void setYieldHandle(Traits::Yield& yield) = 0;
44 
48  virtual Traits::Yield& getYieldHandle() = 0;
49 
51  virtual void yield() = 0;
52 
55  virtual std::atomic_int& signal() = 0;
56 
62  virtual void sleep(const std::chrono::milliseconds& timeMs) = 0;
63  virtual void sleep(const std::chrono::microseconds& timeUs) = 0;
64 };
65 
67 
68 }}
69 
70 #endif //BLOOMBERG_QUANTUM_ICORO_SYNC_H
Definition: quantum_buffer_impl.h:22
virtual ~ICoroSync()=default
Default virtual destructor.
virtual Traits::Yield & getYieldHandle()=0
Retrieve the underlying boost::coroutine object.
Provides an interface to facilitate 'implicit' coroutine yielding within other primitives such as mut...
Definition: quantum_icoro_sync.h:34
std::shared_ptr< ICoroSync > Ptr
Definition: quantum_icoro_sync.h:36
ICoroSync::Ptr ICoroSyncPtr
Definition: quantum_icoro_sync.h:66
virtual void yield()=0
Explicitly yields this coroutine context.
virtual void sleep(const std::chrono::milliseconds &timeMs)=0
Sleeps the coroutine associated with this context for at least 'timeMs' milliseconds or 'timeUs' micr...
virtual std::atomic_int & signal()=0
Accessor to the underlying synchronization variable.
virtual void setYieldHandle(Traits::Yield &yield)=0
Sets the underlying boost::coroutine object so that it can be yielded on.
typename BoostCoro::pull_type Yield
Definition: quantum_traits.h:58