# HG changeset patch # User Alpar Juttner # Date 1430991739 -7200 # Node ID f8ec64f78b5fdc88bf1dd7803660a9f6758ac047 # Parent f95b18d998438ab8e479b864d17cd9fb8e811fde# Parent 0900cfe4a84d4136dfabedd3175f822465c67faa Merge bugfix #473 diff -r f95b18d99843 -r f8ec64f78b5f lemon/cplex.cc --- a/lemon/cplex.cc Wed May 06 11:31:43 2015 +0200 +++ b/lemon/cplex.cc Thu May 07 11:42:19 2015 +0200 @@ -37,37 +37,54 @@ } } + void CplexEnv::incCnt() + { + _cnt_lock->lock(); + ++(*_cnt); + _cnt_lock->unlock(); + } + + void CplexEnv::decCnt() + { + _cnt_lock->lock(); + --(*_cnt); + if (*_cnt == 0) { + delete _cnt; + _cnt_lock->unlock(); + delete _cnt_lock; + CPXcloseCPLEX(&_env); + } + else _cnt_lock->unlock(); + } + CplexEnv::CplexEnv() { int status; + _env = CPXopenCPLEX(&status); + if (_env == 0) + throw LicenseError(status); _cnt = new int; (*_cnt) = 1; - _env = CPXopenCPLEX(&status); - if (_env == 0) { - delete _cnt; - _cnt = 0; - throw LicenseError(status); - } + _cnt_lock = new bits::Lock; } CplexEnv::CplexEnv(const CplexEnv& other) { _env = other._env; _cnt = other._cnt; - ++(*_cnt); + _cnt_lock = other._cnt_lock; + incCnt(); } CplexEnv& CplexEnv::operator=(const CplexEnv& other) { + decCnt(); _env = other._env; _cnt = other._cnt; - ++(*_cnt); + _cnt_lock = other._cnt_lock; + incCnt(); return *this; } CplexEnv::~CplexEnv() { - --(*_cnt); - if (*_cnt == 0) { - delete _cnt; - CPXcloseCPLEX(&_env); - } + decCnt(); } CplexBase::CplexBase() : LpBase() { diff -r f95b18d99843 -r f8ec64f78b5f lemon/cplex.h --- a/lemon/cplex.h Wed May 06 11:31:43 2015 +0200 +++ b/lemon/cplex.h Thu May 07 11:42:19 2015 +0200 @@ -23,6 +23,7 @@ ///\brief Header of the LEMON-CPLEX lp solver interface. #include +#include struct cpxenv; struct cpxlp; @@ -40,7 +41,11 @@ private: cpxenv* _env; mutable int* _cnt; + mutable bits::Lock* _cnt_lock; + void incCnt(); + void decCnt(); + public: /// \brief This exception is thrown when the license check is not