summaryrefslogtreecommitdiff
path: root/cpp/demo
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/demo')
-rw-r--r--cpp/demo/Freeze/bench/Client.cpp4
-rw-r--r--cpp/demo/Freeze/casino/BankI.cpp2
-rw-r--r--cpp/demo/Freeze/casino/Timer.cpp143
-rw-r--r--cpp/demo/Freeze/casino/Timer.h57
-rw-r--r--cpp/demo/Freeze/customEvictor/Client.cpp10
-rw-r--r--cpp/demo/Ice/latency/Client.cpp4
-rwxr-xr-xcpp/demo/Ice/session/ReapThread.cpp2
-rwxr-xr-xcpp/demo/Ice/session/SessionI.cpp4
-rw-r--r--cpp/demo/Ice/throughput/Client.cpp4
-rwxr-xr-xcpp/demo/IcePatch2/MFC/PatchClientDlg.cpp4
10 files changed, 18 insertions, 216 deletions
diff --git a/cpp/demo/Freeze/bench/Client.cpp b/cpp/demo/Freeze/bench/Client.cpp
index e1ec5b2014e..13a78073197 100644
--- a/cpp/demo/Freeze/bench/Client.cpp
+++ b/cpp/demo/Freeze/bench/Client.cpp
@@ -37,7 +37,7 @@ public:
start()
{
_stopped = false;
- _start = IceUtil::Time::now();
+ _start = IceUtil::Time::now(IceUtil::Time::Monotonic);
}
IceUtil::Time
@@ -46,7 +46,7 @@ public:
if(!_stopped)
{
_stopped = true;
- _stop = IceUtil::Time::now();
+ _stop = IceUtil::Time::now(IceUtil::Time::Monotonic);
}
return _stop - _start;
diff --git a/cpp/demo/Freeze/casino/BankI.cpp b/cpp/demo/Freeze/casino/BankI.cpp
index e42cde83177..0050b844278 100644
--- a/cpp/demo/Freeze/casino/BankI.cpp
+++ b/cpp/demo/Freeze/casino/BankI.cpp
@@ -109,7 +109,7 @@ BankI::createBet(int amount, int lifetime, const Ice::Current&)
Ice::Identity ident = { IceUtil::generateUUID(), "bet" };
#endif
- Ice::Long closeTime = IceUtil::Time::now().toMilliSeconds() + lifetime;
+ Ice::Long closeTime = IceUtil::Time::now(IceUtil::Time::Monotonic).toMilliSeconds() + lifetime;
outstandingChips += amount;
Ice::ObjectPtr betI = new BetI(amount, closeTime, _prx, _betEvictor, _bankEdge);
diff --git a/cpp/demo/Freeze/casino/Timer.cpp b/cpp/demo/Freeze/casino/Timer.cpp
deleted file mode 100644
index 3e350032e97..00000000000
--- a/cpp/demo/Freeze/casino/Timer.cpp
+++ /dev/null
@@ -1,143 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-
-#include <Timer.h>
-#include <iostream>
-
-using namespace std;
-using namespace IceUtil;
-
-Timer::Timer() :
- _canceled(false)
-{
- start();
-}
-
-void
-Timer::cancel()
-{
- bool join = false;
- {
- IceUtil::Monitor<IceUtil::Mutex>::Lock sync(_monitor);
- if(!_canceled)
- {
- _canceled = true;
- join = true;
- _monitor.notify();
- }
- }
-
- if(join)
- {
- getThreadControl().join();
- }
-}
-
-
-void
-Timer::schedule(const ::TimerTaskPtr& task, const IceUtil::Time& time)
-{
-#if defined(_MSC_VER) && (_MSC_VER < 1300)
- Entry entry;
- entry.task = task;
- entry.time = time;
-#else
- Entry entry = { task, time };
-#endif
-
- IceUtil::Monitor<IceUtil::Mutex>::Lock sync(_monitor);
-
- // cout << "Scheduling task for " << time.toDateTime() << endl;
-
- bool notify = _queue.empty();
-
- //
- // Insert it at the proper position
- //
- bool inserted = false;
- deque<Entry>::iterator p = _queue.begin();
- while(!inserted && p != _queue.end())
- {
- if(time < p->time)
- {
- _queue.insert(p, entry);
- inserted = true;
- }
- else
- {
- ++p;
- }
- }
-
- if(!inserted)
- {
- _queue.push_back(entry);
- }
-
- if(notify)
- {
- _monitor.notify();
- }
-}
-
-void
-Timer::run()
-{
- IceUtil::Monitor<IceUtil::Mutex>::Lock sync(_monitor);
-
- while(!_canceled)
- {
- while(!_canceled && _queue.empty())
- {
- _monitor.wait(); // wait forever
- }
-
- if(_canceled)
- {
- break;
- }
-
- assert(!_queue.empty());
-
- Entry entry = _queue.front();
- _queue.pop_front();
-
- bool ready = false;
-
- do
- {
- IceUtil::Time now = IceUtil::Time::now();
-
- ready = (entry.time <= now);
- if(!ready)
- {
- // cout << "Waiting for " << (entry.time - now).toDuration() << endl;
-
- ready = (_monitor.timedWait(entry.time - now) == false);
- }
- } while(!_canceled && !ready);
-
- if(ready)
- {
- sync.release();
-
- try
- {
- entry.task->run();
- }
- catch(...)
- {
- cerr << "Task raised an exception" << endl;
- // ignored
- }
-
- sync.acquire();
- }
- }
-}
diff --git a/cpp/demo/Freeze/casino/Timer.h b/cpp/demo/Freeze/casino/Timer.h
deleted file mode 100644
index 95a2bf417dc..00000000000
--- a/cpp/demo/Freeze/casino/Timer.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-
-#ifndef CASINO_TIMER_H
-#define CASINO_TIMER_H
-
-#include <IceUtil/IceUtil.h>
-#include <deque>
-
-//
-// A simplified version of java.util.Timer just for this demo
-//
-
-class TimerTask : public IceUtil::Shared
-{
-public:
-
- virtual void run() = 0;
-};
-
-typedef IceUtil::Handle<TimerTask> TimerTaskPtr;
-
-class Timer : public virtual IceUtil::Shared, private virtual IceUtil::Thread
-{
-public:
-
- Timer();
-
- void cancel();
- void schedule(const TimerTaskPtr&, const IceUtil::Time&);
-
-private:
-
- struct Entry
- {
- TimerTaskPtr task;
- IceUtil::Time time;
- };
-
- virtual void run();
-
- IceUtil::Monitor<IceUtil::Mutex> _monitor;
- bool _canceled;
- std::deque<Entry> _queue;
-
-};
-
-typedef IceUtil::Handle<Timer> TimerPtr;
-
-#endif
-
diff --git a/cpp/demo/Freeze/customEvictor/Client.cpp b/cpp/demo/Freeze/customEvictor/Client.cpp
index 66c3b804bdf..80bf2a11c76 100644
--- a/cpp/demo/Freeze/customEvictor/Client.cpp
+++ b/cpp/demo/Freeze/customEvictor/Client.cpp
@@ -48,7 +48,7 @@ public:
//
// Measures how long it takes to read 'readCount' items at random
//
- IceUtil::Time start = IceUtil::Time::now();
+ IceUtil::Time start = IceUtil::Time::now(IceUtil::Time::Monotonic);
try
{
@@ -64,7 +64,8 @@ public:
ItemPrx item = ItemPrx::uncheckedCast(_anItem->ice_identity(identity));
item->getDescription();
}
- _requestsPerSecond = static_cast<int>(readCount / (IceUtil::Time::now() - start).toSecondsDouble());
+ _requestsPerSecond =
+ static_cast<int>(readCount / (IceUtil::Time::now(IceUtil::Time::Monotonic) - start).toSecondsDouble());
}
catch(const IceUtil::Exception& e)
{
@@ -99,7 +100,7 @@ public:
//
// Measure how long it takes to write 'writeCount' items at random.
//
- IceUtil::Time start = IceUtil::Time::now();
+ IceUtil::Time start = IceUtil::Time::now(IceUtil::Time::Monotonic);
try
{
@@ -117,7 +118,8 @@ public:
item->adjustStock(1);
}
- _requestsPerSecond = static_cast<int>(writeCount / (IceUtil::Time::now() - start).toSecondsDouble());
+ _requestsPerSecond =
+ static_cast<int>(writeCount / (IceUtil::Time::now(IceUtil::Time::Monotonic) - start).toSecondsDouble());
}
catch(const IceUtil::Exception& e)
{
diff --git a/cpp/demo/Ice/latency/Client.cpp b/cpp/demo/Ice/latency/Client.cpp
index ce5cae636d1..686512b432e 100644
--- a/cpp/demo/Ice/latency/Client.cpp
+++ b/cpp/demo/Ice/latency/Client.cpp
@@ -47,7 +47,7 @@ LatencyClient::run(int argc, char* argv[])
// Initial ping to setup the connection.
ping->ice_ping();
- IceUtil::Time tm = IceUtil::Time::now();
+ IceUtil::Time tm = IceUtil::Time::now(IceUtil::Time::Monotonic);
const int repetitions = 100000;
cout << "pinging server " << repetitions << " times (this may take a while)" << endl;
@@ -56,7 +56,7 @@ LatencyClient::run(int argc, char* argv[])
ping->ice_ping();
}
- tm = IceUtil::Time::now() - tm;
+ tm = IceUtil::Time::now(IceUtil::Time::Monotonic) - tm;
cout << "time for " << repetitions << " pings: " << tm * 1000 << "ms" << endl;
cout << "time per ping: " << tm * 1000 / repetitions << "ms" << endl;
diff --git a/cpp/demo/Ice/session/ReapThread.cpp b/cpp/demo/Ice/session/ReapThread.cpp
index 0676f5c8b91..36845dcd183 100755
--- a/cpp/demo/Ice/session/ReapThread.cpp
+++ b/cpp/demo/Ice/session/ReapThread.cpp
@@ -39,7 +39,7 @@ ReapThread::run()
// real-world example. Therefore the current time
// is computed for each iteration.
//
- if((IceUtil::Time::now() - p->session->timestamp()) > _timeout)
+ if((IceUtil::Time::now(IceUtil::Time::Monotonic) - p->session->timestamp()) > _timeout)
{
string name = p->proxy->getName();
p->proxy->destroy();
diff --git a/cpp/demo/Ice/session/SessionI.cpp b/cpp/demo/Ice/session/SessionI.cpp
index a0e70e24168..14e03c8b096 100755
--- a/cpp/demo/Ice/session/SessionI.cpp
+++ b/cpp/demo/Ice/session/SessionI.cpp
@@ -42,7 +42,7 @@ private:
SessionI::SessionI(const string& name) :
_name(name),
- _timestamp(IceUtil::Time::now()),
+ _timestamp(IceUtil::Time::now(IceUtil::Time::Monotonic)),
_nextId(0),
_destroy(false)
{
@@ -72,7 +72,7 @@ SessionI::refresh(const Ice::Current& c)
throw Ice::ObjectNotExistException(__FILE__, __LINE__);
}
- _timestamp = IceUtil::Time::now();
+ _timestamp = IceUtil::Time::now(IceUtil::Time::Monotonic);
}
string
diff --git a/cpp/demo/Ice/throughput/Client.cpp b/cpp/demo/Ice/throughput/Client.cpp
index 82a3e621e69..6bbf4e22f7d 100644
--- a/cpp/demo/Ice/throughput/Client.cpp
+++ b/cpp/demo/Ice/throughput/Client.cpp
@@ -152,7 +152,7 @@ ThroughputClient::run(int argc, char* argv[])
cout << "==> ";
cin >> c;
- IceUtil::Time tm = IceUtil::Time::now();
+ IceUtil::Time tm = IceUtil::Time::now(IceUtil::Time::Monotonic);
const int repetitions = 1000;
if(c == '1' || c == '2' || c == '3' || c == '4')
@@ -379,7 +379,7 @@ ThroughputClient::run(int argc, char* argv[])
}
}
- tm = IceUtil::Time::now() - tm;
+ tm = IceUtil::Time::now(IceUtil::Time::Monotonic) - tm;
cout << "time for " << repetitions << " sequences: " << tm * 1000 << "ms" << endl;
cout << "time per sequence: " << tm * 1000 / repetitions << "ms" << endl;
int wireSize = 0;
diff --git a/cpp/demo/IcePatch2/MFC/PatchClientDlg.cpp b/cpp/demo/IcePatch2/MFC/PatchClientDlg.cpp
index 5f8d6f61acf..0453190293f 100755
--- a/cpp/demo/IcePatch2/MFC/PatchClientDlg.cpp
+++ b/cpp/demo/IcePatch2/MFC/PatchClientDlg.cpp
@@ -181,7 +181,7 @@ CPatchDlg::patchStart(const string& path, Ice::Long size, Ice::Long totalProgres
{
if(!_isPatch)
{
- _startTime = IceUtil::Time::now();
+ _startTime = IceUtil::Time::now(IceUtil::Time::Monotonic);
_status->SetWindowText(CString(L" Patching..."));
_speed->SetWindowText(CString(L" 0.0 KB/s"));
_isPatch = true;
@@ -197,7 +197,7 @@ CPatchDlg::patchStart(const string& path, Ice::Long size, Ice::Long totalProgres
bool
CPatchDlg::patchProgress(Ice::Long, Ice::Long, Ice::Long totalProgress, Ice::Long totalSize)
{
- IceUtil::Time elapsed = IceUtil::Time::now() - _startTime;
+ IceUtil::Time elapsed = IceUtil::Time::now(IceUtil::Time::Monotonic) - _startTime;
if(elapsed.toSeconds() > 0)
{
CString speed;