OnixS C++ FIX Engine  4.2.0
API Documentation
Definitions.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 #if defined (_WIN32) // Windows platform.
23 
24 #if !defined (STRICT)
25 #define STRICT
26 #endif
27 
28 #if !defined (WIN32_LEAN_AND_MEAN)
29 #define WIN32_LEAN_AND_MEAN
30 #endif
31 
32 #include <Windows.h>
33 
34 #else // Linux platform.
35 
36 #include <pthread.h>
37 
38 #endif // Platform Selector.
39 
40 #include <OnixS/FIXEngine/ABI.h>
42 
43 namespace OnixS {
44 namespace Threading {
45 #if defined (_WIN32)
46 /// Type alias for thread identifier.
47 typedef DWORD ThreadId;
48 #else
49 /// Type alias for thread identifier.
50 typedef pthread_t ThreadId;
51 #endif
52 
53 /// The infinite timeout value.
54 enum { InfiniteTimeout = -1 };
55 
56 /// The base class for custom items which can be stored in thread-safe containers.
58 {
59 public:
60 
61  /// Initializes the instance.
62  ItemBase() : next_() {}
63 
64  /// Destructs the instance.
65  virtual ~ItemBase() {}
66 
67  /// Returns the next item.
68  ItemBase * next() const
69  {
70  return next_;
71  }
72 
73  /// Sets the next item.
74  void setNext(ItemBase * nextNode)
75  {
76  next_ = nextNode;
77  }
78 
79  /// Performs a required processing of the item.
80  virtual void process() = 0;
81 
82 private:
83 
84  // The pointer to the next item.
85  ItemBase * volatile next_;
86 };
87 
89 
90 /// The base class for a custom pool allocator to provide
91 /// a strategy to create/destroy items for the thread-safe pool.
93 {
94 public:
95 
96  /// Destructs the instance.
97  virtual ~PoolAllocatorBase() {}
98 
99  /// A strategy to create an item.
100  virtual ItemBase * alloc() = 0;
101 
102  /// A strategy to destroy an item.
103  virtual void free(ItemBase * element) const
104  {
105  delete element;
106  }
107 };
108 
109 }
110 }
virtual ~ItemBase()
Destructs the instance.
Definition: Definitions.h:65
virtual ~PoolAllocatorBase()
Destructs the instance.
Definition: Definitions.h:97
void setNext(ItemBase *nextNode)
Sets the next item.
Definition: Definitions.h:74
PtrTraits< ItemBase >::UniquePtr ItemBaseUniquePtr
Definition: Definitions.h:88
pthread_t ThreadId
Type alias for thread identifier.
Definition: Definitions.h:50
ItemBase * next() const
Returns the next item.
Definition: Definitions.h:68
#define ONIXS_FIXENGINE_API
Definition: ABI.h:45
std::auto_ptr< T > UniquePtr
Definition: Definitions.h:32
ItemBase()
Initializes the instance.
Definition: Definitions.h:62
The base class for a custom pool allocator to provide a strategy to create/destroy items for the thre...
Definition: Definitions.h:92
The base class for custom items which can be stored in thread-safe containers.
Definition: Definitions.h:57
virtual void free(ItemBase *element) const
A strategy to destroy an item.
Definition: Definitions.h:103