QuantumLibrary
quantum_iqueue.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_IQUEUE_H
17 #define BLOOMBERG_QUANTUM_IQUEUE_H
18 
19 #include <quantum/quantum_spinlock.h>
20 #include <quantum/interface/quantum_iterminate.h>
21 #include <quantum/interface/quantum_itask.h>
22 #include <quantum/interface/quantum_iqueue_statistics.h>
23 #include <quantum/quantum_allocator.h>
24 
25 namespace Bloomberg {
26 namespace quantum {
27 
28 //==============================================================================================
29 // interface IQueue
30 //==============================================================================================
33 struct IQueue : public ITerminate
34 {
35  //Typedefs and enum definitions
36  using Ptr = std::shared_ptr<IQueue>;
37  enum class QueueType : int { Coro, IO, All };
38  enum class QueueId : int { Any = -1, Same = -2, All = -3 };
39 
40  //Interface methods
41  virtual void pinToCore(int coreId) = 0;
42 
43  virtual void run() = 0;
44 
45  virtual void enqueue(ITask::Ptr task) = 0;
46 
47  virtual bool tryEnqueue(ITask::Ptr task) = 0;
48 
49  virtual ITask::Ptr dequeue(std::atomic_bool& hint) = 0;
50 
51  virtual ITask::Ptr tryDequeue(std::atomic_bool& hint) = 0;
52 
53  virtual size_t size() const = 0;
54 
55  virtual bool empty() const = 0;
56 
57  virtual IQueueStatistics& stats() = 0;
58 
59  virtual SpinLock& getLock() = 0;
60 
61  virtual void signalEmptyCondition(bool value) = 0;
62 
63  virtual bool isIdle() const = 0;
64 };
65 
67 
68 #ifndef __QUANTUM_QUEUE_LIST_ALLOC_SIZE
69  #define __QUANTUM_QUEUE_LIST_ALLOC_SIZE __QUANTUM_DEFAULT_POOL_ALLOC_SIZE
70 #endif
71 #ifndef __QUANTUM_USE_DEFAULT_ALLOCATOR
72  #ifdef __QUANTUM_ALLOCATE_POOL_FROM_HEAP
74  #else
76  #endif
77 #else
79 #endif
80 
81 }}
82 
83 #endif //BLOOMBERG_QUANTUM_IQUEUE_H
virtual void signalEmptyCondition(bool value)=0
QueueType
Definition: quantum_iqueue.h:37
Definition: quantum_buffer_impl.h:22
virtual ITask::Ptr tryDequeue(std::atomic_bool &hint)=0
virtual bool tryEnqueue(ITask::Ptr task)=0
Definition: quantum_allocator.h:36
std::shared_ptr< ITask > Ptr
Definition: quantum_itask.h:34
Provides a stack-based object pool to the underlying ContiguousPoolManager. The default buffer size i...
Definition: quantum_stack_allocator.h:34
Interface to a task queue. For internal use only.
Definition: quantum_iqueue.h:33
virtual IQueueStatistics & stats()=0
virtual bool isIdle() const =0
virtual void pinToCore(int coreId)=0
virtual size_t size() const =0
std::shared_ptr< IQueue > Ptr
Definition: quantum_iqueue.h:36
virtual SpinLock & getLock()=0
Provides a heap-based object pool to the underlying ContiguousPoolManager. The default buffer size is...
Definition: quantum_heap_allocator.h:33
virtual ITask::Ptr dequeue(std::atomic_bool &hint)=0
IQueue::Ptr IQueuePtr
Definition: quantum_iqueue.h:66
Interface to access and manipulate a QueueStatistics object.
Definition: quantum_iqueue_statistics.h:29
virtual void enqueue(ITask::Ptr task)=0
QueueId
Definition: quantum_iqueue.h:38
virtual bool empty() const =0