Skip to content

Commit 5adbc25

Browse files
committed
Merge branch 'develop'
2 parents ed7719b + e84f8d9 commit 5adbc25

File tree

336 files changed

+8230
-38301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

336 files changed

+8230
-38301
lines changed

autowiring/AutoPacket.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include EXCEPTION_PTR_HEADER
2323

2424
class AutoPacket;
25+
class AutoPacketInternal;
2526
class AutoPacketFactory;
2627
class AutoPacketProfiler;
2728
struct AutoFilterDescriptor;
@@ -47,6 +48,7 @@ class AutoPacket:
4748
AutoPacket(AutoPacket&&) = delete;
4849

4950
public:
51+
// Must hold the lock to 'factory' when calling this constructor
5052
AutoPacket(AutoPacketFactory& factory, std::shared_ptr<void>&& outstanding);
5153
~AutoPacket();
5254

@@ -58,9 +60,12 @@ class AutoPacket:
5860
protected:
5961
// A pointer back to the factory that created us. Used for recording lifetime statistics.
6062
const std::shared_ptr<AutoPacketFactory> m_parentFactory;
63+
64+
// The successor to this packet
65+
std::shared_ptr<AutoPacketInternal> m_successor;
6166

6267
// Hold the time point at which this packet was last initalized.
63-
const std::chrono::high_resolution_clock::time_point m_initTime;
68+
std::chrono::high_resolution_clock::time_point m_initTime;
6469

6570
// Outstanding count local and remote holds:
6671
const std::shared_ptr<void> m_outstanding;
@@ -507,6 +512,12 @@ class AutoPacket:
507512
return GetSubscribers(typeid(auto_id<T>));
508513
}
509514

515+
/// <returns>All decoration dispositions</returns>
516+
/// <remarks>
517+
/// This method is useful for getting a picture of the entire disposition graph
518+
/// </remarks>
519+
std::list<DecorationDisposition> GetDispositions() const;
520+
510521
/// <returns>All decoration dispositions associated with the data type</returns>
511522
/// <remarks>
512523
/// This method is useful for determining whether flow conditions (broadcast, pipes
@@ -517,6 +528,12 @@ class AutoPacket:
517528
return GetDispositions(typeid(auto_id<T>));
518529
}
519530

531+
/// <summary>
532+
/// Returns the next packet that will be issued by the packet factory in this context relative to this context
533+
/// </summary>
534+
std::shared_ptr<AutoPacketInternal> SuccessorInternal(void);
535+
std::shared_ptr<AutoPacket> Successor(void);
536+
520537
/// <returns>True if the indicated type has been requested for use by some consumer</returns>
521538
template<class T>
522539
bool HasSubscribers(void) const {

autowiring/AutoPacketFactory.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct AdjacencyEntry;
1616
class AutoPacketFactory;
1717
class Deferred;
1818
class DispatchQueue;
19+
class AutoPacketInternal;
1920

2021
/// <summary>
2122
/// A configurable factory class for pipeline packets with a built-in object pool
@@ -40,15 +41,12 @@ class AutoPacketFactory:
4041

4142
// State change notification
4243
std::condition_variable m_stateCondition;
43-
44-
// Have we been signaled to stop
45-
bool m_wasStopped;
46-
47-
// Outstanding reference if this factory is currently running:
48-
std::shared_ptr<Object> m_outstanding;
4944

5045
// Internal outstanding reference for issued packet:
5146
std::weak_ptr<void> m_outstandingInternal;
47+
48+
// The last packet issued from this factory
49+
std::shared_ptr<AutoPacketInternal> m_nextPacket;
5250

5351
// Collection of known subscribers
5452
typedef std::unordered_set<AutoFilterDescriptor, std::hash<AutoFilterDescriptor>> t_autoFilterSet;
@@ -79,11 +77,9 @@ class AutoPacketFactory:
7977
}
8078

8179
// CoreRunnable overrides:
82-
bool Start(std::shared_ptr<Object> outstanding) override;
83-
void Stop(bool graceful = false) override;
84-
void Wait(void) override;
85-
bool IsRunning(void) const override { return m_outstanding && !m_wasStopped; };
86-
bool ShouldStop(void) const override { return m_wasStopped; };
80+
bool OnStart(void) override;
81+
void OnStop(bool graceful) override;
82+
void DoAdditionalWait(void) override;
8783

8884
/// <summary>
8985
/// Causes this AutoPacketFactory to release all of its packet subscribers
@@ -134,8 +130,10 @@ class AutoPacketFactory:
134130
/// </summary>
135131
std::shared_ptr<AutoPacket> NewPacket(void);
136132

133+
std::shared_ptr<AutoPacketInternal> ConstructPacket(void);
134+
137135
/// <returns>the number of outstanding AutoPackets</returns>
138-
size_t GetOutstanding(void) const;
136+
size_t GetOutstandingPacketCount(void) const;
139137

140138
/// <summary>
141139
/// Called by each AutoPacket's Finalize method to allow the factory

autowiring/AutoPacketGraph.h

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
2+
#pragma once
3+
#include "AutoFilterDescriptor.h"
4+
#include "AutoPacket.h"
5+
#include "AutoPacketFactory.h"
6+
#include "Autowired.h"
7+
#include "AutowiringEvents.h"
8+
#include "CoreRunnable.h"
9+
#include STL_UNORDERED_MAP
10+
11+
12+
/// <summary>
13+
/// Represents an edge in the graph from a type to an AutoFilter
14+
/// </summary>
15+
struct DeliveryEdge
16+
{
17+
// The type info
18+
const std::type_info* type_info;
19+
20+
// The AutoFilterDescriptor
21+
AutoFilterDescriptor descriptor;
22+
23+
// Specifies if the argument is an input (type -> descriptor) or output (descriptor -> type)
24+
bool input;
25+
26+
// For the unordered map/hash comparison
27+
bool operator==(const DeliveryEdge& rhs) const {
28+
return
29+
type_info == rhs.type_info &&
30+
descriptor == rhs.descriptor &&
31+
input == rhs.input;
32+
}
33+
};
34+
35+
/// <summary>
36+
/// Using the same hash function as the AutoFilterDescriptor
37+
/// </summary>
38+
namespace std {
39+
template<>
40+
struct hash<DeliveryEdge>
41+
{
42+
size_t operator()(const DeliveryEdge& edge) const {
43+
return (size_t) edge.descriptor.GetAutoFilter()->ptr();
44+
}
45+
};
46+
}
47+
48+
/// <summary>
49+
/// Graphical visualization of AutoPackets
50+
/// </summary>
51+
class AutoPacketGraph:
52+
public AutowiringEvents,
53+
public CoreRunnable
54+
{
55+
public:
56+
AutoPacketGraph();
57+
58+
typedef std::unordered_map<DeliveryEdge, size_t, std::hash<DeliveryEdge>> t_deliveryEdges;
59+
60+
protected:
61+
// A mapping of an edge to the number of times it was delivered
62+
t_deliveryEdges m_deliveryGraph;
63+
64+
// A lock for this type
65+
mutable std::mutex m_lock;
66+
67+
// Reference to the AutoPacketFactory
68+
AutoRequired<AutoPacketFactory> m_factory;
69+
70+
/// <summary>
71+
/// Demangle a type name as well as stripping "auto_in< >"
72+
/// </summary>
73+
/// <remarks>
74+
/// The ">" that encloses the templates will have extra spaces between them, for instance
75+
///
76+
/// auto_in<Class>
77+
/// auto_in<Class<T> >
78+
/// auto_in<Class1<Class2, Class3<Class4> > >
79+
///
80+
/// All we care about is matching "^auto_in<(.*)>$"
81+
/// </remarks>
82+
std::string DemangleTypeName(const std::type_info* type_info) const;
83+
84+
/// <summary>
85+
/// Scan all of the objects and add any AutoFilter's from all of the objects in a system.
86+
/// </summary>
87+
/// <remarks>
88+
/// This function will scan all of the objects (and rescan) and only add new edges to our graph.
89+
/// </remarks>
90+
void LoadEdges();
91+
92+
/// <summary>
93+
/// Record the delivery of a packet and increment the number of times the packet has been delivered
94+
/// </summary>
95+
void RecordDelivery(const std::type_info* ti, const AutoFilterDescriptor& descriptor, bool input);
96+
97+
/// AutowiringEvents overrides
98+
virtual void NewContext(CoreContext&) override {}
99+
virtual void ExpiredContext(CoreContext&) override {}
100+
virtual void EventFired(CoreContext&, const std::type_info&) override {}
101+
virtual void NewObject(CoreContext&, const ObjectTraits&) override;
102+
103+
/// CoreRunnable overrides
104+
virtual bool OnStart(void) override;
105+
106+
public:
107+
/// <summary>
108+
/// Get a copy of the packet via AutoFilter
109+
/// </summary>
110+
void AutoFilter(AutoPacket& packet);
111+
112+
/// <summary>
113+
/// Write the graph to a file in graphviz format
114+
/// </summary>
115+
/// <param name="filename">
116+
/// The name of the file to write the graph to
117+
/// </param>
118+
/// <param name="numPackets">
119+
/// Include the number of times the packet was delivered
120+
/// </param>
121+
bool WriteGV(const std::string& filename, bool numPackets = false) const;
122+
};

autowiring/AutoRestarter.h

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,18 @@ class AutoRestarter:
5252
const AutoRestarterConfig config;
5353

5454
// CoreRunnable overrides:
55-
bool Start(std::shared_ptr<Object> outstanding) override {
55+
bool OnStart() override {
5656
// Start the enclosed context, do nothing else
5757
auto ctxt = GetContext();
5858
if(ctxt && config.startWhenCreated)
5959
ctxt->Initiate();
6060
return true;
6161
}
6262

63-
void Stop(bool graceful) override {
63+
void OnStop(bool graceful) override {
6464
std::lock_guard<std::mutex> lk(m_lock);
6565
m_context.reset();
6666
}
67-
bool IsRunning(void) const override { return false; }
68-
bool ShouldStop(void) const override { return true; }
69-
void Wait(void) override {}
7067

7168
private:
7269
mutable std::mutex m_lock;
@@ -84,21 +81,13 @@ class AutoRestarter:
8481
// Parent restarter, we hand control here when we're stopped
8582
AutoRestarter<Sigil>& ar;
8683

87-
bool Start(std::shared_ptr<Object> outstanding) override {
88-
m_outstanding = outstanding;
84+
bool OnStart(void) override {
8985
return true;
9086
}
9187

92-
void Stop(bool graceful) override {
88+
void OnStop(bool graceful) override {
9389
ar.OnContextStopped(*this);
94-
m_outstanding.reset();
9590
}
96-
97-
std::shared_ptr<Object> m_outstanding;
98-
99-
bool IsRunning(void) const override { return false; }
100-
bool ShouldStop(void) const override { return false; }
101-
void Wait(void) {}
10291
};
10392

10493
protected:

autowiring/Autowired.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,14 @@ class AutowiredFast:
261261

262262
// !!!!! Read comment in AutoRequired if you get a compiler error here !!!!!
263263
AutowiredFast(const std::shared_ptr<CoreContext>& ctxt = CoreContext::CurrentContext()) {
264-
if(ctxt)
264+
if (ctxt)
265265
ctxt->FindByTypeRecursive(*this);
266266
}
267267

268+
AutowiredFast(const CoreContext* pCtxt) {
269+
pCtxt->FindByTypeRecursive(*this);
270+
}
271+
268272
operator bool(void) const {
269273
return IsAutowired();
270274
}

autowiring/BasicThread.h

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,6 @@ class BasicThread:
167167
/// </remarks>
168168
bool ThreadSleep(std::chrono::nanoseconds timeout);
169169

170-
public:
171-
// Accessor methods:
172-
bool ShouldStop(void) const override;
173-
bool IsRunning(void) const override;
174-
175170
/// <summary>
176171
/// Causes a new thread to be created in which the Run method will be invoked
177172
/// </summary>
@@ -181,8 +176,13 @@ class BasicThread:
181176
/// Start will not be called from more than one place on the same object. The thread
182177
/// will be invoked from the context which was active at the time the thread was created.
183178
/// </remarks>
184-
virtual bool Start(std::shared_ptr<Object> outstanding);
179+
bool OnStart() override;
180+
181+
void OnStop(bool graceful) override;
185182

183+
void DoAdditionalWait() override;
184+
185+
public:
186186
/// <summary>
187187
/// Begins the core thread
188188
/// </summary>
@@ -194,45 +194,15 @@ class BasicThread:
194194
virtual void Run() = 0;
195195

196196
/// <summary>
197-
/// Waits until the core thread is launched and then terminates
198-
/// </summary>
199-
/// <remarks>
200-
/// Unlike Join, this method may be invoked even if the CoreThread isn't running
201-
/// </remarks>
202-
void Wait(void) override;
203-
204-
/// <summary>
205-
/// Timed version of Wait
197+
/// Provides derived members with a way of obtaining notification that this thread is being stopped
206198
/// </summary>
207-
/// <returns>False if the timeout elapsed, true otherwise</returns>
208-
bool WaitFor(std::chrono::nanoseconds duration);
209-
210-
/// <summary>
211-
/// Timed version of Wait
212-
/// </summary>
213-
/// <returns>False if the timeout elapsed, true otherwise</returns>
214-
template<class TimeType>
215-
bool WaitUntil(TimeType timepoint);
216-
217-
/// <summary>
218-
/// Event which may be used to perform custom handling when the thread is told to stop
219-
/// </summary>
220-
/// <param name="graceful">Set to true to rundown the dispatch queue before quitting</param>
221199
/// <remarks>
222-
/// This method is called when the thread should stop. When invoked, the value of
223-
/// CoreThread::ShouldStop is guaranteed to be true.
224-
///
225-
/// Callers are not required to call CoreThread::OnStop. This method is guaranteed to do
226-
/// nothing by default.
200+
/// Callers must not perform any time-consuming operations in this callback; the method may be called
201+
/// from a time-sensitive context and unacceptable system performance could result if long-duration
202+
/// operations are undertaken here.
227203
/// </remarks>
228204
virtual void OnStop(void) {}
229205

230-
/// <summary>
231-
/// This is an override method that will cause ShouldStop to return true,
232-
/// regardless of what the global stop setting is.
233-
/// </summary>
234-
virtual void Stop(bool graceful = false);
235-
236206
/// <summary>
237207
/// Forces all Autowiring threads to reidentify themselves
238208
/// </summary>

autowiring/C++11/boost_future.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
#include <boost/thread/future.hpp>
1010

1111
namespace std {
12-
using boost::future;
13-
using boost::future_status;
14-
using boost::promise;
15-
using boost::future_error;
16-
using boost::async;
17-
using boost::launch;
12+
using AUTOWIRING_BOOST_NAME::future;
13+
using AUTOWIRING_BOOST_NAME::future_status;
14+
using AUTOWIRING_BOOST_NAME::promise;
15+
using AUTOWIRING_BOOST_NAME::future_error;
16+
using AUTOWIRING_BOOST_NAME::async;
17+
using AUTOWIRING_BOOST_NAME::launch;
1818
}

0 commit comments

Comments
 (0)