RflySimSDK v3.08
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_LamportClock.h
1#ifndef VRPN_LAMPORT_CLOCK_H
2#define VRPN_LAMPORT_CLOCK_H
3
4#include "vrpn_Configure.h" // for VRPN_API
5#include "vrpn_Types.h" // for vrpn_uint32, vrpn_bool
6
7/// @class vrpn_LamportTimestamp
8/// Timestamp for a single event, produced by a vrpn_LamportClock and
9/// hopefully generally usable in place of a struct timeval.
10
11/// @class vrpn_LamportClock
12/// Implements a distributed event clock as defined by Leslie Lamport in
13/// some seminal papers I can't find my copies of, for use by people who
14/// want to sequence events without relying on synchronization of wallclocks.
15
16class VRPN_API vrpn_LamportTimestamp {
17
18 public:
19
20 vrpn_LamportTimestamp (int vectorLength, vrpn_uint32 * vector);
23
24 vrpn_LamportTimestamp & operator = (const vrpn_LamportTimestamp &);
25
26
27 // ACCESSORS
28
29
30 vrpn_bool operator < (const vrpn_LamportTimestamp & r) const;
31 ///< Returns vrpn_true if this timestamp precedes r.
32 ///< It'd be nice if we could throw an exception here,
33 ///< since some timestamps are incommesurate.
34
35
36 // Utility functions.
37
38 vrpn_uint32 operator [] (int i) const;
39 ///< Returns the event count for the i'th host.
40
41 int size (void) const;
42 ///< Returns the number of hosts participating in the timestamp.
43
44
45 private:
46
47 void copy (const vrpn_uint32 *);
48 ///< Used by constructors and operator = to copy values into
49 ///< d_timestamp; don't we wish we were using STL?
50
51 int d_timestampSize;
52 vrpn_uint32 * d_timestamp;
53
55 ///< UNDEFINED - not legal.
56
57};
58
59
60class VRPN_API vrpn_LamportClock {
61
62 public:
63
64 vrpn_LamportClock (int numHosts, int ourIndex);
65 ~vrpn_LamportClock (void);
66
67
68 // MANIPULATORS
69
70
72 ///< Updates this clock to reflect a timestamp received from
73 ///< another clock/host.
74
76 ///< Increments the current timestamp and returns it.
77
78
79 private:
80
81 int d_numHosts;
82 int d_ourIndex;
83 vrpn_uint32 * d_currentTimestamp;
84
85};
86
87
88
89#endif // VRPN_LAMPORT_CLOCK_H
90
91
定义 vrpn_LamportClock.h:60
void receive(const vrpn_LamportTimestamp &)
vrpn_LamportTimestamp * getTimestampAndAdvance(void)
Increments the current timestamp and returns it.
定义 vrpn_LamportClock.h:16
int size(void) const
Returns the number of hosts participating in the timestamp.