Date: Tuesday, December 13, 2005 @ 18:33:12
  Author: gilles
    Path: /cvsroot/carob/carob/src

Modified: Connection.cpp (1.39 -> 1.40)

Fixed connectionCS (critical section) 'leave()'
Was sometimes not released in all cases, sometimes not at all...


----------------+
 Connection.cpp |   57 ++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 38 insertions(+), 19 deletions(-)


Index: carob/src/Connection.cpp
diff -u carob/src/Connection.cpp:1.39 carob/src/Connection.cpp:1.40
--- carob/src/Connection.cpp:1.39       Tue Dec 13 18:18:51 2005
+++ carob/src/Connection.cpp    Tue Dec 13 18:33:12 2005
@@ -217,18 +217,18 @@
 {
   wstring fctName(L"Connection::closeConnection");
 
-  //Wait until other methods/Commands are done
-  connectionCS.Enter();
   if (driverSocketPtr == NULL)
   {
-    //Release lock
-    connectionCS.Leave();
     return false;
   }
+
+  //Wait until other methods/Commands are done
+  connectionCS.Enter();
   
   if (connectionPooling)
   {
     //TODO: real connection pooling...
+    connectionCS.Leave();
     throw NotImplementedException(L"Connection pooling not implemented yet");
     try
     {
@@ -321,6 +321,7 @@
     { // Just cancel the need to start a transaction
       autoCommit = true;
       mustBeginTransaction = false;
+      connectionCS.Leave();
       return;
     }
   }
@@ -328,6 +329,7 @@
   // nothing to change
   if (autoCommit == autoCommitPrm)
   {
+    connectionCS.Leave();
     return;
   }
   // autocommit false -> true
@@ -342,6 +344,7 @@
     writeExecutedInTransaction = false;
     transactionId = 0;
     autoCommit = true;
+    connectionCS.Leave();
     return;
   }
   else // autocommit true -> false
@@ -390,8 +393,15 @@
   wstring fctName(L"Connection::commit");
   
   connectionCS.Enter();
-  
-  checkIfConnected();
+  try
+  {
+    checkIfConnected();
+  }
+  catch (...)
+  {
+    connectionCS.Leave();
+    throw;
+  }
   if (autoCommit)
   {
     connectionCS.Leave();
@@ -411,6 +421,7 @@
     }
     // Commit must be followed by a BEGIN
     mustBeginTransaction = true;
+    connectionCS.Leave();
   }
   catch (SocketIOException e)
   {
@@ -436,7 +447,15 @@
   
   connectionCS.Enter();
 
-  checkIfConnected();
+  try
+  {
+    checkIfConnected();
+  }
+  catch (...)
+  {
+    connectionCS.Leave();
+    throw;
+  }
   if (autoCommit)
   {
     connectionCS.Leave();
@@ -457,6 +476,7 @@
     }
     // Rollback is followed by a BEGIN
     mustBeginTransaction = true;
+    connectionCS.Leave();
   }
   catch (SocketIOException e)
   {
@@ -508,12 +528,12 @@
   connectionCS.Enter();
 
   DriverResultSet* retVal = NULL;
-  
-  checkIfConnected();
-  beginTransactionIfNeeded();
 
   try
   {
+    checkIfConnected();
+    beginTransactionIfNeeded();
+    
     setConnectionParametersOnRequest(request);
     sendCommand(*driverSocketPtr, StatementExecuteQuery);
     request.sendToStream(*driverSocketPtr, controllerNeedsSqlSkeleton);
@@ -535,7 +555,9 @@
   }
   catch (SocketIOException sioe)
   {
+    connectionCS.Leave();
     //TODO: Reconnect and retry
+    throw;
   }
   catch (...)
   {
@@ -556,13 +578,12 @@
 
   int controllerResponse = -1;
   
-  checkIfConnected();
-  beginTransactionIfNeeded();
-
   bool requestIdIsSet = false;
 
   try
   {
+    checkIfConnected();
+    beginTransactionIfNeeded();
     setConnectionParametersOnRequest(request);
     sendCommand(*driverSocketPtr, StatementExecuteUpdate);
     writeRequestOnStream(request);
@@ -613,13 +634,12 @@
   connectionCS.Enter();
   std::list<ResultSetOrUpdateCount> results;
 
-  checkIfConnected();
-  beginTransactionIfNeeded();
-
   bool requestIdIsSet = false;
 
   try
   {
+    checkIfConnected();
+    beginTransactionIfNeeded();
     setConnectionParametersOnRequest(request);
     if (!autoCommit)
       writeExecutedInTransaction = true;
@@ -682,10 +702,9 @@
 
   connectionCS.Enter();
 
-  checkIfConnected();
-
   try
   {
+    checkIfConnected();
     sendCommand(*driverSocketPtr, FetchNextResultSetRows);
     *driverSocketPtr<<cursorName;
     *driverSocketPtr<<fetchSize;
@@ -721,9 +740,9 @@
   wstring fctName(L"Connection::closeRemoteResultSet");
   
   connectionCS.Enter();
-  checkIfConnected();
   try
   {
+    checkIfConnected();
     sendCommand(*driverSocketPtr, CloseRemoteResultSet);
     *driverSocketPtr<<cursorName;
     if (isDebugEnabled())

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to