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
30namespace FIX
31{
33template < typename T > class Queue
34{
35public:
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 {
66 }
67
68private:
71 std::queue < T > m_queue;
72};
73}
74
75#endif
Portable implementation of an event/conditional mutex.
Definition Event.h:37
void wait(double s)
Definition Event.h:70
void signal()
Definition Event.h:59
Locks/Unlocks a mutex using RAII.
Definition Mutex.h:96
Portable implementation of a mutex.
Definition Mutex.h:31
A thread safe monitored queue.
Definition Queue.h:34
std::queue< T > m_queue
Definition Queue.h:71
void signal()
Definition Queue.h:63
bool pop(T &value)
Definition Queue.h:43
void push(const T &value)
Definition Queue.h:36
int size()
Definition Queue.h:52
Mutex m_mutex
Definition Queue.h:70
void wait(double s)
Definition Queue.h:58
Event m_event
Definition Queue.h:69

Generated on Thu May 22 2025 08:23:50 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001