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;
71  static const uint64_t NS_PER_SEC = (uint64_t)1000000000;
72 
73 protected:
85  virtual bool DoRealtime (void);
86 
100  virtual uint64_t DoGetCurrentRealtime (void);
101 
127  virtual void DoSetOrigin (uint64_t ns);
128 
142  virtual int64_t DoGetDrift (uint64_t ns);
143 
165  virtual bool DoSynchronize (uint64_t nsCurrent, uint64_t nsDelay);
166  virtual void DoSignal (void);
167  virtual void DoSetCondition (bool cond);
168 
169  virtual void DoEventStart (void);
170  virtual uint64_t DoEventEnd (void);
171 
172  bool SpinWait (uint64_t);
173  bool SleepWait (uint64_t);
174 
175  uint64_t DriftCorrect (uint64_t nsNow, uint64_t nsDelay);
176 
177  uint64_t GetRealtime (void);
178  uint64_t GetNormalizedRealtime (void);
179 
180  void NsToTimeval (int64_t ns, struct timeval *tv);
181  uint64_t TimevalToNs (struct timeval *tv);
182 
183  void TimevalAdd (
184  struct timeval *tv1,
185  struct timeval *tv2,
186  struct timeval *result);
187 
188  uint64_t m_cpuTick;
189  uint64_t m_realtimeTick;
190  uint64_t m_jiffy;
191  uint64_t m_nsEventStart;
192 
194 };
195 
196 } // namespace ns3
197 
198 #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
Conversion from ns to s.
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)