[Lemon-commits] Alpar Juttner: Merge bugfix #473 to branch 1.3

Lemon HG hg at lemon.cs.elte.hu
Thu May 7 11:42:46 CEST 2015


details:   http://lemon.cs.elte.hu/hg/lemon/rev/57a344e446c9
changeset: 1348:57a344e446c9
user:      Alpar Juttner <alpar [at] cs.elte.hu>
date:      Thu May 07 11:41:48 2015 +0200
description:
	Merge bugfix #473 to branch 1.3

diffstat:

 lemon/cplex.cc |  43 ++++++++++++++++++++++++++++++-------------
 lemon/cplex.h  |   5 +++++
 2 files changed, 35 insertions(+), 13 deletions(-)

diffs (94 lines):

diff --git a/lemon/cplex.cc b/lemon/cplex.cc
--- a/lemon/cplex.cc
+++ b/lemon/cplex.cc
@@ -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 --git a/lemon/cplex.h b/lemon/cplex.h
--- a/lemon/cplex.h
+++ b/lemon/cplex.h
@@ -23,6 +23,7 @@
 ///\brief Header of the LEMON-CPLEX lp solver interface.
 
 #include <lemon/lp_base.h>
+#include <lemon/bits/lock.h>
 
 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


More information about the Lemon-commits mailing list