OnixS C++ Eurex T7 Market and Reference Data Interface (EMDI, RDI, EOBI) Handlers  8.1.0
API documentation
Semaphore.cpp
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 #include <OnixS/Core/Bootstrap/Platform.h>
20 
21 #include <OnixS/Core/Concurrency/Semaphore.h>
22 
24 
25 
26 namespace OnixS {
27 namespace Eurex {
28 namespace MarketData {
29 
30 
32 {
33 public:
34  Impl(int initialCounter) :
35  sem_(initialCounter)
36  {
37  }
38 
40  {
41  }
42 
43  bool acquire(int timeoutInMs)
44  {
45  if (timeoutInMs == -1)
46  {
47  sem_.acquire();
48  return true;
49  }
50  else
51  {
52  const OnixS::Time::TotalSeconds seconds = timeoutInMs / 1000;
53  const OnixS::Time::Nanoseconds nanoseconds = (timeoutInMs % 1000) * 1000000;
54  const OnixS::Time::TimeSpan timeout(seconds, OnixS::Time::NanosecondSubseconds(nanoseconds));
55  return sem_.acquire(timeout);
56  }
57  }
58 
59  void release()
60  {
61  sem_.release();
62  }
63 
64 private:
65  OnixS::Concurrency::Semaphore sem_;
66 };
67 
68 Semaphore::Semaphore(int initialCounter) :
69  impl_(new Impl(initialCounter))
70 {
71 }
72 
74 {
75  delete impl_;
76 }
77 
78 bool Semaphore::acquire(int timeoutInMs)
79 {
80  return impl_->acquire(timeoutInMs);
81 }
82 
84 {
85  impl_->release();
86 }
87 
88 }}}
89 
Definition: Defines.h:30
bool acquire(int timeoutInMs=-1)
Definition: Semaphore.cpp:78
Semaphore(int initialCounter=0)
Definition: Semaphore.cpp:68