OnixS C++ FIX Engine  4.12.0
API Documentation
ThreadSafeQueue.h
Go to the documentation of this file.
1 /*
2 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5 * and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable OnixS Software
8 * Services Agreement (the Agreement) and Customer end user license agreements granting
9 * a non-assignable, non-transferable and non-exclusive license to use the software
10 * for it's own data processing purposes under the terms defined in the Agreement.
11 *
12 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
19 
20 #pragma once
21 
22 #include <OnixS/FIXEngine/ABI.h>
24 
25 namespace OnixS {
26 namespace Threading {
27 
29 {
30  enum Enum
31  {
32  /// No data during the timeout.
34 
35  /// We get data immediately or after waiting during the timeout.
37 
38  // We don't get data but was signaled to stop wait.
40  };
41 };
42 
43 /// The thread-safe queue to send data from some thread(s) to another single thread.
44 /// The thread-safe queue owns enqueued elements and deallocates element's memory on the destruction.
46 {
47 public:
48 
49  /// Initializes the instance.
51 
52  /// Cleans up enqueued elements and internal resources.
53  ~ThreadSafeQueue();
54 
55  /// Adds an item to the queue.
56  /// Takes the ownership of the item from the smart pointer.
57  ///
58  /// @throw The DomainException if the smart pointer is null.
59  ///
60  /// @param enqueueItem The smart pointer to the allocated item to enqueue.
61  void enqueue(ItemBaseUniquePtr & enqueueItem);
62 
63  /// Tries to get an item from the queue during the timeout.
64  /// Gives the ownership of the item to the smart pointer.
65  /// Returns the `ThreadSafeQueueResult` value which reflects the result status ('Timeout', 'Data', 'Signaled').
66  ///
67  /// @param dequeueItem The smart pointer to store the dequeued item.
68  /// @param waitInMs The waiting timeout.
69  ThreadSafeQueueResult::Enum dequeue(ItemBaseUniquePtr & dequeueItem, const int waitInMs = InfiniteTimeout);
70 
71  /// Removes all elements from the queue.
72  void clear();
73 
74  /// Returns 'true' if the queue is empty, otherwise 'false'.
75  bool empty() const;
76 
77  /// Wakes up the queue if it was in the waiting mode.
78  /// The `dequeue` method will return the 'Signaled' status if it was in the waiting mode.
79  void signal();
80 
81 private:
82 
83  /// Implementation details.
84  struct Impl;
85  Impl * impl_;
86 
87  /// The copying and assignment are prohibited.
89  ThreadSafeQueue & operator = (const ThreadSafeQueue &);
90 };
91 
92 }
93 }
PtrTraits< ItemBase >::UniquePtr ItemBaseUniquePtr
Definition: Definitions.h:89
#define ONIXS_FIXENGINE_API
Definition: ABI.h:45
We get data immediately or after waiting during the timeout.
virtual void clear()=0
Clears the storage.
The thread-safe queue to send data from some thread(s) to another single thread.