summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2007-07-11 16:51:22 +0200
committerBenoit Foucher <benoit@zeroc.com>2007-07-11 18:09:54 +0200
commitfbad48f4dfee89a8b7fff64bb79e7b323a94f399 (patch)
treeb8eb23bfe8fab5e7f2f352f247fa8bb11ca9aea7 /cpp
parent- Adding comments regarding the Oracle Database demos to the (diff)
downloadice-fbad48f4dfee89a8b7fff64bb79e7b323a94f399.tar.bz2
ice-fbad48f4dfee89a8b7fff64bb79e7b323a94f399.tar.xz
ice-fbad48f4dfee89a8b7fff64bb79e7b323a94f399.zip
Fixed bug 2288
Diffstat (limited to 'cpp')
-rw-r--r--cpp/demo/Ice/bidir/CallbackI.cpp34
-rw-r--r--cpp/demo/Ice/bidir/CallbackI.h1
2 files changed, 21 insertions, 14 deletions
diff --git a/cpp/demo/Ice/bidir/CallbackI.cpp b/cpp/demo/Ice/bidir/CallbackI.cpp
index d24888c0dd3..3077f510e7f 100644
--- a/cpp/demo/Ice/bidir/CallbackI.cpp
+++ b/cpp/demo/Ice/bidir/CallbackI.cpp
@@ -17,7 +17,6 @@ using namespace Demo;
CallbackSenderI::CallbackSenderI(const Ice::CommunicatorPtr& communicator) :
_communicator(communicator),
_destroy(false),
- _num(0),
_callbackSenderThread(new CallbackSenderThread(this))
{
}
@@ -62,29 +61,38 @@ CallbackSenderI::start()
void
CallbackSenderI::run()
{
- IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
-
- while(!_destroy)
+ int num = 0;
+ while(true)
{
- timedWait(IceUtil::Time::seconds(2));
+ std::set<Demo::CallbackReceiverPrx> clients;
+ {
+ IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
+ timedWait(IceUtil::Time::seconds(2));
- if(!_destroy && !_clients.empty())
+ if(_destroy)
+ {
+ break;
+ }
+
+ clients = _clients;
+ }
+
+ if(!clients.empty())
{
- ++_num;
-
- set<CallbackReceiverPrx>::iterator p = _clients.begin();
- while(p != _clients.end())
+ ++num;
+ for(set<CallbackReceiverPrx>::iterator p = clients.begin(); p != clients.end(); ++p)
{
try
{
- (*p)->callback(_num);
- ++p;
+ (*p)->callback(num);
}
catch(const Exception& ex)
{
cerr << "removing client `" << _communicator->identityToString((*p)->ice_getIdentity()) << "':\n"
<< ex << endl;
- _clients.erase(p++);
+
+ IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
+ _clients.erase(*p);
}
}
}
diff --git a/cpp/demo/Ice/bidir/CallbackI.h b/cpp/demo/Ice/bidir/CallbackI.h
index e99789bfa31..ffa1311742b 100644
--- a/cpp/demo/Ice/bidir/CallbackI.h
+++ b/cpp/demo/Ice/bidir/CallbackI.h
@@ -35,7 +35,6 @@ private:
Ice::CommunicatorPtr _communicator;
bool _destroy;
- Ice::Int _num;
std::set<Demo::CallbackReceiverPrx> _clients;
//