Queue.h
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 
3 /****************************************************************************
4 ** Copyright (c) 2001-2014
5 **
6 ** This file is part of the QuickFIX FIX Engine
7 **
8 ** This file may be distributed under the terms of the quickfixengine.org
9 ** license as defined by quickfixengine.org and appearing in the file
10 ** LICENSE included in the packaging of this file.
11 **
12 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14 **
15 ** See http://www.quickfixengine.org/LICENSE for licensing information.
16 **
17 ** Contact ask@quickfixengine.org if any conditions of this licensing are
18 ** not clear to you.
19 **
20 ****************************************************************************/
21 
22 #ifndef FIX_QUEUE_H
23 #define FIX_QUEUE_H
24 
25 #include "Utility.h"
26 #include "Event.h"
27 #include "Mutex.h"
28 #include <queue>
29 
30 namespace FIX
31 {
33 template < typename T > class Queue
34 {
35 public:
36  void push( const T& value )
37  {
38  Locker locker( m_mutex );
39  m_queue.push( value );
40  signal();
41  }
42 
43  bool pop( T& value )
44  {
45  Locker locker( m_mutex );
46  if ( !m_queue.size() ) return false;
47  value = m_queue.front();
48  m_queue.pop();
49  return true;
50  }
51 
52  int size()
53  {
54  Locker locker( m_mutex );
55  return m_queue.size();
56  }
57 
58  void wait( double s )
59  {
60  m_event.wait( s );
61  }
62 
63  void signal()
64  {
65  m_event.signal();
66  }
67 
68 private:
69  Event m_event;
71  std::queue < T > m_queue;
72 };
73 }
74 
75 #endif
FIX::Queue::m_mutex
Mutex m_mutex
Definition: Queue.h:104
FIX::Queue::m_queue
std::queue< T > m_queue
Definition: Queue.h:105
FIX::Event::signal
void signal()
Definition: Event.h:93
FIX::Mutex
Portable implementation of a mutex.
Definition: Mutex.h:47
FIX::Queue::push
void push(const T &value)
Definition: Queue.h:70
FIX::Queue::wait
void wait(double s)
Definition: Queue.h:92
Mutex.h
FIX::Queue::pop
bool pop(T &value)
Definition: Queue.h:77
FIX::Queue::signal
void signal()
Definition: Queue.h:97
FIX
Definition: Acceptor.cpp:34
Event.h
FIX::Locker
Locks/Unlocks a mutex using RAII.
Definition: Mutex.h:112
FIX::Queue::m_event
Event m_event
Definition: Queue.h:103
FIX::Queue::size
int size()
Definition: Queue.h:86
FIX::Event::wait
void wait(double s)
Definition: Event.h:104
Utility.h

Generated on Wed Apr 29 2020 19:41:30 for QuickFIX by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2001