A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
wall-clock-synchronizer.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 University of Washington
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */
18 
19 #ifndef WALL_CLOCK_CLOCK_SYNCHRONIZER_H
20 #define WALL_CLOCK_CLOCK_SYNCHRONIZER_H
21 
22 #include "system-condition.h"
23 #include "synchronizer.h"
24 
25 namespace ns3 {
26 
63 {
64 public:
66  virtual ~WallClockSynchronizer ();
67 
68  static const uint64_t US_PER_NS = (uint64_t)1000;
69  static const uint64_t US_PER_SEC = (uint64_t)1000000;
70  static const uint64_t NS_PER_SEC = (uint64_t)1000000000;
71 
72 protected:
84  virtual bool DoRealtime (void);
85 
99  virtual uint64_t DoGetCurrentRealtime (void);
100 
126  virtual void DoSetOrigin (uint64_t ns);
127 
141  virtual int64_t DoGetDrift (uint64_t ns);
142 
163  virtual bool DoSynchronize (uint64_t nsCurrent, uint64_t nsDelay);
164  virtual void DoSignal (void);
165  virtual void DoSetCondition (bool cond);
166 
167  virtual void DoEventStart (void);
168  virtual uint64_t DoEventEnd (void);
169 
170  bool SpinWait (uint64_t);
171  bool SleepWait (uint64_t);
172 
173  uint64_t DriftCorrect (uint64_t nsNow, uint64_t nsDelay);
174 
175  uint64_t GetRealtime (void);
176  uint64_t GetNormalizedRealtime (void);
177 
178  void NsToTimeval (int64_t ns, struct timeval *tv);
179  uint64_t TimevalToNs (struct timeval *tv);
180 
181  void TimevalAdd (
182  struct timeval *tv1,
183  struct timeval *tv2,
184  struct timeval *result);
185 
186  uint64_t m_cpuTick;
187  uint64_t m_realtimeTick;
188  uint64_t m_jiffy;
189  uint64_t m_nsEventStart;
190 
192 };
193 
194 } // namespace ns3
195 
196 #endif /* WALL_CLOCK_SYNCHRONIZER_H */
uint64_t TimevalToNs(struct timeval *tv)
A class which provides a relatively platform-independent conditional-wait thread synchronization prim...
static const uint64_t NS_PER_SEC
virtual int64_t DoGetDrift(uint64_t ns)
Declaration of method used to retrieve drift between the real time clock used to synchronize the simu...
virtual bool DoRealtime(void)
Return true if this synchronizer is actually synchronizing to a realtime clock.
virtual uint64_t DoGetCurrentRealtime(void)
Retrieve the value of the origin of the underlying normalized wall clock time in nanosecond units...
virtual bool DoSynchronize(uint64_t nsCurrent, uint64_t nsDelay)
Wait until the real time is in sync with the specified simulation time.
Base class used for synchronizing the simulation events to some real time "wall clock.".
Definition: synchronizer.h:44
virtual void DoSetOrigin(uint64_t ns)
Establish a correspondence between a simulation time and a wall-clock (real) time.
static const uint64_t US_PER_SEC
virtual void DoSetCondition(bool cond)
Declaration of the method used to set the condition variable that tells a possible simulator thread w...
void NsToTimeval(int64_t ns, struct timeval *tv)
void TimevalAdd(struct timeval *tv1, struct timeval *tv2, struct timeval *result)
Class used for synchronizing the simulation events to a real-time "wall clock" using Posix Clock func...
virtual void DoSignal(void)
Declaration of the method used to tell a possible simulator thread waiting in the DoSynchronize metho...
uint64_t DriftCorrect(uint64_t nsNow, uint64_t nsDelay)