summaryrefslogtreecommitdiff
path: root/matlab/src
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2017-10-02 14:07:26 -0700
committerMark Spruiell <mes@zeroc.com>2017-10-02 14:07:26 -0700
commit99ab669b7f6226bea2289b62c03346ec1fe38e59 (patch)
treed086a61111b31aa252f87b6d35d0d045c258e0b5 /matlab/src
parentMoving Ice.ValueHolder (diff)
downloadice-99ab669b7f6226bea2289b62c03346ec1fe38e59.tar.bz2
ice-99ab669b7f6226bea2289b62c03346ec1fe38e59.tar.xz
ice-99ab669b7f6226bea2289b62c03346ec1fe38e59.zip
C++ synchronization fix
Diffstat (limited to 'matlab/src')
-rw-r--r--matlab/src/IceMatlab/Future.cpp16
-rw-r--r--matlab/src/IceMatlab/Future.h1
-rw-r--r--matlab/src/IceMatlab/ObjectPrx.cpp16
3 files changed, 16 insertions, 17 deletions
diff --git a/matlab/src/IceMatlab/Future.cpp b/matlab/src/IceMatlab/Future.cpp
index 15fa83471f2..ce46e2f084e 100644
--- a/matlab/src/IceMatlab/Future.cpp
+++ b/matlab/src/IceMatlab/Future.cpp
@@ -19,7 +19,7 @@ using namespace IceMatlab;
void
IceMatlab::Future::token(function<void()> t)
{
- Lock sync(_mutex);
+ lock_guard<mutex> lock(_mutex);
if(!isFinished())
{
_token = std::move(t);
@@ -29,15 +29,15 @@ IceMatlab::Future::token(function<void()> t)
bool
IceMatlab::Future::waitUntilFinished()
{
- Lock sync(_mutex);
- _cond.wait(sync, [this]{ return this->isFinished(); });
+ unique_lock<mutex> lock(_mutex);
+ _cond.wait(lock, [this]{ return this->isFinished(); });
return !_exception;
}
void
IceMatlab::Future::exception(exception_ptr e)
{
- Lock sync(_mutex);
+ lock_guard<mutex> lock(_mutex);
_token = nullptr;
_exception = e;
_cond.notify_all();
@@ -46,7 +46,7 @@ IceMatlab::Future::exception(exception_ptr e)
exception_ptr
IceMatlab::Future::getException() const
{
- Lock sync(const_cast<mutex&>(_mutex));
+ lock_guard<mutex> lock(const_cast<mutex&>(_mutex));
return _exception;
}
@@ -58,7 +58,7 @@ IceMatlab::Future::sent()
void
IceMatlab::Future::cancel()
{
- Lock sync(_mutex);
+ lock_guard<mutex> lock(_mutex);
if(_token)
{
_token();
@@ -77,7 +77,7 @@ IceMatlab::SimpleFuture::SimpleFuture() :
void
IceMatlab::SimpleFuture::done()
{
- Lock sync(_mutex);
+ lock_guard<mutex> lock(_mutex);
_done = true;
_cond.notify_all();
}
@@ -85,7 +85,7 @@ IceMatlab::SimpleFuture::done()
string
IceMatlab::SimpleFuture::state() const
{
- Lock sync(const_cast<mutex&>(_mutex));
+ lock_guard<mutex> lock(const_cast<mutex&>(_mutex));
if(_exception || _done)
{
return "finished";
diff --git a/matlab/src/IceMatlab/Future.h b/matlab/src/IceMatlab/Future.h
index cc8ce697334..0b6858bffb9 100644
--- a/matlab/src/IceMatlab/Future.h
+++ b/matlab/src/IceMatlab/Future.h
@@ -32,7 +32,6 @@ protected:
std::mutex _mutex;
std::condition_variable _cond;
- using Lock = std::unique_lock<std::mutex>;
std::function<void()> _token;
std::exception_ptr _exception; // If a local exception occurs.
diff --git a/matlab/src/IceMatlab/ObjectPrx.cpp b/matlab/src/IceMatlab/ObjectPrx.cpp
index 6e050e2dd25..11242b88ca2 100644
--- a/matlab/src/IceMatlab/ObjectPrx.cpp
+++ b/matlab/src/IceMatlab/ObjectPrx.cpp
@@ -65,7 +65,7 @@ InvocationFuture::InvocationFuture(bool twoway, bool batch) :
void
InvocationFuture::sent()
{
- Lock sync(_mutex);
+ lock_guard<mutex> lock(_mutex);
if(_state == State::Running)
{
_state = _twoway ? State::Sent : State::Finished;
@@ -75,7 +75,7 @@ InvocationFuture::sent()
void
InvocationFuture::exception(exception_ptr e)
{
- Lock sync(_mutex);
+ lock_guard<mutex> lock(_mutex);
_state = State::Finished;
_token = nullptr;
_exception = e;
@@ -86,7 +86,7 @@ void
InvocationFuture::finished(const std::shared_ptr<Ice::Communicator>& communicator,
const Ice::EncodingVersion& encoding, bool b, pair<const Ice::Byte*, const Ice::Byte*> p)
{
- Lock sync(_mutex);
+ lock_guard<mutex> lock(_mutex);
_ok = b;
_state = State::Finished;
_token = nullptr;
@@ -101,7 +101,7 @@ InvocationFuture::finished(const std::shared_ptr<Ice::Communicator>& communicato
string
InvocationFuture::state() const
{
- Lock sync(const_cast<mutex&>(_mutex));
+ lock_guard<mutex> lock(const_cast<mutex&>(_mutex));
string st;
switch(_state)
{
@@ -121,7 +121,7 @@ InvocationFuture::state() const
void
InvocationFuture::getResults(bool& ok, pair<const Ice::Byte*, const Ice::Byte*>& p)
{
- Lock sync(_mutex);
+ lock_guard<mutex> lock(_mutex);
assert(_twoway);
ok = _ok;
if(!_data.empty())
@@ -164,7 +164,7 @@ private:
string
GetConnectionFuture::state() const
{
- Lock sync(const_cast<mutex&>(_mutex));
+ lock_guard<mutex> lock(const_cast<mutex&>(_mutex));
if(_exception || _connection)
{
return "finished";
@@ -178,7 +178,7 @@ GetConnectionFuture::state() const
void
GetConnectionFuture::finished(shared_ptr<Ice::Connection> con)
{
- Lock sync(_mutex);
+ lock_guard<mutex> lock(_mutex);
_token = nullptr;
_connection = con;
_cond.notify_all();
@@ -187,7 +187,7 @@ GetConnectionFuture::finished(shared_ptr<Ice::Connection> con)
shared_ptr<Ice::Connection>
GetConnectionFuture::getConnection() const
{
- Lock sync(const_cast<mutex&>(_mutex));
+ lock_guard<mutex> lock(const_cast<mutex&>(_mutex));
return _connection;
}