Event.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_EVENT_H
23#define FIX_EVENT_H
24
25#include "Utility.h"
26#include <math.h>
27
28#ifndef _MSC_VER
29#include <pthread.h>
30#include <cmath>
31#endif
32
33namespace FIX
34{
36class Event
37{
38public:
40 {
41#ifdef _MSC_VER
42 m_event = CreateEvent( 0, false, false, 0 );
43#else
44 pthread_mutex_init( &m_mutex, 0 );
45 pthread_cond_init( &m_event, 0 );
46#endif
47 }
48
50 {
51#ifdef _MSC_VER
52 CloseHandle( m_event );
53#else
54 pthread_cond_destroy( &m_event );
55 pthread_mutex_destroy( &m_mutex );
56#endif
57 }
58
59 void signal()
60 {
61#ifdef _MSC_VER
62 SetEvent( m_event );
63#else
64 pthread_mutex_lock( &m_mutex );
65 pthread_cond_broadcast( &m_event );
66 pthread_mutex_unlock( &m_mutex );
67#endif
68 }
69
70 void wait( double s )
71 {
72#ifdef _MSC_VER
73 WaitForSingleObject( m_event, (long)(s * 1000) );
74#else
75 pthread_mutex_lock( &m_mutex );
76 timespec time, remainder;
77 double intpart;
78 time.tv_nsec = (long)(modf(s, &intpart) * 1e9);
79 time.tv_sec = (int)intpart;
80 pthread_cond_timedwait( &m_event, &m_mutex, &time );
81 pthread_mutex_unlock( &m_mutex );
82#endif
83 }
84
85private:
86#ifdef _MSC_VER
87 HANDLE m_event;
88#else
89 pthread_cond_t m_event;
90 pthread_mutex_t m_mutex;
91#endif
92};
93}
94
95#endif
Portable implementation of an event/conditional mutex.
Definition Event.h:37
pthread_cond_t m_event
Definition Event.h:89
void wait(double s)
Definition Event.h:70
pthread_mutex_t m_mutex
Definition Event.h:90
Event()
Definition Event.h:39
~Event()
Definition Event.h:49
void signal()
Definition Event.h:59

Generated on Thu Feb 29 2024 22:38:19 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001